本文整理汇总了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)
示例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__'))
示例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__'))
示例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")
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)