Python test.support.swap_item() Examples
The following are 18
code examples of test.support.swap_item().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.support
, or try the search function
.
Example #1
Source File: test_dynamic.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #2
Source File: test_support.py From android_universal with MIT License | 5 votes |
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)
Example #3
Source File: __init__.py From android_universal with MIT License | 5 votes |
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')
Example #4
Source File: test_operator.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: test_dynamic.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: test_dynamic.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #7
Source File: test_dynamic.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_support.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: test_sysconfig.py From setuptools with MIT License | 5 votes |
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
Example #10
Source File: test_test_support.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: test_dynamic.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: test_dynamic.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #13
Source File: test_support.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #14
Source File: test_operator.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #15
Source File: test_dynamic.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #16
Source File: test_dynamic.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #17
Source File: test_dynamic.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #18
Source File: test_support.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)