1
1
import os
2
2
import sys
3
- from test .support import TESTFN , rmtree , unlink , captured_stdout
3
+ from test .support import TESTFN , TESTFN_UNICODE , FS_NONASCII , rmtree , unlink , captured_stdout
4
4
from test .support .script_helper import assert_python_ok , assert_python_failure
5
5
import textwrap
6
6
import unittest
@@ -428,9 +428,10 @@ class TestCoverageCommandLineOutput(unittest.TestCase):
428
428
coverfile = 'tmp.cover'
429
429
430
430
def setUp (self ):
431
- with open (self .codefile , 'w' ) as f :
431
+ with open (self .codefile , 'w' , encoding = 'iso-8859-15' ) as f :
432
432
f .write (textwrap .dedent ('''\
433
- x = 42
433
+ # coding: iso-8859-15
434
+ x = 'spœm'
434
435
if []:
435
436
print('unreachable')
436
437
''' ))
@@ -451,9 +452,10 @@ def test_cover_files_written_no_highlight(self):
451
452
self .assertEqual (stderr , b'' )
452
453
self .assertFalse (os .path .exists (tracecoverpath ))
453
454
self .assertTrue (os .path .exists (self .coverfile ))
454
- with open (self .coverfile ) as f :
455
+ with open (self .coverfile , encoding = 'iso-8859-15' ) as f :
455
456
self .assertEqual (f .read (),
456
- " 1: x = 42\n "
457
+ " # coding: iso-8859-15\n "
458
+ " 1: x = 'spœm'\n "
457
459
" 1: if []:\n "
458
460
" print('unreachable')\n "
459
461
)
@@ -462,9 +464,10 @@ def test_cover_files_written_with_highlight(self):
462
464
argv = '-m trace --count --missing' .split () + [self .codefile ]
463
465
status , stdout , stderr = assert_python_ok (* argv )
464
466
self .assertTrue (os .path .exists (self .coverfile ))
465
- with open (self .coverfile ) as f :
467
+ with open (self .coverfile , encoding = 'iso-8859-15' ) as f :
466
468
self .assertEqual (f .read (), textwrap .dedent ('''\
467
- 1: x = 42
469
+ # coding: iso-8859-15
470
+ 1: x = 'spœm'
468
471
1: if []:
469
472
>>>>>> print('unreachable')
470
473
''' ))
@@ -485,15 +488,19 @@ def test_failures(self):
485
488
self .assertIn (message , stderr )
486
489
487
490
def test_listfuncs_flag_success (self ):
488
- with open (TESTFN , 'w' ) as fd :
489
- self .addCleanup (unlink , TESTFN )
491
+ filename = TESTFN + '.py'
492
+ modulename = os .path .basename (TESTFN )
493
+ with open (filename , 'w' , encoding = 'utf-8' ) as fd :
494
+ self .addCleanup (unlink , filename )
490
495
fd .write ("a = 1\n " )
491
- status , stdout , stderr = assert_python_ok ('-m' , 'trace' , '-l' , TESTFN ,
496
+ status , stdout , stderr = assert_python_ok ('-m' , 'trace' , '-l' , filename ,
492
497
PYTHONIOENCODING = 'utf-8' )
493
498
self .assertIn (b'functions called:' , stdout )
499
+ expected = f'filename: { filename } , modulename: { modulename } , funcname: <module>'
500
+ self .assertIn (expected .encode (), stdout )
494
501
495
502
def test_sys_argv_list (self ):
496
- with open (TESTFN , 'w' ) as fd :
503
+ with open (TESTFN , 'w' , encoding = 'utf-8' ) as fd :
497
504
self .addCleanup (unlink , TESTFN )
498
505
fd .write ("import sys\n " )
499
506
fd .write ("print(type(sys.argv))\n " )
@@ -506,7 +513,8 @@ def test_sys_argv_list(self):
506
513
def test_count_and_summary (self ):
507
514
filename = f'{ TESTFN } .py'
508
515
coverfilename = f'{ TESTFN } .cover'
509
- with open (filename , 'w' ) as fd :
516
+ modulename = os .path .basename (TESTFN )
517
+ with open (filename , 'w' , encoding = 'utf-8' ) as fd :
510
518
self .addCleanup (unlink , filename )
511
519
self .addCleanup (unlink , coverfilename )
512
520
fd .write (textwrap .dedent ("""\
@@ -524,7 +532,7 @@ def f():
524
532
stdout = stdout .decode ()
525
533
self .assertEqual (status , 0 )
526
534
self .assertIn ('lines cov% module (path)' , stdout )
527
- self .assertIn (f'6 100% { TESTFN } ({ filename } )' , stdout )
535
+ self .assertIn (f'6 100% { modulename } ({ filename } )' , stdout )
528
536
529
537
def test_run_as_module (self ):
530
538
assert_python_ok ('-m' , 'trace' , '-l' , '--module' , 'timeit' , '-n' , '1' )
0 commit comments