]> granicus.if.org Git - python/commitdiff
Add tests for using sys.path_hooks by importlib.machinery.PathFinder.
authorBrett Cannon <bcannon@gmail.com>
Thu, 5 Feb 2009 23:36:02 +0000 (23:36 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 5 Feb 2009 23:36:02 +0000 (23:36 +0000)
Lib/importlib/_bootstrap.py
Lib/importlib/test/import_/test_path.py

index 849dabb3399deb7ca96b02b093465e7440b4e9a9..8eff65c9ee5f7bcdbfe6df7aaa9031309169721d 100644 (file)
@@ -601,7 +601,7 @@ class PathFinder:
     @classmethod
     def _implicit_hooks(cls):
         """Return a list of the implicit path hooks."""
-        return [self._default_hook, imp.NullImporter]
+        return [cls._default_hook, imp.NullImporter]
 
     @classmethod
     def _path_hooks(cls, path):
index 70dae2f70948163117ffa9d1e6d06c4cd4306cb3..6bace12036c42464474130d3152c266a545661b1 100644 (file)
@@ -208,8 +208,16 @@ class FinderTests(unittest.TestCase):
 
     def test_path_hooks(self):
         # Test that sys.path_hooks is used.
-        # TODO(brett.cannon) implement
-        pass
+        # Test that sys.path_importer_cache is set.
+        module = '<test module>'
+        path = '<test path>'
+        importer = util.mock_modules(module)
+        hook = import_util.mock_path_hook(path, importer=importer)
+        with util.import_state(path_hooks=[hook]):
+            loader = machinery.PathFinder.find_module(module, [path])
+            self.assert_(loader is importer)
+            self.assert_(path in sys.path_importer_cache)
+            self.assert_(sys.path_importer_cache[path] is importer)
 
     def test_implicit_hooks(self):
         # Test that the implicit path hooks are used.