summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2021-04-05 04:11:23 (GMT)
committerGitHub <noreply@github.com>2021-04-05 04:11:23 (GMT)
commitc8e5eb904e12010d2302364e1037c24a30f5e241 (patch)
treeea1ad39012846500bbb9560262c7f9cd464b62f8 /Lib/test/test_importlib
parentee952b5c7355cb64179ca9bb77b13e7738132d3d (diff)
downloadcpython-c8e5eb904e12010d2302364e1037c24a30f5e241.zip
cpython-c8e5eb904e12010d2302364e1037c24a30f5e241.tar.gz
cpython-c8e5eb904e12010d2302364e1037c24a30f5e241.tar.bz2
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)
* Fix test_shutil * Fix test_imp * Fix test_import * Fix test_importlib
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/fixtures.py2
-rw-r--r--Lib/test/test_importlib/source/test_file_loader.py10
-rw-r--r--Lib/test/test_importlib/source/test_finder.py2
-rw-r--r--Lib/test/test_importlib/test_api.py2
-rw-r--r--Lib/test/test_importlib/test_files.py2
-rw-r--r--Lib/test/test_importlib/test_main.py4
-rw-r--r--Lib/test/test_importlib/test_pkg_import.py2
-rw-r--r--Lib/test/test_importlib/util.py6
8 files changed, 15 insertions, 15 deletions
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py
index 429313e..b50afda 100644
--- a/Lib/test/test_importlib/fixtures.py
+++ b/Lib/test/test_importlib/fixtures.py
@@ -250,7 +250,7 @@ def build_files(file_defs, prefix=pathlib.Path()):
with full_name.open('wb') as f:
f.write(contents)
else:
- with full_name.open('w') as f:
+ with full_name.open('w', encoding='utf-8') as f:
f.write(DALS(contents))
diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py
index cbd1533..1065ac5 100644
--- a/Lib/test/test_importlib/source/test_file_loader.py
+++ b/Lib/test/test_importlib/source/test_file_loader.py
@@ -124,7 +124,7 @@ class SimpleTest(abc.LoaderTests):
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 @@ class SimpleTest(abc.LoaderTests):
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 @@ class SimpleTest(abc.LoaderTests):
# [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 @@ class SimpleTest(abc.LoaderTests):
# 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 @@ class SimpleTest(abc.LoaderTests):
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))
diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py
index e9207de..80e930c 100644
--- a/Lib/test/test_importlib/source/test_finder.py
+++ b/Lib/test/test_importlib/source/test_finder.py
@@ -127,7 +127,7 @@ class FinderTests(abc.FinderTests):
# The empty string from sys.path means to search in the cwd.
finder = self.machinery.FileFinder('', (self.machinery.SourceFileLoader,
self.machinery.SOURCE_SUFFIXES))
- with open('mod.py', 'w') as file:
+ with open('mod.py', 'w', encoding='utf-8') as file:
file.write("# test file for importlib")
try:
loader = self._find(finder, 'mod', loader_only=True)
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py
index 384ae9c..8344fb0 100644
--- a/Lib/test/test_importlib/test_api.py
+++ b/Lib/test/test_importlib/test_api.py
@@ -312,7 +312,7 @@ class ReloadTests:
'__file__': None,
}
os.mkdir(name)
- with open(bad_path, 'w') as init_file:
+ with open(bad_path, 'w', encoding='utf-8') as init_file:
init_file.write('eggs = None')
module = self.init.import_module(name)
ns = vars(module).copy()
diff --git a/Lib/test/test_importlib/test_files.py b/Lib/test/test_importlib/test_files.py
index 1e7a1f3..481829b 100644
--- a/Lib/test/test_importlib/test_files.py
+++ b/Lib/test/test_importlib/test_files.py
@@ -15,7 +15,7 @@ class FilesTests:
def test_read_text(self):
files = resources.files(self.data)
- actual = files.joinpath('utf-8.file').read_text()
+ actual = files.joinpath('utf-8.file').read_text(encoding='utf-8')
assert actual == 'Hello, UTF-8 world!\n'
@unittest.skipUnless(
diff --git a/Lib/test/test_importlib/test_main.py b/Lib/test/test_importlib/test_main.py
index db97e53..08069c9 100644
--- a/Lib/test/test_importlib/test_main.py
+++ b/Lib/test/test_importlib/test_main.py
@@ -83,7 +83,7 @@ class NameNormalizationTests(fixtures.OnSysPath, fixtures.SiteDir, unittest.Test
metadata_dir = site_dir / 'my_pkg.dist-info'
metadata_dir.mkdir()
metadata = metadata_dir / 'METADATA'
- with metadata.open('w') as strm:
+ with metadata.open('w', encoding='utf-8') as strm:
strm.write('Version: 1.0\n')
return 'my-pkg'
@@ -102,7 +102,7 @@ class NameNormalizationTests(fixtures.OnSysPath, fixtures.SiteDir, unittest.Test
metadata_dir = site_dir / 'CherryPy.dist-info'
metadata_dir.mkdir()
metadata = metadata_dir / 'METADATA'
- with metadata.open('w') as strm:
+ with metadata.open('w', encoding='utf-8') as strm:
strm.write('Version: 1.0\n')
return 'CherryPy'
diff --git a/Lib/test/test_importlib/test_pkg_import.py b/Lib/test/test_importlib/test_pkg_import.py
index 36e78af..66f5f8b 100644
--- a/Lib/test/test_importlib/test_pkg_import.py
+++ b/Lib/test/test_importlib/test_pkg_import.py
@@ -42,7 +42,7 @@ class TestImport(unittest.TestCase):
compiled_path = cache_from_source(self.module_path)
if os.path.exists(compiled_path):
os.remove(compiled_path)
- with open(self.module_path, 'w') as f:
+ with open(self.module_path, 'w', encoding='utf-8') as f:
f.write(contents)
def test_package_import__semantics(self):
diff --git a/Lib/test/test_importlib/util.py b/Lib/test/test_importlib/util.py
index 5c0375e..ca0d8c9 100644
--- a/Lib/test/test_importlib/util.py
+++ b/Lib/test/test_importlib/util.py
@@ -116,7 +116,7 @@ def case_insensitive_tests(test):
def submodule(parent, name, pkg_dir, content=''):
path = os.path.join(pkg_dir, name + '.py')
- with open(path, 'w') as subfile:
+ with open(path, 'w', encoding='utf-8') as subfile:
subfile.write(content)
return '{}.{}'.format(parent, name), path
@@ -176,7 +176,7 @@ def temp_module(name, content='', *, pkg=False):
content = ''
if content is not None:
# not a namespace package
- with open(modpath, 'w') as modfile:
+ with open(modpath, 'w', encoding='utf-8') as modfile:
modfile.write(content)
yield location
@@ -384,7 +384,7 @@ def create_modules(*names):
os.mkdir(file_path)
created_paths.append(file_path)
file_path = os.path.join(file_path, name_parts[-1] + '.py')
- with open(file_path, 'w') as file:
+ with open(file_path, 'w', encoding='utf-8') as file:
file.write(source.format(name))
created_paths.append(file_path)
mapping[name] = file_path