diff options
author | Brett Cannon <brett@python.org> | 2014-02-26 23:26:49 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-02-26 23:26:49 (GMT) |
commit | d3acef9bf4658bfaee0b98b79d4c42406faf7b83 (patch) | |
tree | ec14535bc2da15f88645ee353d1600d8f26b9e31 /Lib/test/test_importlib | |
parent | 9fff849dbfe31642fac2e58d42e0ef73891f5c04 (diff) | |
download | cpython-d3acef9bf4658bfaee0b98b79d4c42406faf7b83.zip cpython-d3acef9bf4658bfaee0b98b79d4c42406faf7b83.tar.gz cpython-d3acef9bf4658bfaee0b98b79d4c42406faf7b83.tar.bz2 |
Issue #20763: Fix importlib.machinery.PathFinder to support
PathEntryFinder instances which only define find_module().
Reported by Yukihiro Nakadaira.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/import_/test_path.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py index 713e754..1274f8c 100644 --- a/Lib/test/test_importlib/import_/test_path.py +++ b/Lib/test/test_importlib/import_/test_path.py @@ -116,5 +116,29 @@ Frozen_FinderTests, Source_FinderTests = util.test_both( FinderTests, importlib=importlib, machinery=machinery) +class PathEntryFinderTests: + + def test_finder_with_failing_find_module(self): + # PathEntryFinder with find_module() defined should work. + # Issue #20763. + class Finder: + path_location = 'test_finder_with_find_module' + def __init__(self, path): + if path != self.path_location: + raise ImportError + + @staticmethod + def find_module(fullname): + return None + + + with util.import_state(path=[Finder.path_location]+sys.path[:], + path_hooks=[Finder]): + self.machinery.PathFinder.find_spec('importlib') + +Frozen_PEFTests, Source_PEFTests = util.test_both( + PathEntryFinderTests, machinery=machinery) + + if __name__ == '__main__': unittest.main() |