本文整理汇总了Python中test.support.swap_item方法的典型用法代码示例。如果您正苦于以下问题:Python support.swap_item方法的具体用法?Python support.swap_item怎么用?Python support.swap_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.support
的用法示例。
在下文中一共展示了support.swap_item方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_swap_item
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_swap_item(self):
D = {"x":1}
with support.swap_item(D, "x", 5) as x:
self.assertEqual(D["x"], 5)
self.assertEqual(x, 1)
self.assertEqual(D["x"], 1)
with support.swap_item(D, "y", 5) as y:
self.assertEqual(D["y"], 5)
self.assertIsNone(y)
self.assertNotIn("y", D)
with support.swap_item(D, "y", 5):
del D["y"]
self.assertNotIn("y", D)
示例2: test_swap_item
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_swap_item(self):
D = {"item":1}
with support.swap_item(D, "item", 5):
self.assertEqual(D["item"], 5)
self.assertEqual(D["item"], 1)
示例3: test_globals_shadow_builtins
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_globals_shadow_builtins(self):
# Modify globals() to shadow an entry in builtins.
def foo():
return len([1, 2, 3])
self.configure_func(foo)
self.assertEqual(foo(), 3)
with swap_item(globals(), "len", lambda x: 7):
self.assertEqual(foo(), 7)
示例4: test_cannot_replace_builtins_dict_while_active
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_cannot_replace_builtins_dict_while_active(self):
def foo():
x = range(3)
yield len(x)
yield len(x)
self.configure_func(foo)
g = foo()
self.assertEqual(next(g), 3)
with swap_item(globals(), "__builtins__", {"len": lambda x: 7}):
self.assertEqual(next(g), 3)
示例5: test_cannot_replace_builtins_dict_between_calls
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_cannot_replace_builtins_dict_between_calls(self):
def foo():
return len([1, 2, 3])
self.configure_func(foo)
self.assertEqual(foo(), 3)
with swap_item(globals(), "__builtins__", {"len": lambda x: 7}):
self.assertEqual(foo(), 3)
示例6: copy
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def copy(self, obj, proto):
with support.swap_item(sys.modules, 'operator', self.module):
pickled = pickle.dumps(obj, proto)
with support.swap_item(sys.modules, 'operator', self.module2):
return pickle.loads(pickled)
示例7: test_swap_item
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_swap_item(self):
D = {"item":1}
with support.swap_item(D, "item", 5):
self.assertEqual(D["item"], 5)
self.assertEqual(D["item"], 1)
# XXX -follows a list of untested API
# make_legacy_pyc
# is_resource_enabled
# requires
# fcmp
# umaks
# findfile
# check_warnings
# EnvironmentVarGuard
# TransientResource
# transient_internet
# run_with_locale
# set_memlimit
# bigmemtest
# precisionbigmemtest
# bigaddrspacetest
# requires_resource
# run_doctest
# threading_cleanup
# reap_threads
# reap_children
# strip_python_stderr
# args_from_interpreter_flags
# can_symlink
# skip_unless_symlink
# SuppressCrashReport
示例8: customize_compiler
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def customize_compiler(self):
# make sure AR gets caught
class compiler:
compiler_type = 'unix'
def set_executables(self, **kw):
self.exes = kw
sysconfig_vars = {
'AR': 'sc_ar',
'CC': 'sc_cc',
'CXX': 'sc_cxx',
'ARFLAGS': '--sc-arflags',
'CFLAGS': '--sc-cflags',
'CCSHARED': '--sc-ccshared',
'LDSHARED': 'sc_ldshared',
'SHLIB_SUFFIX': 'sc_shutil_suffix',
# On macOS, disable _osx_support.customize_compiler()
'CUSTOMIZED_OSX_COMPILER': 'True',
}
comp = compiler()
with contextlib.ExitStack() as cm:
for key, value in sysconfig_vars.items():
cm.enter_context(swap_item(sysconfig._config_vars, key, value))
sysconfig.customize_compiler(comp)
return comp
示例9: test_issue31566
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import swap_item [as 别名]
def test_issue31566(self):
# warn() shouldn't cause an assertion failure in case of a bad
# __name__ global.
with original_warnings.catch_warnings(module=self.module):
self.module.filterwarnings('error', category=UserWarning)
with support.swap_item(globals(), '__name__', b'foo'), \
support.swap_item(globals(), '__file__', None):
self.assertRaises(UserWarning, self.module.warn, 'bar')