Skip to content

Commit 227bdb1

Browse files
committed
Fixed tests to check stderr on errors
1 parent 1c9051d commit 227bdb1

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

tests/test_analyze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_logsource_invalid_rule():
208208
cli = CliRunner()
209209
result = cli.invoke(analyze_logsource, ["-", "tests/files/sigma_rule_without_condition.yml"])
210210
assert result.exit_code != 0
211-
assert "at least one condition" in result.stdout
211+
assert "at least one condition" in result.stderr
212212

213213

214214
def test_fields_help():
@@ -244,4 +244,4 @@ def test_fields_invalid_rule():
244244
cli = CliRunner()
245245
result = cli.invoke(analyze_fields, ["-t", "text_query_test", "-", "tests/files/sigma_rule_without_condition.yml"])
246246
assert result.exit_code != 0
247-
assert "at least one condition" in result.stdout
247+
assert "at least one condition" in result.stderr

tests/test_convert.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_convert_invalid_rule():
4343
],
4444
)
4545
assert result.exit_code > 0
46-
assert "at least one condition" in result.stdout
46+
assert "at least one condition" in result.stderr
4747

4848

4949
def test_convert_stdin():
@@ -132,38 +132,38 @@ def test_convert_unknown_backend():
132132
result = cli.invoke(
133133
convert, ["-t", "notexisting", "-f", "foo", "tests/files/valid"]
134134
)
135-
assert "Invalid value for" in result.stdout
136-
assert "--plugin-type backend" in result.stdout
135+
assert "Invalid value for" in result.stderr
136+
assert "--plugin-type backend" in result.stderr
137137

138138

139139
def test_convert_unknown_format():
140140
cli = CliRunner()
141141
result = cli.invoke(
142142
convert, ["-t", "text_query_test", "-f", "nonexisting", "tests/files/valid"]
143143
)
144-
assert "Invalid value for format" in result.stdout
145-
assert "sigma list formats" in result.stdout
144+
assert "Invalid value for format" in result.stderr
145+
assert "sigma list formats" in result.stderr
146146

147147

148148
def test_convert_unknown_pipeline():
149149
cli = CliRunner()
150150
result = cli.invoke(
151151
convert, ["-t", "text_query_test", "-p", "nonexisting", "tests/files/valid"]
152152
)
153-
assert "'nonexisting' was not found" in result.stdout
154-
assert "--plugin-type pipeline" in result.stdout
153+
assert "'nonexisting' was not found" in result.stderr
154+
assert "--plugin-type pipeline" in result.stderr
155155

156156

157157
def test_convert_missing_input():
158158
cli = CliRunner()
159159
result = cli.invoke(convert, ["-t", "text_query_test"])
160-
assert "Missing argument" in result.stdout
160+
assert "Missing argument" in result.stderr
161161

162162

163163
def test_convert_missing_pipeline():
164164
cli = CliRunner()
165165
result = cli.invoke(convert, ["-t", "mandatory_pipeline_test", "tests/files/valid"])
166-
assert result.exit_code > 0 and "pipeline required" in result.stdout
166+
assert result.exit_code > 0 and "pipeline required" in result.stderr
167167

168168

169169
def test_convert_missing_pipeline_ignore():
@@ -180,7 +180,7 @@ def test_convert_wrong_pipeline():
180180
result = cli.invoke(
181181
convert, ["-t", "text_query_test", "-p", "another_test", "tests/files/valid"]
182182
)
183-
assert result.exit_code > 0 and "'another_test' is not intended" in result.stdout
183+
assert result.exit_code > 0 and "'another_test' is not intended" in result.stderr
184184

185185

186186
def test_yml_pipeline_doesnt_trigger_wrong_pipeline():
@@ -206,7 +206,7 @@ def test_backend_option_invalid_format():
206206
convert, ["-t", "text_query_test", "-O", "invalid", "tests/files/valid"]
207207
)
208208
assert result.exit_code != 0
209-
assert "not format key=value" in result.stdout
209+
assert "not format key=value" in result.stderr
210210

211211

212212
def test_backend_option_invalid_type():
@@ -215,7 +215,7 @@ def test_backend_option_invalid_type():
215215
convert, ["-t", "text_query_test", "-O", 123, "tests/files/valid"]
216216
)
217217
assert result.exit_code != 0
218-
assert "must be a string" in result.stdout
218+
assert "must be a string" in result.stderr
219219

220220

221221
def test_convert_output_backend_option():
@@ -253,19 +253,21 @@ def test_convert_output_backend_option_list():
253253
)
254254
assert '[123, "test"]' in result.stdout
255255

256+
256257
def test_convert_correlation_method_without_backend_correlation_support(monkeypatch):
257258
monkeypatch.setattr(sigma.backends.test.backend.TextQueryTestBackend, "correlation_methods", None)
258259
cli = CliRunner()
259260
result = cli.invoke(
260261
convert, ["-t", "text_query_test", "-f", "str", "-c", "test", "tests/files/valid"]
261262
)
262263
assert result.exit_code != 0
263-
assert "Backend 'text_query_test' does not support correlation" in result.stdout
264+
assert "Backend 'text_query_test' does not support correlation" in result.stderr
265+
264266

265267
def test_convert_invalid_correlation_method():
266268
cli = CliRunner()
267269
result = cli.invoke(
268270
convert, ["-t", "text_query_test", "-f", "str", "-c", "invalid", "tests/files/valid"]
269271
)
270272
assert result.exit_code != 0
271-
assert "Correlation method 'invalid' is not supported" in result.stdout
273+
assert "Correlation method 'invalid' is not supported" in result.stderr

tests/test_filters.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55

66
def test_filter_basic_operation():
7-
cli = CliRunner(
8-
mix_stderr=True
9-
)
7+
cli = CliRunner()
108
result = cli.invoke(
119
convert, ["-t", "text_query_test", "--filter", "tests/files/sigma_filter.yml", "tests/files/valid/sigma_rule.yml"],
1210
)
@@ -35,9 +33,7 @@ def test_filter_basic_from_stdin():
3533

3634

3735
def test_filter_with_pipeline_mapping():
38-
cli = CliRunner(
39-
mix_stderr=True
40-
)
36+
cli = CliRunner()
4137
result = cli.invoke(
4238
convert, [
4339
"-t",

0 commit comments

Comments
 (0)