Issue #15502: Finish bringing importlib.abc in line with the current

state of the import system. Also make importlib.invalidate_caches()
work with sys.meta_path instead of sys.path_importer_cache to
completely separate the path-based import system from the overall
import system.

Patch by Eric Snow.
This commit is contained in:
Brett Cannon 2012-08-10 12:21:12 -04:00
parent 2d6266d5f1
commit f4dc9204cc
8 changed files with 1294 additions and 1207 deletions

View file

@ -36,11 +36,13 @@ class MetaPathFinder(InheritanceTests, unittest.TestCase):
subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter,
machinery.PathFinder, machinery.WindowsRegistryFinder]
class PathEntryFinder(InheritanceTests, unittest.TestCase):
superclasses = [abc.Finder]
subclasses = [machinery.FileFinder]
class Loader(InheritanceTests, unittest.TestCase):
subclasses = [abc.PyLoader]

View file

@ -148,11 +148,15 @@ class InvalidateCacheTests(unittest.TestCase):
self.called = True
key = 'gobledeegook'
ins = InvalidatingNullFinder()
sys.path_importer_cache[key] = ins
meta_ins = InvalidatingNullFinder()
path_ins = InvalidatingNullFinder()
sys.meta_path.insert(0, meta_ins)
self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key))
sys.path_importer_cache[key] = path_ins
self.addCleanup(lambda: sys.meta_path.remove(meta_ins))
importlib.invalidate_caches()
self.assertTrue(ins.called)
self.assertTrue(meta_ins.called)
self.assertTrue(path_ins.called)
def test_method_lacking(self):
# There should be no issues if the method is not defined.