Skip to content

Commit 48e1a3b

Browse files
committed
add a bit of coverage to get CI to pass
1 parent 89d4a14 commit 48e1a3b

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

modernize/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
from modernize.main import main
66

7-
sys.exit(main())
7+
if __name__ == "__main__":
8+
sys.exit(main())

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ addopts = [
3838
"--strict-config",
3939
"--strict-markers",
4040
"--cov",
41-
"--cov-fail-under=91.53",
41+
"--cov-fail-under=92.11",
4242
"--cov-report=term-missing:skip-covered",
4343
]
4444
xfail_strict = true

tests/test_future_behaviour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from utils import check_on_input
1010

11-
from modernize.main import main as modernize_main
11+
from modernize.__main__ import main as modernize_main
1212

1313
SINGLE_PRINT_CONTENT = """
1414
print 'world'

tests/test_main.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
from __future__ import generator_stop
22

3-
import sys
4-
5-
try:
6-
from StringIO import StringIO # Python 2
7-
except ImportError:
8-
from io import StringIO # Python 3
3+
import contextlib
4+
import io
95

106
from utils import check_on_input
117

12-
from modernize.main import main as modernize_main
8+
from modernize.__main__ import main as modernize_main
139

1410

1511
def test_list_fixers():
16-
sio = StringIO()
17-
real_stdout = sys.stdout
18-
sys.stdout = sio
19-
try:
20-
exitcode = modernize_main(["-l"])
21-
finally:
22-
sys.stdout = real_stdout
23-
assert exitcode == 0, exitcode
24-
assert "xrange_six" in sio.getvalue()
12+
stdout = io.StringIO()
13+
with contextlib.redirect_stdout(stdout):
14+
returncode = modernize_main(["-l"])
15+
assert returncode == 0
16+
assert "xrange_six" in stdout.getvalue()
17+
18+
19+
def test_nofix_fixers(tmp_path):
20+
stdout = io.StringIO()
21+
stderr = io.StringIO()
22+
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
23+
returncode = modernize_main(["--nofix=ham", str(tmp_path)])
24+
25+
assert returncode == 2
26+
assert stderr.getvalue() == "Error: fix 'ham' was not found\n"
27+
assert stdout.getvalue() == ""
2528

2629

2730
NO_SIX_SAMPLE = """\

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import tempfile
66

7-
from modernize.main import main as modernize_main
7+
from modernize.__main__ import main as modernize_main
88

99

1010
def check_on_input(

0 commit comments

Comments
 (0)