Skip to content

Commit 8a4491e

Browse files
amurekicodingjoe
authored andcommitted
Make sure we receive int exit code
1 parent 1dfb345 commit 8a4491e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

tests/fixtures/.relint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
hint: Get it done right away!
44
filePattern: ^(?!.*test_).*\.(py|js)$
55
error: false
6+
7+
- name: No fixme (warning)
8+
pattern: '[fF][iI][xX][mM][eE]'
9+
hint: Fix it right away!
10+
filePattern: ^(?!.*test_).*\.(py|js)$
11+
error: true

tests/test_main.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,32 @@ def test_version(tmpdir, capsys):
1717

1818

1919
class TestMain:
20-
@pytest.mark.parametrize("filename", ["test_parse.py", "[a-b].py", "[b-a].py"])
21-
def test_main_execution(self, filename, tmpdir, fixture_dir):
20+
def test_main_execution(self, tmpdir, fixture_dir):
2221
with (fixture_dir / ".relint.yml").open() as fs:
2322
config = fs.read()
2423
tmpdir.join(".relint.yml").write(config)
24+
tmpdir.join("dummy.py").write("# TODO do something")
2525
with tmpdir.as_cwd():
2626
with pytest.raises(SystemExit) as exc_info:
27-
main(["relint.py", filename])
27+
main(["relint.py", "dummy.py"])
2828

2929
assert exc_info.value.code == 0
3030

31+
def test_main_execution_with_error(self, capsys, tmpdir, fixture_dir):
32+
with (fixture_dir / ".relint.yml").open() as fs:
33+
config = fs.read()
34+
tmpdir.join(".relint.yml").write(config)
35+
tmpdir.join("dummy.py").write("# FIXME do something")
36+
with tmpdir.as_cwd():
37+
with pytest.raises(SystemExit) as exc_info:
38+
main(["relint.py", "dummy.py"])
39+
40+
expected_message = "dummy.py:1 No fixme (warning)\nHint: Fix it right away!\n1> # FIXME do something\n"
41+
42+
out, _ = capsys.readouterr()
43+
assert expected_message == out
44+
assert exc_info.value.code == 1
45+
3146
def test_main_execution_with_custom_template(self, capsys, tmpdir, fixture_dir):
3247
with (fixture_dir / ".relint.yml").open() as fs:
3348
config = fs.read()
@@ -45,16 +60,16 @@ def test_main_execution_with_custom_template(self, capsys, tmpdir, fixture_dir):
4560
assert expected_message == out
4661
assert exc_info.value.code == 0
4762

48-
@pytest.mark.parametrize("filename", ["test_parse.py", "[a-b].py", "[b-a].py"])
49-
def test_raise_for_warnings(self, filename, tmpdir, fixture_dir):
63+
def test_raise_for_warnings(self, tmpdir, fixture_dir):
5064
with (fixture_dir / ".relint.yml").open() as fs:
5165
config = fs.read()
5266
tmpdir.join(".relint.yml").write(config)
67+
tmpdir.join("dummy.py").write("# TODO do something")
5368
with tmpdir.as_cwd():
5469
with pytest.raises(SystemExit) as exc_info:
55-
main(["relint.py", "-W", filename])
70+
main(["relint.py", "dummy.py", "-W"])
5671

57-
assert exc_info.value.code != 0
72+
assert exc_info.value.code == 1
5873

5974
def test_main_execution_with_diff(self, capsys, mocker, tmpdir, fixture_dir):
6075
with (fixture_dir / ".relint.yml").open() as fs:

0 commit comments

Comments
 (0)