mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +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
|
|
@ -124,7 +124,7 @@ def test_module_reuse(self):
|
|||
module = loader.load_module('_temp')
|
||||
module_id = id(module)
|
||||
module_dict_id = id(module.__dict__)
|
||||
with open(mapping['_temp'], 'w') as file:
|
||||
with open(mapping['_temp'], 'w', encoding='utf-8') as file:
|
||||
file.write("testing_var = 42\n")
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
|
|
@ -145,7 +145,7 @@ def test_state_after_failure(self):
|
|||
orig_module = types.ModuleType(name)
|
||||
for attr in attributes:
|
||||
setattr(orig_module, attr, value)
|
||||
with open(mapping[name], 'w') as file:
|
||||
with open(mapping[name], 'w', encoding='utf-8') as file:
|
||||
file.write('+++ bad syntax +++')
|
||||
loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
|
||||
with self.assertRaises(SyntaxError):
|
||||
|
|
@ -162,7 +162,7 @@ def test_state_after_failure(self):
|
|||
# [syntax error]
|
||||
def test_bad_syntax(self):
|
||||
with util.create_modules('_temp') as mapping:
|
||||
with open(mapping['_temp'], 'w') as file:
|
||||
with open(mapping['_temp'], 'w', encoding='utf-8') as file:
|
||||
file.write('=')
|
||||
loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
|
||||
with self.assertRaises(SyntaxError):
|
||||
|
|
@ -175,7 +175,7 @@ def test_file_from_empty_string_dir(self):
|
|||
# Loading a module found from an empty string entry on sys.path should
|
||||
# not only work, but keep all attributes relative.
|
||||
file_path = '_temp.py'
|
||||
with open(file_path, 'w') as file:
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
file.write("# test file for importlib")
|
||||
try:
|
||||
with util.uncache('_temp'):
|
||||
|
|
@ -199,7 +199,7 @@ def test_timestamp_overflow(self):
|
|||
with util.create_modules('_temp') as mapping:
|
||||
source = mapping['_temp']
|
||||
compiled = self.util.cache_from_source(source)
|
||||
with open(source, 'w') as f:
|
||||
with open(source, 'w', encoding='utf-8') as f:
|
||||
f.write("x = 5")
|
||||
try:
|
||||
os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue