Exemplo n.º 1
0
    def test_reload_loader_replaced(self):
        with import_helper.CleanImport('types'):
            import types
            types.__loader__ = None
            self.init.invalidate_caches()
            reloaded = self.init.reload(types)

            self.assertIsNot(reloaded.__loader__, None)
            self.assertIs(reloaded, types)
            self.assertIs(sys.modules['types'], types)
Exemplo n.º 2
0
    def test_reload_missing_loader(self):
        with import_helper.CleanImport('types'):
            import types
            loader = types.__loader__
            del types.__loader__
            reloaded = self.init.reload(types)

            self.assertIs(reloaded, types)
            self.assertIs(sys.modules['types'], types)
            self.assertEqual(reloaded.__loader__.path, loader.path)
Exemplo n.º 3
0
 def test_frozen_submodule_in_unfrozen_package(self):
     with import_helper.CleanImport('__phello__', '__phello__.spam'):
         with import_helper.frozen_modules(enabled=False):
             import __phello__
         with import_helper.frozen_modules(enabled=True):
             import __phello__.spam as spam
     self.assertIs(spam, __phello__.spam)
     self.assertIsNot(__phello__.__spec__.loader,
                      importlib.machinery.FrozenImporter)
     self.assertIs(spam.__spec__.loader, importlib.machinery.FrozenImporter)
Exemplo n.º 4
0
 def test_target_ignored(self):
     imported = ('__hello__', '__phello__')
     with import_helper.CleanImport(*imported, usefrozen=True):
         import __hello__ as match
         import __phello__ as nonmatch
     name = '__hello__'
     actual = self.find(name)
     for target in (None, match, nonmatch, object(), 'not-a-module-object'):
         with self.subTest(target):
             spec = self.find(name, target=target)
             self.assertEqual(spec, actual)
Exemplo n.º 5
0
 def test_load_from_source(self):
     # Verify that the imp module can correctly load and find .py files
     # XXX (ncoghlan): It would be nice to use import_helper.CleanImport
     # here, but that breaks because the os module registers some
     # handlers in copy_reg on import. Since CleanImport doesn't
     # revert that registration, the module is left in a broken
     # state after reversion. Reinitialising the module contents
     # and just reverting os.environ to its previous state is an OK
     # workaround
     with import_helper.CleanImport('os', 'os.path', OS_PATH_NAME):
         import os
         orig_path = os.path
         orig_getenv = os.getenv
         with os_helper.EnvironmentVarGuard():
             x = imp.find_module("os")
             self.addCleanup(x[0].close)
             new_os = imp.load_module("os", *x)
             self.assertIs(os, new_os)
             self.assertIs(orig_path, new_os.path)
             self.assertIsNot(orig_getenv, new_os.getenv)
Exemplo n.º 6
0
 def test_builtin(self):
     with import_helper.CleanImport('marshal'):
         import marshal
         imp.reload(marshal)
Exemplo n.º 7
0
 def test_extension(self):
     with import_helper.CleanImport('time'):
         import time
         imp.reload(time)
Exemplo n.º 8
0
 def test_CleanImport(self):
     import importlib
     with import_helper.CleanImport("asyncore"):
         importlib.import_module("asyncore")
Exemplo n.º 9
0
 def test_future3(self):
     with import_helper.CleanImport('test_future3'):
         from test import test_future3
Exemplo n.º 10
0
 def test_future2(self):
     with import_helper.CleanImport('future_test2'):
         from test import future_test2
         self.assertEqual(future_test2.result, 6)
Exemplo n.º 11
0
 def test_multiple_features(self):
     with import_helper.CleanImport("test.test_future5"):
         from test import test_future5
Exemplo n.º 12
0
 def test_CleanImport(self):
     import importlib
     with import_helper.CleanImport("pprint"):
         importlib.import_module("pprint")
Exemplo n.º 13
0
 def test_reload_modules(self):
     for mod in ('tokenize', 'time', 'marshal'):
         with self.subTest(module=mod):
             with import_helper.CleanImport(mod):
                 module = self.init.import_module(mod)
                 self.init.reload(module)