Finish implementing tests for importlib.machinery.PathFinder by testing that

implicit hooks are handled properly.
This commit is contained in:
Brett Cannon 2009-02-06 00:07:49 +00:00
parent 1f9bcd38a9
commit 6411aa5dd4
2 changed files with 31 additions and 14 deletions

View File

@ -9,11 +9,15 @@ to do
* Create meta_path importer for sys.path. * Create meta_path importer for sys.path.
+ Create hook.
+ Write tests.
+ Rewrite Import to use the hook.
+ Document. + Document.
* Refactor __import__.
+ Create a greatest common denominator function for __import__/import_module
that takes in an absolute module name and performs the import.
+ Use GCD import for __import__.
+ Use GCD import for import_module.
* Implement PEP 302 protocol for loaders (should just be a matter of testing). * Implement PEP 302 protocol for loaders (should just be a matter of testing).
+ Built-in. + Built-in.
@ -21,7 +25,7 @@ to do
+ Extension. + Extension.
+ Source/bytecode. + Source/bytecode.
* Public API to expose (w/ docs!) * Public API left to expose (w/ docs!)
+ abc + abc
@ -33,6 +37,8 @@ to do
* load_module * load_module
- (?) Importer(Finder, Loader)
- ResourceLoader(Loader) - ResourceLoader(Loader)
* get_data * get_data
@ -58,8 +64,6 @@ to do
+ machinery + machinery
- (?) Chained path hook/finder - (?) Chained path hook/finder
- BuiltinImporter
- FrozenImporter
- (?) FileFinder - (?) FileFinder
- Extensions importers - Extensions importers
@ -75,10 +79,8 @@ to do
* OPTIMIZE! * OPTIMIZE!
+ Fast path common cases. + Fast path absolute name.
+ Fast path pulling from sys.modules.
- Absolute name from sys.path.
- Relative name from sys.path.
* Bootstrap importlib as implementation of builtins.__import__ * Bootstrap importlib as implementation of builtins.__import__

View File

@ -2,9 +2,10 @@ from importlib import machinery
from .. import util from .. import util
from . import util as import_util from . import util as import_util
from contextlib import nested from contextlib import nested
from imp import new_module import imp
import os import os
import sys import sys
from test import support
from types import MethodType from types import MethodType
import unittest import unittest
@ -143,7 +144,7 @@ class __path__Tests(BaseTests):
self.run_test(self.hooks_order_test, location, [location]) self.run_test(self.hooks_order_test, location, [location])
def test_path_argument(self): def test_path_argument(self):
module = new_module('pkg') module = imp.new_module('pkg')
module.__path__ = ['random __path__'] module.__path__ = ['random __path__']
name = 'pkg.whatever' name = 'pkg.whatever'
sys.modules['pkg'] = module sys.modules['pkg'] = module
@ -221,8 +222,22 @@ class FinderTests(unittest.TestCase):
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.
# TODO(brett.cannon) implement existing_path = os.path.dirname(support.TESTFN)
pass 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(): def test_main():