Skip to content

Commit 9df15e3

Browse files
committed
Add test for the multiple line call statements.
1 parent 6170ed0 commit 9df15e3

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

tests/sample2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- encoding: utf-8 -*-
2+
if __name__ == "__main__":
3+
import functools
4+
5+
def deco(opt):
6+
def decorator(func):
7+
@functools.wraps(func)
8+
def wrapper(*args):
9+
return func(*args)
10+
return wrapper
11+
return decorator
12+
13+
@deco(1)
14+
@deco(2)
15+
@deco(3)
16+
def foo(*args):
17+
return args
18+
19+
foo(
20+
'a',
21+
'b'
22+
)
23+
try:
24+
None(
25+
'a',
26+
'b'
27+
) # doh!
28+
except:
29+
pass

tests/simple.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
""" s@tart
2+
1
3+
2
4+
3
5+
4
6+
""" # end
7+
class Foo(object):
8+
9+
@staticmethod
10+
def a(*args):
11+
return args
12+
13+
b = staticmethod(
14+
lambda *a:
15+
a
16+
)
17+
18+
19+
def deco(_):
20+
return lambda func: lambda *a: func(*a)
21+
22+
23+
@deco(1)
24+
@deco(2)
25+
@deco(3)
26+
@deco(4)
27+
def a(*args):
28+
return args
29+
30+
31+
Foo.a(
32+
1,
33+
2,
34+
3,
35+
)
36+
Foo.b(
37+
1,
38+
2,
39+
3,
40+
)
41+
a()

tests/test_hunter.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,92 @@ def test_pth_activation():
4040
assert b"posixpath.py" in output
4141
assert b"call def join(a, *p):" in output
4242

43+
def test_pth_sample2():
44+
env = dict(os.environ, PYTHONHUNTER="module='__main__'")
45+
env.pop('COVERAGE_PROCESS_START', None)
46+
env.pop('COV_CORE_SOURCE', None)
47+
output = subprocess.check_output(
48+
['python', os.path.join(os.path.dirname(__file__), 'sample2.py')],
49+
env=env,
50+
stderr=subprocess.STDOUT,
51+
)
52+
for line, expected in izip_longest(output.decode('utf8').splitlines(), [
53+
'* tests/sample2.py:* call if __name__ == "__main__":',
54+
'* tests/sample2.py:* line if __name__ == "__main__":',
55+
'* tests/sample2.py:* line import functools',
56+
'* tests/sample2.py:* line def deco(opt):',
57+
'* tests/sample2.py:* line @deco(1)',
58+
'* tests/sample2.py:* call def deco(opt):',
59+
'* tests/sample2.py:* line def decorator(func):',
60+
'* tests/sample2.py:* line return decorator',
61+
'* tests/sample2.py:* return return decorator',
62+
'* * ... return value: <function deco*',
63+
'* tests/sample2.py:* line @deco(2)',
64+
'* tests/sample2.py:* call def deco(opt):',
65+
'* tests/sample2.py:* line def decorator(func):',
66+
'* tests/sample2.py:* line return decorator',
67+
'* tests/sample2.py:* return return decorator',
68+
'* * ... return value: <function deco*',
69+
'* tests/sample2.py:* line @deco(3)',
70+
'* tests/sample2.py:* call def deco(opt):',
71+
'* tests/sample2.py:* line def decorator(func):',
72+
'* tests/sample2.py:* line return decorator',
73+
'* tests/sample2.py:* return return decorator',
74+
'* * ... return value: <function deco*',
75+
'* tests/sample2.py:* call def decorator(func):',
76+
'* tests/sample2.py:* line @functools.wraps(func)',
77+
'* tests/sample2.py:* line return wrapper',
78+
'* tests/sample2.py:* return return wrapper',
79+
'* * ... return value: <function foo *',
80+
'* tests/sample2.py:* call def decorator(func):',
81+
'* tests/sample2.py:* line @functools.wraps(func)',
82+
'* tests/sample2.py:* line return wrapper',
83+
'* tests/sample2.py:* return return wrapper',
84+
'* * ... return value: <function foo *',
85+
'* tests/sample2.py:* call def decorator(func):',
86+
'* tests/sample2.py:* line @functools.wraps(func)',
87+
'* tests/sample2.py:* line return wrapper',
88+
'* tests/sample2.py:* return return wrapper',
89+
'* * ... return value: <function foo *',
90+
'* tests/sample2.py:* line foo(',
91+
"* tests/sample2.py:* line 'a',",
92+
"* tests/sample2.py:* line 'b'",
93+
'* tests/sample2.py:* call @functools.wraps(func)',
94+
'* * | def wrapper(*args):',
95+
'* tests/sample2.py:* line return func(*args)',
96+
'* tests/sample2.py:* call @functools.wraps(func)',
97+
'* * | def wrapper(*args):',
98+
'* tests/sample2.py:* line return func(*args)',
99+
'* tests/sample2.py:* call @functools.wraps(func)',
100+
'* * | def wrapper(*args):',
101+
'* tests/sample2.py:* line return func(*args)',
102+
'* tests/sample2.py:* call @deco(1)',
103+
'* * | @deco(2)',
104+
'* * | @deco(3)',
105+
'* * | def foo(*args):',
106+
'* tests/sample2.py:* line return args',
107+
'* tests/sample2.py:* return return args',
108+
"* * ... return value: ('a', 'b')",
109+
"* tests/sample2.py:* return return func(*args)",
110+
"* * ... return value: ('a', 'b')",
111+
"* tests/sample2.py:* return return func(*args)",
112+
"* * ... return value: ('a', 'b')",
113+
"* tests/sample2.py:* return return func(*args)",
114+
"* * ... return value: ('a', 'b')",
115+
"* tests/sample2.py:* line try:",
116+
"* tests/sample2.py:* line None(",
117+
"* tests/sample2.py:* line 'a',",
118+
"* tests/sample2.py:* line 'b'",
119+
"* tests/sample2.py:* exception 'b'",
120+
"* * ... exception value: *",
121+
"* tests/sample2.py:* line except:",
122+
"* tests/sample2.py:* line pass",
123+
"* tests/sample2.py:* return pass",
124+
"* ... return value: None",
125+
], fillvalue="MISSING"):
126+
assert fnmatchcase(line, expected), "%r didn't match %r" % (line, expected)
127+
128+
43129
def test_repr():
44130
assert repr(Q(module='a')) == "Query(module='a')"
45131
assert str(Q(module='a')) == "Query(module='a')"

0 commit comments

Comments
 (0)