class ImportHooksLookupTests(unittest.TestCase, LookupsTestCase): """ Tests for lookup methods in the presence of L{ihooks}-style import hooks. Runs all of the tests from L{LookupsTestCase} after installing a custom import hook. """ skip = ("ihooks support is broken, and has probably been broken since " "Python 2.6. On the other hand, no one should use ihooks.") def setUp(self): """ Perturb the normal import behavior subtly by installing an import hook. No custom behavior is provided, but this adds some extra frames to the call stack, which L{namedAny} must be able to account for. """ self.importer = ModuleImporter() self.importer.install() def tearDown(self): """ Uninstall the custom import hook. """ self.importer.uninstall()
class ImportHooksLookupTests(LookupsTestCase): """ Tests for lookup methods in the presence of L{ihooks}-style import hooks. Runs all of the tests from L{LookupsTestCase} after installing a custom import hook. """ if ModuleImporter == None: skip = "ihooks not available" def setUp(self): """ Perturb the normal import behavior subtly by installing an import hook. No custom behavior is provided, but this adds some extra frames to the call stack, which L{namedAny} must be able to account for. """ self.importer = ModuleImporter() self.importer.install() def tearDown(self): """ Uninstall the custom import hook. """ self.importer.uninstall()
def install(self): if not sys.modules.has_key(''): sys.modules[''] = package = imp.new_module('') package.__path__ = None self.loader.init_package(package) for m in sys.modules.values(): if not m: continue if not hasattr(m, '__'): self.loader.set_parent(m) ModuleImporter.install(self)
"""New import scheme with package support.