mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-42134: Raise ImportWarning when calling find_module() in the import system (GH-25044)
This commit is contained in:
parent
cf35e05f89
commit
a7ff6df60c
9 changed files with 1012 additions and 962 deletions
|
@ -123,12 +123,16 @@ class FinderTests:
|
|||
failing_finder.to_return = None
|
||||
path = 'testing path'
|
||||
with util.import_state(path_importer_cache={path: failing_finder}):
|
||||
self.assertIsNone(
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", ImportWarning)
|
||||
self.assertIsNone(
|
||||
self.machinery.PathFinder.find_spec('whatever', [path]))
|
||||
success_finder = TestFinder()
|
||||
success_finder.to_return = __loader__
|
||||
with util.import_state(path_importer_cache={path: success_finder}):
|
||||
spec = self.machinery.PathFinder.find_spec('whatever', [path])
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", ImportWarning)
|
||||
spec = self.machinery.PathFinder.find_spec('whatever', [path])
|
||||
self.assertEqual(spec.loader, __loader__)
|
||||
|
||||
def test_finder_with_find_loader(self):
|
||||
|
@ -248,7 +252,9 @@ class PathEntryFinderTests:
|
|||
|
||||
with util.import_state(path=[Finder.path_location]+sys.path[:],
|
||||
path_hooks=[Finder]):
|
||||
self.machinery.PathFinder.find_spec('importlib')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", ImportWarning)
|
||||
self.machinery.PathFinder.find_spec('importlib')
|
||||
|
||||
def test_finder_with_failing_find_module(self):
|
||||
# PathEntryFinder with find_module() defined should work.
|
||||
|
@ -266,7 +272,9 @@ class PathEntryFinderTests:
|
|||
|
||||
with util.import_state(path=[Finder.path_location]+sys.path[:],
|
||||
path_hooks=[Finder]):
|
||||
self.machinery.PathFinder.find_module('importlib')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", ImportWarning)
|
||||
self.machinery.PathFinder.find_module('importlib')
|
||||
|
||||
|
||||
(Frozen_PEFTests,
|
||||
|
|
|
@ -151,6 +151,7 @@ class FindLoaderTests:
|
|||
with test_util.import_state(meta_path=[self.FakeMetaFinder]):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
warnings.simplefilter('ignore', ImportWarning)
|
||||
self.assertEqual((name, None), self.init.find_loader(name))
|
||||
|
||||
def test_success_path(self):
|
||||
|
@ -161,6 +162,7 @@ class FindLoaderTests:
|
|||
with test_util.import_state(meta_path=[self.FakeMetaFinder]):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
warnings.simplefilter('ignore', ImportWarning)
|
||||
self.assertEqual((name, path),
|
||||
self.init.find_loader(name, path))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue