55import py_compile
66import sys
77from test import support
8- from test .support import script_helper , os_helper , import_helper
8+ from test .support import import_helper
9+ from test .support import os_helper
10+ from test .support import script_helper
911import unittest
1012import warnings
1113with warnings .catch_warnings ():
@@ -57,11 +59,10 @@ def testLock(self):
5759 "RuntimeError" )
5860
5961class ImportTests (unittest .TestCase ):
60- # TODO: RustPython
61- # def setUp(self):
62- # mod = importlib.import_module('test.encoded_modules')
63- # self.test_strings = mod.test_strings
64- # self.test_path = mod.__path__
62+ def setUp (self ):
63+ mod = importlib .import_module ('test.encoded_modules' )
64+ self .test_strings = mod .test_strings
65+ self .test_path = mod .__path__
6566
6667 # TODO: RUSTPYTHON
6768 @unittest .expectedFailure
@@ -71,8 +72,6 @@ def test_import_encoded_module(self):
7172 'module_' + modname )
7273 self .assertEqual (teststr , mod .test )
7374
74- # TODO: RUSTPYTHON
75- @unittest .expectedFailure
7675 def test_find_module_encoding (self ):
7776 for mod , encoding , _ in self .test_strings :
7877 with imp .find_module ('module_' + mod , self .test_path )[0 ] as fd :
@@ -82,8 +81,6 @@ def test_find_module_encoding(self):
8281 with self .assertRaises (SyntaxError ):
8382 imp .find_module ('badsyntax_pep3120' , path )
8483
85- # TODO: RUSTPYTHON
86- @unittest .expectedFailure
8784 def test_issue1267 (self ):
8885 for mod , encoding , _ in self .test_strings :
8986 fp , filename , info = imp .find_module ('module_' + mod ,
@@ -107,7 +104,7 @@ def test_issue3594(self):
107104 temp_mod_name = 'test_imp_helper'
108105 sys .path .insert (0 , '.' )
109106 try :
110- with open (temp_mod_name + '.py' , 'w' ) as file :
107+ with open (temp_mod_name + '.py' , 'w' , encoding = "latin-1" ) as file :
111108 file .write ("# coding: cp1252\n u = 'test.test_imp'\n " )
112109 file , filename , info = imp .find_module (temp_mod_name )
113110 file .close ()
@@ -162,7 +159,7 @@ def test_issue5604(self):
162159 # if the curdir is not in sys.path the test fails when run with
163160 # ./python ./Lib/test/regrtest.py test_imp
164161 sys .path .insert (0 , os .curdir )
165- with open (temp_mod_name + '.py' , 'w' ) as file :
162+ with open (temp_mod_name + '.py' , 'w' , encoding = "utf-8" ) as file :
166163 file .write ('a = 1\n ' )
167164 file , filename , info = imp .find_module (temp_mod_name )
168165 with file :
@@ -190,7 +187,7 @@ def test_issue5604(self):
190187
191188 if not os .path .exists (test_package_name ):
192189 os .mkdir (test_package_name )
193- with open (init_file_name , 'w' ) as file :
190+ with open (init_file_name , 'w' , encoding = "utf-8" ) as file :
194191 file .write ('b = 2\n ' )
195192 with warnings .catch_warnings ():
196193 warnings .simplefilter ('ignore' )
@@ -315,7 +312,7 @@ def test_bug7732(self):
315312 def test_multiple_calls_to_get_data (self ):
316313 # Issue #18755: make sure multiple calls to get_data() can succeed.
317314 loader = imp ._LoadSourceCompatibility ('imp' , imp .__file__ ,
318- open (imp .__file__ ))
315+ open (imp .__file__ , encoding = "utf-8" ))
319316 loader .get_data (imp .__file__ ) # File should be closed
320317 loader .get_data (imp .__file__ ) # Will need to create a newly opened file
321318
@@ -396,7 +393,7 @@ class ReloadTests(unittest.TestCase):
396393 reload()."""
397394
398395 def test_source (self ):
399- # XXX (ncoghlan): It would be nice to use test.support .CleanImport
396+ # XXX (ncoghlan): It would be nice to use test.import_helper .CleanImport
400397 # here, but that breaks because the os module registers some
401398 # handlers in copy_reg on import. Since CleanImport doesn't
402399 # revert that registration, the module is left in a broken
0 commit comments