Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_importhooks.ImportHooksTestCase Class Reference
Inheritance diagram for test.test_importhooks.ImportHooksTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_importhooks.ImportHooksTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def doTestImports
def testMetaPath
def testPathHook
def testBlocker
def testImpWrapper
def setUp
def tearDown

Public Attributes

 path
 meta_path
 path_hooks
 modules_before

Detailed Description

Definition at line 156 of file test_importhooks.py.


Member Function Documentation

def test.test_importhooks.ImportHooksTestCase.doTestImports (   self,
  importer = None 
)

Definition at line 158 of file test_importhooks.py.

00158 
00159     def doTestImports(self, importer=None):
00160         import hooktestmodule
00161         import hooktestpackage
00162         import hooktestpackage.sub
00163         import hooktestpackage.sub.subber
00164         self.assertEqual(hooktestmodule.get_name(),
00165                          "hooktestmodule")
00166         self.assertEqual(hooktestpackage.get_name(),
00167                          "hooktestpackage")
00168         self.assertEqual(hooktestpackage.sub.get_name(),
00169                          "hooktestpackage.sub")
00170         self.assertEqual(hooktestpackage.sub.subber.get_name(),
00171                          "hooktestpackage.sub.subber")
00172         if importer:
00173             self.assertEqual(hooktestmodule.__loader__, importer)
00174             self.assertEqual(hooktestpackage.__loader__, importer)
00175             self.assertEqual(hooktestpackage.sub.__loader__, importer)
00176             self.assertEqual(hooktestpackage.sub.subber.__loader__, importer)
00177 
00178         TestImporter.modules['reloadmodule'] = (False, test_co)
00179         import reloadmodule
00180         self.assertFalse(hasattr(reloadmodule,'reloaded'))
00181 
00182         import hooktestpackage.newrel
00183         self.assertEqual(hooktestpackage.newrel.get_name(),
00184                          "hooktestpackage.newrel")
00185         self.assertEqual(hooktestpackage.newrel.sub,
00186                          hooktestpackage.sub)
00187 
00188         import hooktestpackage.sub.subber.subest as subest
00189         self.assertEqual(subest.get_name(),
00190                          "hooktestpackage.sub.subber.subest")
00191         self.assertEqual(subest.sub,
00192                          hooktestpackage.sub)
00193 
00194         import hooktestpackage.futrel
00195         self.assertEqual(hooktestpackage.futrel.get_name(),
00196                          "hooktestpackage.futrel")
00197         self.assertEqual(hooktestpackage.futrel.sub,
00198                          hooktestpackage.sub)
00199 
00200         import sub
00201         self.assertEqual(sub.get_name(), "sub")
00202 
00203         import hooktestpackage.oldabs
00204         self.assertEqual(hooktestpackage.oldabs.get_name(),
00205                          "hooktestpackage.oldabs")
00206         self.assertEqual(hooktestpackage.oldabs.sub, sub)
00207 
00208         import hooktestpackage.newabs
00209         self.assertEqual(hooktestpackage.newabs.get_name(),
00210                          "hooktestpackage.newabs")
00211         self.assertEqual(hooktestpackage.newabs.sub, sub)

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in test.test_zipimport.UncompressedZipImportTestCase.

Definition at line 141 of file test_importhooks.py.

00141 
00142     def setUp(self):
00143         self.path = sys.path[:]
00144         self.meta_path = sys.meta_path[:]
00145         self.path_hooks = sys.path_hooks[:]
00146         sys.path_importer_cache.clear()
00147         self.modules_before = support.modules_setup()

Here is the caller graph for this function:

Definition at line 148 of file test_importhooks.py.

00148 
00149     def tearDown(self):
00150         sys.path[:] = self.path
00151         sys.meta_path[:] = self.meta_path
00152         sys.path_hooks[:] = self.path_hooks
00153         sys.path_importer_cache.clear()
00154         support.modules_cleanup(*self.modules_before)
00155 

Here is the caller graph for this function:

Definition at line 222 of file test_importhooks.py.

00222 
00223     def testBlocker(self):
00224         mname = "exceptions"  # an arbitrary harmless builtin module
00225         support.unload(mname)
00226         sys.meta_path.append(ImportBlocker(mname))
00227         self.assertRaises(ImportError, __import__, mname)

Here is the call graph for this function:

Definition at line 228 of file test_importhooks.py.

00228 
00229     def testImpWrapper(self):
00230         i = ImpWrapper()
00231         sys.meta_path.append(i)
00232         sys.path_hooks.append(ImpWrapper)
00233         mnames = ("colorsys", "urllib.parse", "distutils.core")
00234         for mname in mnames:
00235             parent = mname.split(".")[0]
00236             for n in list(sys.modules):
00237                 if n.startswith(parent):
00238                     del sys.modules[n]
00239         for mname in mnames:
00240             m = __import__(mname, globals(), locals(), ["__dummy__"])
00241             m.__loader__  # to make sure we actually handled the import
00242 

Here is the call graph for this function:

Definition at line 212 of file test_importhooks.py.

00212 
00213     def testMetaPath(self):
00214         i = MetaImporter()
00215         sys.meta_path.append(i)
00216         self.doTestImports(i)

Here is the call graph for this function:

Definition at line 217 of file test_importhooks.py.

00217 
00218     def testPathHook(self):
00219         sys.path_hooks.append(PathImporter)
00220         sys.path.append(test_path)
00221         self.doTestImports()

Here is the call graph for this function:


Member Data Documentation

Definition at line 143 of file test_importhooks.py.

Definition at line 146 of file test_importhooks.py.

Definition at line 142 of file test_importhooks.py.

Definition at line 144 of file test_importhooks.py.


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