1
1
import os
2
+ from pickle import dump
2
3
import sys
3
4
from 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 )
5
6
from test .support .script_helper import assert_python_ok , assert_python_failure
6
7
import textwrap
7
8
import unittest
11
12
12
13
from test .tracedmodules import testmod
13
14
15
+ ##
16
+ ## See also test_sys_settrace.py, which contains tests that cover
17
+ ## tracing of many more code blocks.
18
+ ##
19
+
14
20
#------------------------------- Utilities -----------------------------------#
15
21
16
22
def fix_ext_py (filename ):
@@ -191,7 +197,7 @@ def test_trace_list_comprehension(self):
191
197
firstlineno_called = get_firstlineno (traced_doubler )
192
198
expected = {
193
199
(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
195
201
# below changed compared to 2.x.
196
202
(self .my_py_filename , firstlineno_calling + 2 ): 12 ,
197
203
(self .my_py_filename , firstlineno_calling + 3 ): 1 ,
@@ -212,9 +218,9 @@ def test_traced_decorated_function(self):
212
218
(self .my_py_filename , firstlineno + 4 ): 1 ,
213
219
(self .my_py_filename , firstlineno + 5 ): 1 ,
214
220
(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 ,
218
224
(self .my_py_filename , firstlineno + 10 ): 1 ,
219
225
(self .my_py_filename , firstlineno + 11 ): 1 ,
220
226
}
@@ -297,9 +303,8 @@ def test_simple_caller(self):
297
303
def test_arg_errors (self ):
298
304
res = self .tracer .runfunc (traced_capturer , 1 , 2 , self = 3 , func = 4 )
299
305
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 )
303
308
with self .assertRaises (TypeError ):
304
309
self .tracer .runfunc ()
305
310
@@ -406,7 +411,7 @@ def test_coverage(self):
406
411
407
412
def test_coverage_ignore (self ):
408
413
# 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__ ) ))
410
415
# sys.prefix does not work when running from a checkout
411
416
tracer = trace .Trace (ignoredirs = [sys .base_prefix , sys .base_exec_prefix ,
412
417
libpath ], trace = 0 , count = 1 )
@@ -439,6 +444,15 @@ def test_issue9936(self):
439
444
self .assertIn (modname , coverage )
440
445
self .assertEqual (coverage [modname ], (5 , 100 ))
441
446
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
+
442
456
### Tests that don't mess with sys.settrace and can be traced
443
457
### themselves TODO: Skip tests that do mess with sys.settrace when
444
458
### regrtest is invoked with -T option.
@@ -547,7 +561,8 @@ def test_sys_argv_list(self):
547
561
fd .write ("print(type(sys.argv))\n " )
548
562
549
563
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' )
551
566
self .assertIn (direct_stdout .strip (), trace_stdout )
552
567
553
568
# TODO: RUSTPYTHON
@@ -569,7 +584,8 @@ def f():
569
584
for i in range(10):
570
585
f()
571
586
""" ))
572
- status , stdout , _ = assert_python_ok ('-m' , 'trace' , '-cs' , filename )
587
+ status , stdout , _ = assert_python_ok ('-m' , 'trace' , '-cs' , filename ,
588
+ PYTHONIOENCODING = 'utf-8' )
573
589
stdout = stdout .decode ()
574
590
self .assertEqual (status , 0 )
575
591
self .assertIn ('lines cov% module (path)' , stdout )
0 commit comments