mirror of https://github.com/python/cpython.git
Add tests for using sys.path_hooks by importlib.machinery.PathFinder.
This commit is contained in:
parent
5874ef16ed
commit
1f9bcd38a9
|
@ -601,7 +601,7 @@ class PathFinder:
|
||||||
@classmethod
|
@classmethod
|
||||||
def _implicit_hooks(cls):
|
def _implicit_hooks(cls):
|
||||||
"""Return a list of the implicit path hooks."""
|
"""Return a list of the implicit path hooks."""
|
||||||
return [self._default_hook, imp.NullImporter]
|
return [cls._default_hook, imp.NullImporter]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _path_hooks(cls, path):
|
def _path_hooks(cls, path):
|
||||||
|
|
|
@ -208,8 +208,16 @@ def test_path_importer_cache_has_None(self):
|
||||||
|
|
||||||
def test_path_hooks(self):
|
def test_path_hooks(self):
|
||||||
# Test that sys.path_hooks is used.
|
# Test that sys.path_hooks is used.
|
||||||
# TODO(brett.cannon) implement
|
# Test that sys.path_importer_cache is set.
|
||||||
pass
|
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):
|
def test_implicit_hooks(self):
|
||||||
# Test that the implicit path hooks are used.
|
# Test that the implicit path hooks are used.
|
||||||
|
|
Loading…
Reference in New Issue