summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2021-04-06 15:56:57 (GMT)
committerGitHub <noreply@github.com>2021-04-06 15:56:57 (GMT)
commit57c6cb5100d19a0e0218c77d887c3c239c9ce435 (patch)
tree8e193c0bc12f476821639c8363d280ef9d604271 /Lib/test/test_importlib
parentefccff9ac84009ef48e8cb22548ce80940f76533 (diff)
downloadcpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.zip
cpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.tar.gz
cpython-57c6cb5100d19a0e0218c77d887c3c239c9ce435.tar.bz2
bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169)
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/builtin/test_finder.py16
-rw-r--r--Lib/test/test_importlib/extension/test_case_sensitivity.py12
-rw-r--r--Lib/test/test_importlib/extension/test_finder.py11
-rw-r--r--Lib/test/test_importlib/frozen/test_finder.py5
-rw-r--r--Lib/test/test_importlib/frozen/test_loader.py2
-rw-r--r--Lib/test/test_importlib/import_/test_path.py8
-rw-r--r--Lib/test/test_importlib/source/test_case_sensitivity.py5
-rw-r--r--Lib/test/test_importlib/test_abc.py4
-rw-r--r--Lib/test/test_importlib/test_api.py8
9 files changed, 44 insertions, 27 deletions
diff --git a/Lib/test/test_importlib/builtin/test_finder.py b/Lib/test/test_importlib/builtin/test_finder.py
index 084f3de..6f51aba 100644
--- a/Lib/test/test_importlib/builtin/test_finder.py
+++ b/Lib/test/test_importlib/builtin/test_finder.py
@@ -5,6 +5,7 @@ machinery = util.import_importlib('importlib.machinery')
import sys
import unittest
+import warnings
@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
@@ -58,7 +59,9 @@ class FinderTests(abc.FinderTests):
def test_module(self):
# Common case.
with util.uncache(util.BUILTINS.good_name):
- found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name)
self.assertTrue(found)
self.assertTrue(hasattr(found, 'load_module'))
@@ -70,14 +73,19 @@ class FinderTests(abc.FinderTests):
def test_failure(self):
assert 'importlib' not in sys.builtin_module_names
- loader = self.machinery.BuiltinImporter.find_module('importlib')
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ loader = self.machinery.BuiltinImporter.find_module('importlib')
self.assertIsNone(loader)
def test_ignore_path(self):
# The value for 'path' should always trigger a failed import.
with util.uncache(util.BUILTINS.good_name):
- loader = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name,
- ['pkg'])
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ loader = self.machinery.BuiltinImporter.find_module(
+ util.BUILTINS.good_name,
+ ['pkg'])
self.assertIsNone(loader)
diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py
index 4d76fa0..20bf035 100644
--- a/Lib/test/test_importlib/extension/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py
@@ -12,30 +12,30 @@ machinery = util.import_importlib('importlib.machinery')
@util.case_insensitive_tests
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
- def find_module(self):
+ def find_spec(self):
good_name = util.EXTENSIONS.name
bad_name = good_name.upper()
assert good_name != bad_name
finder = self.machinery.FileFinder(util.EXTENSIONS.path,
(self.machinery.ExtensionFileLoader,
self.machinery.EXTENSION_SUFFIXES))
- return finder.find_module(bad_name)
+ return finder.find_spec(bad_name)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_sensitive(self):
with os_helper.EnvironmentVarGuard() as env:
env.unset('PYTHONCASEOK')
self.caseok_env_changed(should_exist=False)
- loader = self.find_module()
- self.assertIsNone(loader)
+ spec = self.find_spec()
+ self.assertIsNone(spec)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_insensitivity(self):
with os_helper.EnvironmentVarGuard() as env:
env.set('PYTHONCASEOK', '1')
self.caseok_env_changed(should_exist=True)
- loader = self.find_module()
- self.assertTrue(hasattr(loader, 'load_module'))
+ spec = self.find_spec()
+ self.assertTrue(spec)
(Frozen_ExtensionCaseSensitivity,
diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py
index c9b4a37..e8065d7 100644
--- a/Lib/test/test_importlib/extension/test_finder.py
+++ b/Lib/test/test_importlib/extension/test_finder.py
@@ -11,16 +11,15 @@ class FinderTests(abc.FinderTests):
"""Test the finder for extension modules."""
- def find_module(self, fullname):
+ def find_spec(self, fullname):
importer = self.machinery.FileFinder(util.EXTENSIONS.path,
(self.machinery.ExtensionFileLoader,
self.machinery.EXTENSION_SUFFIXES))
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', DeprecationWarning)
- return importer.find_module(fullname)
+
+ return importer.find_spec(fullname)
def test_module(self):
- self.assertTrue(self.find_module(util.EXTENSIONS.name))
+ self.assertTrue(self.find_spec(util.EXTENSIONS.name))
# No extension module as an __init__ available for testing.
test_package = test_package_in_package = None
@@ -32,7 +31,7 @@ class FinderTests(abc.FinderTests):
test_package_over_module = None
def test_failure(self):
- self.assertIsNone(self.find_module('asdfjkl;'))
+ self.assertIsNone(self.find_spec('asdfjkl;'))
(Frozen_FinderTests,
diff --git a/Lib/test/test_importlib/frozen/test_finder.py b/Lib/test/test_importlib/frozen/test_finder.py
index 519aa02..eb7a4d2 100644
--- a/Lib/test/test_importlib/frozen/test_finder.py
+++ b/Lib/test/test_importlib/frozen/test_finder.py
@@ -4,6 +4,7 @@ from .. import util
machinery = util.import_importlib('importlib.machinery')
import unittest
+import warnings
class FindSpecTests(abc.FinderTests):
@@ -49,7 +50,9 @@ class FinderTests(abc.FinderTests):
def find(self, name, path=None):
finder = self.machinery.FrozenImporter
- return finder.find_module(name, path)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ return finder.find_module(name, path)
def test_module(self):
name = '__hello__'
diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py
index 632246a..f0cf179 100644
--- a/Lib/test/test_importlib/frozen/test_loader.py
+++ b/Lib/test/test_importlib/frozen/test_loader.py
@@ -78,7 +78,7 @@ class ExecModuleTests(abc.LoaderTests):
test_state_after_failure = None
def test_unloadable(self):
- assert self.machinery.FrozenImporter.find_module('_not_real') is None
+ assert self.machinery.FrozenImporter.find_spec('_not_real') is None
with self.assertRaises(ImportError) as cm:
self.exec_module('_not_real')
self.assertEqual(cm.exception.name, '_not_real')
diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py
index 2ba7030..57a2522 100644
--- a/Lib/test/test_importlib/import_/test_path.py
+++ b/Lib/test/test_importlib/import_/test_path.py
@@ -75,7 +75,8 @@ class FinderTests:
with util.import_state(path_importer_cache={}, path_hooks=[],
path=[path_entry]):
with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter('always')
+ warnings.simplefilter('always', ImportWarning)
+ warnings.simplefilter('ignore', DeprecationWarning)
self.assertIsNone(self.find('os'))
self.assertIsNone(sys.path_importer_cache[path_entry])
self.assertEqual(len(w), 1)
@@ -216,7 +217,9 @@ class FinderTests:
class FindModuleTests(FinderTests):
def find(self, *args, **kwargs):
- return self.machinery.PathFinder.find_module(*args, **kwargs)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ return self.machinery.PathFinder.find_module(*args, **kwargs)
def check_found(self, found, importer):
self.assertIs(found, importer)
@@ -278,6 +281,7 @@ class PathEntryFinderTests:
path_hooks=[Finder]):
with warnings.catch_warnings():
warnings.simplefilter("ignore", ImportWarning)
+ warnings.simplefilter("ignore", DeprecationWarning)
self.machinery.PathFinder.find_module('importlib')
diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py
index 77c06a7..19543f4 100644
--- a/Lib/test/test_importlib/source/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/source/test_case_sensitivity.py
@@ -9,6 +9,7 @@ machinery = util.import_importlib('importlib.machinery')
import os
from test.support import os_helper
import unittest
+import warnings
@util.case_insensitive_tests
@@ -64,7 +65,9 @@ class CaseSensitivityTest(util.CASEOKTestBase):
class CaseSensitivityTestPEP302(CaseSensitivityTest):
def find(self, finder):
- return finder.find_module(self.name)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ return finder.find_module(self.name)
(Frozen_CaseSensitivityTestPEP302,
diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py
index 98f5835..45cbf90 100644
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -55,7 +55,7 @@ class InheritanceTests:
class MetaPathFinder(InheritanceTests):
- superclass_names = ['Finder']
+ superclass_names = []
subclass_names = ['BuiltinImporter', 'FrozenImporter', 'PathFinder',
'WindowsRegistryFinder']
@@ -66,7 +66,7 @@ class MetaPathFinder(InheritanceTests):
class PathEntryFinder(InheritanceTests):
- superclass_names = ['Finder']
+ superclass_names = []
subclass_names = ['FileFinder']
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py
index 8344fb0..763b2ad 100644
--- a/Lib/test/test_importlib/test_api.py
+++ b/Lib/test/test_importlib/test_api.py
@@ -440,9 +440,9 @@ class StartupTests:
with self.subTest(name=name):
self.assertTrue(hasattr(module, '__loader__'),
'{!r} lacks a __loader__ attribute'.format(name))
- if self.machinery.BuiltinImporter.find_module(name):
+ if self.machinery.BuiltinImporter.find_spec(name):
self.assertIsNot(module.__loader__, None)
- elif self.machinery.FrozenImporter.find_module(name):
+ elif self.machinery.FrozenImporter.find_spec(name):
self.assertIsNot(module.__loader__, None)
def test_everyone_has___spec__(self):
@@ -450,9 +450,9 @@ class StartupTests:
if isinstance(module, types.ModuleType):
with self.subTest(name=name):
self.assertTrue(hasattr(module, '__spec__'))
- if self.machinery.BuiltinImporter.find_module(name):
+ if self.machinery.BuiltinImporter.find_spec(name):
self.assertIsNot(module.__spec__, None)
- elif self.machinery.FrozenImporter.find_module(name):
+ elif self.machinery.FrozenImporter.find_spec(name):
self.assertIsNot(module.__spec__, None)