Skip to content

Commit 07b8f3d

Browse files
committed
split and tidy tests
1 parent 22a6ffd commit 07b8f3d

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

examples/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ IPY=python -c
44
err
55

66
hello:
7-
# this is a comment
8-
$(IPY) "print('hello world')"
7+
# this is a comment followed by a multi-line command
8+
$(IPY) \
9+
"print('hello world')"
910

1011
err:
1112
keyboardmashitalltogetherthisshouldnotrunotherwiseunittestswillfail

pymake/tests/tests_main.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
from textwrap import dedent
55
from pymake import main, PymakeKeyError, PymakeTypeError
66

7+
dn = path.dirname
8+
fname = path.join(dn(dn(dn(path.abspath(__file__)))),
9+
"examples", "Makefile").replace('\\', '/')
10+
711

812
def _sh(*cmd, **kwargs):
913
return subprocess.Popen(cmd, stdout=subprocess.PIPE,
1014
**kwargs).communicate()[0].decode('utf-8')
1115

1216

13-
# WARNING: this should be the last test as it messes with sys.stdin, argv
1417
def test_main():
1518
"""Test execution"""
16-
dn = path.dirname
17-
fname = path.join(dn(dn(dn(path.abspath(__file__)))),
18-
"examples", "Makefile").replace('\\', '/')
1919
res = _sh(sys.executable, '-c', dedent('''\
2020
from pymake import main; import sys
2121
sys.argv = ["", "-f", "''' + fname + '''"]
@@ -27,12 +27,15 @@ def test_main():
2727
assert ("hello world" in res)
2828

2929
# semi-fake test which gets coverage:
30-
_SYS = sys.stdin, sys.argv
31-
30+
_SYS = sys.argv
3231
sys.argv = ['', '-f', fname]
3332
main()
33+
sys.argv = _SYS
34+
3435

36+
def test_invalid_alias():
3537
"""Test invalid alias"""
38+
_SYS = sys.argv
3639
sys.argv = ['', '-f', fname, 'foo']
3740
try:
3841
main()
@@ -41,21 +44,37 @@ def test_main():
4144
raise
4245
else:
4346
raise PymakeKeyError('foo')
47+
sys.argv = _SYS
4448

49+
50+
def test_multi_target():
4551
"""Test various targets"""
52+
_SYS = sys.argv
4653
for trg in ['circle', 'empty', 'one']:
4754
sys.argv = ['', '-s', '-f', fname, trg]
4855
main()
56+
sys.argv = _SYS
57+
4958

59+
def test_print_data_base():
5060
"""Test --print-data-base with errors"""
61+
_SYS = sys.argv
5162
sys.argv = ['', '-s', '-p', '-f', fname, 'err']
5263
main()
64+
sys.argv = _SYS
5365

66+
67+
def test_just_print():
5468
"""Test --just-print with errors"""
69+
_SYS = sys.argv
5570
sys.argv = ['', '-s', '-n', '-f', fname, 'err']
5671
main()
72+
sys.argv = _SYS
73+
5774

75+
def test_ignore_errors():
5876
"""Test --ignore-errors"""
77+
_SYS = sys.argv
5978
sys.argv = ['', '-s', '-f', fname, 'err']
6079
try:
6180
main()
@@ -66,14 +85,16 @@ def test_main():
6685

6786
sys.argv = ['', '-s', '-i', '-f', fname, 'err']
6887
main()
88+
sys.argv = _SYS
6989

90+
91+
def test_help_version():
7092
"""Test help and version"""
93+
_SYS = sys.argv
7194
for i in ('-h', '--help', '-v', '--version'):
7295
sys.argv = ['', i]
7396
try:
7497
main()
7598
except SystemExit:
7699
pass
77-
78-
# clean up
79-
sys.stdin, sys.argv = _SYS
100+
sys.argv = _SYS

0 commit comments

Comments
 (0)