Skip to content

Commit 17a3965

Browse files
committed
Add more tests (check that CodePrinter works as a predicate).
1 parent cad2e00 commit 17a3965

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

tests/sample4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""nothing"""

tests/test_hunter.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def test_pth_activation():
5757
assert expected_call.encode() in output
5858

5959

60+
def test_pth_sample4():
61+
env = dict(os.environ, PYTHONHUNTER="CodePrinter")
62+
env.pop('COVERAGE_PROCESS_START', None)
63+
env.pop('COV_CORE_SOURCE', None)
64+
output = subprocess.check_output(
65+
[sys.executable, os.path.join(os.path.dirname(__file__), 'sample4.py')],
66+
env=env,
67+
stderr=subprocess.STDOUT,
68+
)
69+
assert output
70+
71+
6072
def test_pth_sample2():
6173
env = dict(os.environ, PYTHONHUNTER="module='__main__'")
6274
env.pop('COVERAGE_PROCESS_START', None)
@@ -66,7 +78,7 @@ def test_pth_sample2():
6678
env=env,
6779
stderr=subprocess.STDOUT,
6880
)
69-
for line, expected in izip_longest(output.decode('utf8').splitlines(), [
81+
for line, expected in izip_longest(output.decode('utf-8').splitlines(), [
7082
'* tests*sample2.py:* call if __name__ == "__main__": #*',
7183
'* tests*sample2.py:* line if __name__ == "__main__": #*',
7284
'* tests*sample2.py:* line import functools',
@@ -198,14 +210,14 @@ def a():
198210
], fillvalue="MISSING"):
199211
assert fnmatchcase(line, expected), "%r didn't match %r" % (line, expected)
200212

213+
201214
def test_tracing_printing_failures():
202215
lines = StringIO()
203-
with trace(CodePrinter(stream=lines),VarsPrinter("x", stream=lines)):
216+
with trace(CodePrinter(stream=lines), VarsPrinter("x", stream=lines)):
204217
class Bad(Exception):
205218
def __repr__(self):
206219
raise RuntimeError("I'm a bad class!")
207220

208-
209221
def a():
210222
x = Bad()
211223
return x
@@ -355,3 +367,12 @@ def test_trace_api_expansion():
355367
function="foobar", actions=[VarsPrinter("foobar"), Debugger]), module="foo",)
356368
assert trace(Q(function="foobar", actions=[VarsPrinter("foobar"),
357369
lambda event: print("some custom output")]), module="foo",)
370+
371+
372+
def test_trace_with_class_actions():
373+
with trace(CodePrinter):
374+
def a():
375+
pass
376+
377+
a()
378+

0 commit comments

Comments
 (0)