Back to index

python3.2  3.2.2
Public Member Functions
importlib.test.import_.test_path.DefaultPathFinderTests Class Reference

List of all members.

Public Member Functions

def test_implicit_hooks
def test_path_importer_cache_has_None

Detailed Description

Test importlib._bootstrap._DefaultPathFinder.

Definition at line 78 of file test_path.py.


Member Function Documentation

Definition at line 82 of file test_path.py.

00082 
00083     def test_implicit_hooks(self):
00084         # Test that the implicit path hooks are used.
00085         bad_path = '<path>'
00086         module = '<module>'
00087         assert not os.path.exists(bad_path)
00088         existing_path = tempfile.mkdtemp()
00089         try:
00090             with util.import_state():
00091                 nothing = _bootstrap._DefaultPathFinder.find_module(module,
00092                                                         path=[existing_path])
00093                 self.assertTrue(nothing is None)
00094                 self.assertTrue(existing_path in sys.path_importer_cache)
00095                 result = isinstance(sys.path_importer_cache[existing_path],
00096                                     imp.NullImporter)
00097                 self.assertFalse(result)
00098                 nothing = _bootstrap._DefaultPathFinder.find_module(module,
00099                                                             path=[bad_path])
00100                 self.assertTrue(nothing is None)
00101                 self.assertTrue(bad_path in sys.path_importer_cache)
00102                 self.assertTrue(isinstance(sys.path_importer_cache[bad_path],
00103                                            imp.NullImporter))
00104         finally:
00105             os.rmdir(existing_path)
00106 

Here is the call graph for this function:

Definition at line 107 of file test_path.py.

00107 
00108     def test_path_importer_cache_has_None(self):
00109         # Test that the default hook is used when sys.path_importer_cache
00110         # contains None for a path.
00111         module = '<test module>'
00112         importer = util.mock_modules(module)
00113         path = '<test path>'
00114         # XXX Not blackbox.
00115         original_hook = _bootstrap._DEFAULT_PATH_HOOK
00116         mock_hook = import_util.mock_path_hook(path, importer=importer)
00117         _bootstrap._DEFAULT_PATH_HOOK = mock_hook
00118         try:
00119             with util.import_state(path_importer_cache={path: None}):
00120                 loader = _bootstrap._DefaultPathFinder.find_module(module,
00121                                                                     path=[path])
00122                 self.assertTrue(loader is importer)
00123         finally:
00124             _bootstrap._DEFAULT_PATH_HOOK = original_hook
00125 

Here is the call graph for this function:


The documentation for this class was generated from the following file: