Skip to content

Commit e391fbe

Browse files
committed
Fix sys.argv pathing in tests and fix test of main execution with diff
1 parent d5443b7 commit e391fbe

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ setup_requires =
2929
tests_require =
3030
pytest
3131
pytest-cov
32+
pytest-mock
3233
py_modules = relint
3334

3435
[options.entry_points]

test_relint.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import sys
23

34
import pytest
@@ -7,18 +8,29 @@
78

89

910
class TestMain:
10-
def test_main_execution(self):
11-
sys.argv.extend(['relint.py', 'test_relint.py'])
11+
def test_main_execution(self, mocker):
12+
mocker.patch.object(sys, 'argv', ['relint.py', 'test_relint.py'])
13+
1214
with pytest.raises(SystemExit) as exc_info:
1315
main()
1416

1517
assert exc_info.value.code == 0
1618

17-
def test_main_execution_with_diff(self, capsys):
18-
sys.argv.extend(['relint.py', 'test_relint.py', '--diff'])
19-
sys.stdin = open('test.diff')
20-
with pytest.raises(SystemExit) as exc_info:
21-
main()
19+
def test_main_execution_with_diff(self, capsys, mocker, tmpdir):
20+
tmpdir.join('.relint.yml').write(open('.relint.yml').read())
21+
tmpdir.join('dummy.py').write("# TODO do something")
22+
diff = io.StringIO(
23+
"diff --git a/dummy.py b/dummy.py\n"
24+
"@@ -0,0 +1 @@\n"
25+
"+# TODO do something"
26+
)
27+
28+
mocker.patch.object(sys, 'argv', ['relint.py', 'dummy.py', '--diff'])
29+
mocker.patch.object(sys, 'stdin', diff)
30+
31+
with tmpdir.as_cwd():
32+
with pytest.raises(SystemExit) as exc_info:
33+
main()
2234

2335
expected_message = 'Hint: Get it done right away!'
2436

0 commit comments

Comments
 (0)