11import os
2+ from pickle import dump
23import sys
34from test .support import captured_stdout
4- from test .support .os_helper import TESTFN , TESTFN_UNICODE , FS_NONASCII , rmtree , unlink
5+ from test .support .os_helper import ( TESTFN , rmtree , unlink )
56from test .support .script_helper import assert_python_ok , assert_python_failure
67import textwrap
78import unittest
1112
1213from test .tracedmodules import testmod
1314
15+ ##
16+ ## See also test_sys_settrace.py, which contains tests that cover
17+ ## tracing of many more code blocks.
18+ ##
19+
1420#------------------------------- Utilities -----------------------------------#
1521
1622def fix_ext_py (filename ):
@@ -191,7 +197,7 @@ def test_trace_list_comprehension(self):
191197 firstlineno_called = get_firstlineno (traced_doubler )
192198 expected = {
193199 (self .my_py_filename , firstlineno_calling + 1 ): 1 ,
194- # List compehentions work differently in 3.x, so the count
200+ # List comprehensions work differently in 3.x, so the count
195201 # below changed compared to 2.x.
196202 (self .my_py_filename , firstlineno_calling + 2 ): 12 ,
197203 (self .my_py_filename , firstlineno_calling + 3 ): 1 ,
@@ -212,9 +218,9 @@ def test_traced_decorated_function(self):
212218 (self .my_py_filename , firstlineno + 4 ): 1 ,
213219 (self .my_py_filename , firstlineno + 5 ): 1 ,
214220 (self .my_py_filename , firstlineno + 6 ): 1 ,
215- (self .my_py_filename , firstlineno + 7 ): 1 ,
216- (self .my_py_filename , firstlineno + 8 ): 1 ,
217- (self .my_py_filename , firstlineno + 9 ): 1 ,
221+ (self .my_py_filename , firstlineno + 7 ): 2 ,
222+ (self .my_py_filename , firstlineno + 8 ): 2 ,
223+ (self .my_py_filename , firstlineno + 9 ): 2 ,
218224 (self .my_py_filename , firstlineno + 10 ): 1 ,
219225 (self .my_py_filename , firstlineno + 11 ): 1 ,
220226 }
@@ -297,9 +303,8 @@ def test_simple_caller(self):
297303 def test_arg_errors (self ):
298304 res = self .tracer .runfunc (traced_capturer , 1 , 2 , self = 3 , func = 4 )
299305 self .assertEqual (res , ((1 , 2 ), {'self' : 3 , 'func' : 4 }))
300- with self .assertWarns (DeprecationWarning ):
301- res = self .tracer .runfunc (func = traced_capturer , arg = 1 )
302- self .assertEqual (res , ((), {'arg' : 1 }))
306+ with self .assertRaises (TypeError ):
307+ self .tracer .runfunc (func = traced_capturer , arg = 1 )
303308 with self .assertRaises (TypeError ):
304309 self .tracer .runfunc ()
305310
@@ -406,7 +411,7 @@ def test_coverage(self):
406411
407412 def test_coverage_ignore (self ):
408413 # Ignore all files, nothing should be traced nor printed
409- libpath = os .path .normpath (os .path .dirname (os .__file__ ))
414+ libpath = os .path .normpath (os .path .dirname (os .path . dirname ( __file__ ) ))
410415 # sys.prefix does not work when running from a checkout
411416 tracer = trace .Trace (ignoredirs = [sys .base_prefix , sys .base_exec_prefix ,
412417 libpath ], trace = 0 , count = 1 )
@@ -439,6 +444,15 @@ def test_issue9936(self):
439444 self .assertIn (modname , coverage )
440445 self .assertEqual (coverage [modname ], (5 , 100 ))
441446
447+ def test_coverageresults_update (self ):
448+ # Update empty CoverageResults with a non-empty infile.
449+ infile = TESTFN + '-infile'
450+ with open (infile , 'wb' ) as f :
451+ dump (({}, {}, {'caller' : 1 }), f , protocol = 1 )
452+ self .addCleanup (unlink , infile )
453+ results = trace .CoverageResults ({}, {}, infile , {})
454+ self .assertEqual (results .callers , {'caller' : 1 })
455+
442456### Tests that don't mess with sys.settrace and can be traced
443457### themselves TODO: Skip tests that do mess with sys.settrace when
444458### regrtest is invoked with -T option.
@@ -547,7 +561,8 @@ def test_sys_argv_list(self):
547561 fd .write ("print(type(sys.argv))\n " )
548562
549563 status , direct_stdout , stderr = assert_python_ok (TESTFN )
550- status , trace_stdout , stderr = assert_python_ok ('-m' , 'trace' , '-l' , TESTFN )
564+ status , trace_stdout , stderr = assert_python_ok ('-m' , 'trace' , '-l' , TESTFN ,
565+ PYTHONIOENCODING = 'utf-8' )
551566 self .assertIn (direct_stdout .strip (), trace_stdout )
552567
553568 # TODO: RUSTPYTHON
@@ -569,7 +584,8 @@ def f():
569584 for i in range(10):
570585 f()
571586 """ ))
572- status , stdout , _ = assert_python_ok ('-m' , 'trace' , '-cs' , filename )
587+ status , stdout , _ = assert_python_ok ('-m' , 'trace' , '-cs' , filename ,
588+ PYTHONIOENCODING = 'utf-8' )
573589 stdout = stdout .decode ()
574590 self .assertEqual (status , 0 )
575591 self .assertIn ('lines cov% module (path)' , stdout )
0 commit comments