mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)
* Fix test_shutil * Fix test_imp * Fix test_import * Fix test_importlib
This commit is contained in:
parent
ee952b5c73
commit
c8e5eb904e
11 changed files with 55 additions and 50 deletions
|
@ -102,7 +102,7 @@ class ImportTests(unittest.TestCase):
|
|||
temp_mod_name = 'test_imp_helper'
|
||||
sys.path.insert(0, '.')
|
||||
try:
|
||||
with open(temp_mod_name + '.py', 'w') as file:
|
||||
with open(temp_mod_name + '.py', 'w', encoding="latin-1") as file:
|
||||
file.write("# coding: cp1252\nu = 'test.test_imp'\n")
|
||||
file, filename, info = imp.find_module(temp_mod_name)
|
||||
file.close()
|
||||
|
@ -157,7 +157,7 @@ class ImportTests(unittest.TestCase):
|
|||
# if the curdir is not in sys.path the test fails when run with
|
||||
# ./python ./Lib/test/regrtest.py test_imp
|
||||
sys.path.insert(0, os.curdir)
|
||||
with open(temp_mod_name + '.py', 'w') as file:
|
||||
with open(temp_mod_name + '.py', 'w', encoding="utf-8") as file:
|
||||
file.write('a = 1\n')
|
||||
file, filename, info = imp.find_module(temp_mod_name)
|
||||
with file:
|
||||
|
@ -185,7 +185,7 @@ class ImportTests(unittest.TestCase):
|
|||
|
||||
if not os.path.exists(test_package_name):
|
||||
os.mkdir(test_package_name)
|
||||
with open(init_file_name, 'w') as file:
|
||||
with open(init_file_name, 'w', encoding="utf-8") as file:
|
||||
file.write('b = 2\n')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
|
@ -310,7 +310,7 @@ class ImportTests(unittest.TestCase):
|
|||
def test_multiple_calls_to_get_data(self):
|
||||
# Issue #18755: make sure multiple calls to get_data() can succeed.
|
||||
loader = imp._LoadSourceCompatibility('imp', imp.__file__,
|
||||
open(imp.__file__))
|
||||
open(imp.__file__, encoding="utf-8"))
|
||||
loader.get_data(imp.__file__) # File should be closed
|
||||
loader.get_data(imp.__file__) # Will need to create a newly opened file
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue