summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-06 00:07:49 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-06 00:07:49 (GMT)
commit6411aa5dd429acf4cd8f41c8e798d3df364d469a (patch)
tree9b7ef607bcfff5e650622fbe105f3f5ca57b2159 /Lib/importlib/test
parent1f9bcd38a9868b0d320681c603d5b4aa20ec54fe (diff)
downloadcpython-6411aa5dd429acf4cd8f41c8e798d3df364d469a.zip
cpython-6411aa5dd429acf4cd8f41c8e798d3df364d469a.tar.gz
cpython-6411aa5dd429acf4cd8f41c8e798d3df364d469a.tar.bz2
Finish implementing tests for importlib.machinery.PathFinder by testing that
implicit hooks are handled properly.
Diffstat (limited to 'Lib/importlib/test')
-rw-r--r--Lib/importlib/test/import_/test_path.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/Lib/importlib/test/import_/test_path.py b/Lib/importlib/test/import_/test_path.py
index 6bace12..b4ae779 100644
--- a/Lib/importlib/test/import_/test_path.py
+++ b/Lib/importlib/test/import_/test_path.py
@@ -2,9 +2,10 @@ from importlib import machinery
from .. import util
from . import util as import_util
from contextlib import nested
-from imp import new_module
+import imp
import os
import sys
+from test import support
from types import MethodType
import unittest
@@ -143,7 +144,7 @@ class __path__Tests(BaseTests):
self.run_test(self.hooks_order_test, location, [location])
def test_path_argument(self):
- module = new_module('pkg')
+ module = imp.new_module('pkg')
module.__path__ = ['random __path__']
name = 'pkg.whatever'
sys.modules['pkg'] = module
@@ -221,8 +222,22 @@ class FinderTests(unittest.TestCase):
def test_implicit_hooks(self):
# Test that the implicit path hooks are used.
- # TODO(brett.cannon) implement
- pass
+ existing_path = os.path.dirname(support.TESTFN)
+ bad_path = '<path>'
+ module = '<module>'
+ assert not os.path.exists(bad_path)
+ with util.import_state():
+ nothing = machinery.PathFinder.find_module(module,
+ path=[existing_path])
+ self.assert_(nothing is None)
+ self.assert_(existing_path in sys.path_importer_cache)
+ self.assert_(not isinstance(sys.path_importer_cache[existing_path],
+ imp.NullImporter))
+ nothing = machinery.PathFinder.find_module(module, path=[bad_path])
+ self.assert_(nothing is None)
+ self.assert_(bad_path in sys.path_importer_cache)
+ self.assert_(isinstance(sys.path_importer_cache[bad_path],
+ imp.NullImporter))
def test_main():