summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-05 23:36:02 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-05 23:36:02 (GMT)
commit1f9bcd38a9868b0d320681c603d5b4aa20ec54fe (patch)
treed2d186f128500e255a54ccda482881230ebc842c /Lib/importlib
parent5874ef16edfa34cf6ff184e56ada8b78687b689f (diff)
downloadcpython-1f9bcd38a9868b0d320681c603d5b4aa20ec54fe.zip
cpython-1f9bcd38a9868b0d320681c603d5b4aa20ec54fe.tar.gz
cpython-1f9bcd38a9868b0d320681c603d5b4aa20ec54fe.tar.bz2
Add tests for using sys.path_hooks by importlib.machinery.PathFinder.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py2
-rw-r--r--Lib/importlib/test/import_/test_path.py12
2 files changed, 11 insertions, 3 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 849dabb..8eff65c 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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):
diff --git a/Lib/importlib/test/import_/test_path.py b/Lib/importlib/test/import_/test_path.py
index 70dae2f..6bace12 100644
--- a/Lib/importlib/test/import_/test_path.py
+++ b/Lib/importlib/test/import_/test_path.py
@@ -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.