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


Python support.swap_item方法代码示例

本文整理汇总了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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_test_support.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_support.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_dynamic.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_dynamic.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_dynamic.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_operator.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:34,代码来源:test_support.py

示例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 
开发者ID:pypa,项目名称:setuptools,代码行数:31,代码来源:test_sysconfig.py

示例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') 
开发者ID:bkerler,项目名称:android_universal,代码行数:10,代码来源:__init__.py


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