@@ -58,7 +58,7 @@ def setUp(self):
5858 self .directory = tempfile .mkdtemp ()
5959 self .source_path = os .path .join (self .directory , '_test.py' )
6060 self .bc_path = importlib .util .cache_from_source (self .source_path )
61- with open (self .source_path , 'w' ) as file :
61+ with open (self .source_path , 'w' , encoding = "utf-8" ) as file :
6262 file .write ('x = 123\n ' )
6363 self .source_path2 = os .path .join (self .directory , '_test2.py' )
6464 self .bc_path2 = importlib .util .cache_from_source (self .source_path2 )
@@ -73,7 +73,7 @@ def tearDown(self):
7373
7474 def add_bad_source_file (self ):
7575 self .bad_source_path = os .path .join (self .directory , '_test_bad.py' )
76- with open (self .bad_source_path , 'w' ) as file :
76+ with open (self .bad_source_path , 'w' , encoding = "utf-8" ) as file :
7777 file .write ('x (\n ' )
7878
7979 def timestamp_metadata (self ):
@@ -164,7 +164,7 @@ def test_no_pycache_in_non_package(self):
164164 data_file = os .path .join (data_dir , 'file' )
165165 os .mkdir (data_dir )
166166 # touch data/file
167- with open (data_file , 'w ' ):
167+ with open (data_file , 'wb ' ):
168168 pass
169169 compileall .compile_file (data_file )
170170 self .assertFalse (os .path .exists (os .path .join (data_dir , '__pycache__' )))
@@ -440,8 +440,7 @@ def setUpClass(cls):
440440 if not directory .is_dir ():
441441 directory .mkdir ()
442442 directory_created = True
443- with path .open ('w' ) as file :
444- file .write ('# for test_compileall' )
443+ path .write_text ('# for test_compileall' , encoding = "utf-8" )
445444 except OSError :
446445 sys_path_writable = False
447446 break
@@ -704,7 +703,7 @@ def test_include_file_with_arg(self):
704703 f2 = script_helper .make_script (self .pkgdir , 'f2' , '' )
705704 f3 = script_helper .make_script (self .pkgdir , 'f3' , '' )
706705 f4 = script_helper .make_script (self .pkgdir , 'f4' , '' )
707- with open (os .path .join (self .directory , 'l1' ), 'w' ) as l1 :
706+ with open (os .path .join (self .directory , 'l1' ), 'w' , encoding = "utf-8" ) as l1 :
708707 l1 .write (os .path .join (self .pkgdir , 'f1.py' )+ os .linesep )
709708 l1 .write (os .path .join (self .pkgdir , 'f2.py' )+ os .linesep )
710709 self .assertRunOK ('-i' , os .path .join (self .directory , 'l1' ), f4 )
@@ -718,7 +717,7 @@ def test_include_file_no_arg(self):
718717 f2 = script_helper .make_script (self .pkgdir , 'f2' , '' )
719718 f3 = script_helper .make_script (self .pkgdir , 'f3' , '' )
720719 f4 = script_helper .make_script (self .pkgdir , 'f4' , '' )
721- with open (os .path .join (self .directory , 'l1' ), 'w' ) as l1 :
720+ with open (os .path .join (self .directory , 'l1' ), 'w' , encoding = "utf-8" ) as l1 :
722721 l1 .write (os .path .join (self .pkgdir , 'f2.py' )+ os .linesep )
723722 self .assertRunOK ('-i' , os .path .join (self .directory , 'l1' ))
724723 self .assertNotCompiled (f1 )
0 commit comments