@@ -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+
6072def 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+
201214def 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