当前位置: 首页>>代码示例>>Python>>正文


Python support.CleanImport方法代码示例

本文整理汇总了Python中test.support.CleanImport方法的典型用法代码示例。如果您正苦于以下问题:Python support.CleanImport方法的具体用法?Python support.CleanImport怎么用?Python support.CleanImport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test.support的用法示例。


在下文中一共展示了support.CleanImport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_load_from_source

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
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 support.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
        orig_path = os.path
        orig_getenv = os.getenv
        with support.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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_imp.py

示例2: test_reload_init_module_attrs

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_reload_init_module_attrs(self):
        self.spec.loader = NewLoader()
        with CleanImport(self.spec.name):
            loaded = self.bootstrap._load(self.spec)
            loaded.__name__ = 'ham'
            del loaded.__loader__
            del loaded.__package__
            del loaded.__spec__
            self.bootstrap._exec(self.spec, loaded)

        self.assertEqual(loaded.__name__, self.spec.name)
        self.assertIs(loaded.__loader__, self.spec.loader)
        self.assertEqual(loaded.__package__, self.spec.parent)
        self.assertIs(loaded.__spec__, self.spec)
        self.assertFalse(hasattr(loaded, '__path__'))
        self.assertFalse(hasattr(loaded, '__file__'))
        self.assertFalse(hasattr(loaded, '__cached__')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_spec.py

示例3: test_reload_init_module_attrs

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_reload_init_module_attrs(self):
        self.spec.loader = NewLoader()
        with CleanImport(self.spec.name):
            loaded = self.bootstrap._SpecMethods(self.spec).load()
            loaded.__name__ = 'ham'
            del loaded.__loader__
            del loaded.__package__
            del loaded.__spec__
            self.bootstrap._SpecMethods(self.spec).exec(loaded)

        self.assertEqual(loaded.__name__, self.spec.name)
        self.assertIs(loaded.__loader__, self.spec.loader)
        self.assertEqual(loaded.__package__, self.spec.parent)
        self.assertIs(loaded.__spec__, self.spec)
        self.assertFalse(hasattr(loaded, '__path__'))
        self.assertFalse(hasattr(loaded, '__file__'))
        self.assertFalse(hasattr(loaded, '__cached__')) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:test_spec.py

示例4: test_CleanImport

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_CleanImport(self):
        import importlib
        with support.CleanImport("asyncore"):
            importlib.import_module("asyncore") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_test_support.py

示例5: test_source

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_source(self):
        # XXX (ncoghlan): It would be nice to use test.support.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 support.EnvironmentVarGuard():
            import os
            imp.reload(os) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_imp.py

示例6: test_extension

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_extension(self):
        with support.CleanImport('time'):
            import time
            imp.reload(time) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_imp.py

示例7: test_builtin

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_builtin(self):
        with support.CleanImport('marshal'):
            import marshal
            imp.reload(marshal) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_imp.py

示例8: test_future2

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_future2(self):
        with support.CleanImport('future_test2'):
            from test import future_test2
            self.assertEqual(future_test2.result, 6) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_future.py

示例9: test_future3

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_future3(self):
        with support.CleanImport('test_future3'):
            from test import test_future3 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_future.py

示例10: test_multiple_features

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_multiple_features(self):
        with support.CleanImport("test.test_future5"):
            from test import test_future5 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_future.py

示例11: test_get_loader_handles_missing_spec_attribute

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_get_loader_handles_missing_spec_attribute(self):
        name = 'spam'
        mod = type(sys)(name)
        del mod.__spec__
        with CleanImport(name):
            sys.modules[name] = mod
            loader = pkgutil.get_loader(name)
        self.assertIsNone(loader) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_pkgutil.py

示例12: test_get_loader_handles_spec_attribute_none

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_get_loader_handles_spec_attribute_none(self):
        name = 'spam'
        mod = type(sys)(name)
        mod.__spec__ = None
        with CleanImport(name):
            sys.modules[name] = mod
            loader = pkgutil.get_loader(name)
        self.assertIsNone(loader) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_pkgutil.py

示例13: test_reload_missing_loader

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_reload_missing_loader(self):
        with support.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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_api.py

示例14: test_reload_loader_replaced

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_reload_loader_replaced(self):
        with support.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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_api.py

示例15: test_load

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import CleanImport [as 别名]
def test_load(self):
        self.spec.loader = NewLoader()
        with CleanImport(self.spec.name):
            loaded = self.bootstrap._load(self.spec)
            installed = sys.modules[self.spec.name]

        self.assertEqual(loaded.eggs, 1)
        self.assertIs(loaded, installed) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_spec.py


注:本文中的test.support.CleanImport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。