Python operator.delitem() Examples
The following are 30
code examples of operator.delitem().
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
operator
, or try the search function
.
Example #1
Source File: test_process.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_encodableUnicodeEnvironment(self): """ Test C{os.environ} (inherited by every subprocess on Windows) that contains an ascii-encodable Unicode string. This is different from passing Unicode environment explicitly to spawnProcess (which is not supported on Python 2). """ os.environ[self.goodKey] = self.goodValue self.addCleanup(operator.delitem, os.environ, self.goodKey) p = GetEnvironmentDictionary.run(reactor, [], properEnv) def gotEnvironment(environ): self.assertEqual( environ[self.goodKey.encode('ascii')], self.goodValue.encode('ascii')) return p.getResult().addCallback(gotEnvironment)
Example #2
Source File: test_dbm_dumb.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_check_closed(self): f = dumbdbm.open(_fname, 'c') f.close() for meth in (partial(operator.delitem, f), partial(operator.setitem, f, 'b'), partial(operator.getitem, f), partial(operator.contains, f)): with self.assertRaises(dumbdbm.error) as cm: meth('test') self.assertEqual(str(cm.exception), "DBM object has already been closed") for meth in (operator.methodcaller('keys'), operator.methodcaller('iterkeys'), operator.methodcaller('items'), len): with self.assertRaises(dumbdbm.error) as cm: meth(f) self.assertEqual(str(cm.exception), "DBM object has already been closed")
Example #3
Source File: test_process.py From learn_python3_spider with MIT License | 6 votes |
def test_encodableUnicodeEnvironment(self): """ Test C{os.environ} (inherited by every subprocess on Windows) that contains an ascii-encodable Unicode string. This is different from passing Unicode environment explicitly to spawnProcess (which is not supported on Python 2). """ os.environ[self.goodKey] = self.goodValue self.addCleanup(operator.delitem, os.environ, self.goodKey) p = GetEnvironmentDictionary.run(reactor, [], properEnv) def gotEnvironment(environ): self.assertEqual( environ[self.goodKey.encode('ascii')], self.goodValue.encode('ascii')) return p.getResult().addCallback(gotEnvironment)
Example #4
Source File: test_dbm_dumb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_check_closed(self): f = dumbdbm.open(_fname, 'c') f.close() for meth in (partial(operator.delitem, f), partial(operator.setitem, f, 'b'), partial(operator.getitem, f), partial(operator.contains, f)): with self.assertRaises(dumbdbm.error) as cm: meth('test') self.assertEqual(str(cm.exception), "DBM object has already been closed") for meth in (operator.methodcaller('keys'), operator.methodcaller('iterkeys'), operator.methodcaller('items'), len): with self.assertRaises(dumbdbm.error) as cm: meth(f) self.assertEqual(str(cm.exception), "DBM object has already been closed")
Example #5
Source File: test_dbm_dumb.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_check_closed(self): f = dumbdbm.open(_fname, 'c') f.close() for meth in (partial(operator.delitem, f), partial(operator.setitem, f, 'b'), partial(operator.getitem, f), partial(operator.contains, f)): with self.assertRaises(dumbdbm.error) as cm: meth('test') self.assertEqual(str(cm.exception), "DBM object has already been closed") for meth in (operator.methodcaller('keys'), operator.methodcaller('iterkeys'), operator.methodcaller('items'), len): with self.assertRaises(dumbdbm.error) as cm: meth(f) self.assertEqual(str(cm.exception), "DBM object has already been closed")
Example #6
Source File: test_dbm_dumb.py From android_universal with MIT License | 6 votes |
def test_check_closed(self): f = dumbdbm.open(_fname, 'c') f.close() for meth in (partial(operator.delitem, f), partial(operator.setitem, f, 'b'), partial(operator.getitem, f), partial(operator.contains, f)): with self.assertRaises(dumbdbm.error) as cm: meth('test') self.assertEqual(str(cm.exception), "DBM object has already been closed") for meth in (operator.methodcaller('keys'), operator.methodcaller('iterkeys'), operator.methodcaller('items'), len): with self.assertRaises(dumbdbm.error) as cm: meth(f) self.assertEqual(str(cm.exception), "DBM object has already been closed")
Example #7
Source File: test_array.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_buffer(self): a = array.array(self.typecode, self.example) m = memoryview(a) expected = m.tobytes() self.assertEqual(a.tobytes(), expected) self.assertEqual(a.tobytes()[0], expected[0]) # Resizing is forbidden when there are buffer exports. # For issue 4509, we also check after each error that # the array was not modified. self.assertRaises(BufferError, a.append, a[0]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.extend, a[0:1]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.remove, a[0]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.pop, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.fromlist, a.tolist()) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.frombytes, a.tobytes()) self.assertEqual(m.tobytes(), expected) if self.typecode == 'u': self.assertRaises(BufferError, a.fromunicode, a.tounicode()) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.imul, a, 2) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.imul, a, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.delitem, a, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.delitem, a, slice(0, 1)) self.assertEqual(m.tobytes(), expected)
Example #8
Source File: test_parser.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_load_packaged_grammar(self): modname = __name__ + '.load_test' class MyLoader: def get_data(self, where): return pickle.dumps({'elephant': 19}) class MyModule: __file__ = 'parsertestmodule' __spec__ = importlib.util.spec_from_loader(modname, MyLoader()) sys.modules[modname] = MyModule() self.addCleanup(operator.delitem, sys.modules, modname) g = pgen2_driver.load_packaged_grammar(modname, 'Grammar.txt') self.assertEqual(g.elephant, 19)
Example #9
Source File: test_array.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_buffer(self): a = array.array(self.typecode, self.example) m = memoryview(a) expected = m.tobytes() self.assertEqual(a.tobytes(), expected) self.assertEqual(a.tobytes()[0], expected[0]) # Resizing is forbidden when there are buffer exports. # For issue 4509, we also check after each error that # the array was not modified. self.assertRaises(BufferError, a.append, a[0]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.extend, a[0:1]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.remove, a[0]) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.pop, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.fromlist, a.tolist()) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, a.frombytes, a.tobytes()) self.assertEqual(m.tobytes(), expected) if self.typecode == 'u': self.assertRaises(BufferError, a.fromunicode, a.tounicode()) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.imul, a, 2) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.imul, a, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.delitem, a, 0) self.assertEqual(m.tobytes(), expected) self.assertRaises(BufferError, operator.delitem, a, slice(0, 1)) self.assertEqual(m.tobytes(), expected)
Example #10
Source File: test_operator.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_delitem(self): a = [4, 3, 2, 1] self.assertRaises(TypeError, operator.delitem, a) self.assertRaises(TypeError, operator.delitem, a, None) self.assertTrue(operator.delitem(a, 1) is None) self.assertTrue(a == [4, 2, 1])
Example #11
Source File: test_pointers.py From datafari with Apache License 2.0 | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #12
Source File: expr.py From owasp-pysec with Apache License 2.0 | 5 votes |
def __delitem__(self, key): return Expression((self, key), operator.delitem)
Example #13
Source File: test_pointers.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #14
Source File: test_pointers.py From android_universal with MIT License | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #15
Source File: test_parser.py From android_universal with MIT License | 5 votes |
def test_load_packaged_grammar(self): modname = __name__ + '.load_test' class MyLoader: def get_data(self, where): return pickle.dumps({'elephant': 19}) class MyModule: __file__ = 'parsertestmodule' __spec__ = importlib.util.spec_from_loader(modname, MyLoader()) sys.modules[modname] = MyModule() self.addCleanup(operator.delitem, sys.modules, modname) g = pgen2_driver.load_packaged_grammar(modname, 'Grammar.txt') self.assertEqual(g.elephant, 19)
Example #16
Source File: test_config.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_immutable(self): config_file = os.path.join(self.make_dir(), "config") config = ConfigurationFile(config_file, mutable=False) self.assertRaises(ConfigurationImmutable, setitem, config, "alice", 1) self.assertRaises(ConfigurationImmutable, delitem, config, "alice")
Example #17
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_delitem(self): a = [4, 3, 2, 1] self.failUnlessRaises(TypeError, operator.delitem, a) self.failUnlessRaises(TypeError, operator.delitem, a, None) self.failUnless(operator.delitem(a, 1) is None) self.assert_(a == [4, 2, 1])
Example #18
Source File: test_postgresql.py From django-sqlserver with MIT License | 5 votes |
def override_db_setting(self, **kwargs): for setting, value in kwargs.items(): original_value = connection.settings_dict.get(setting) if setting in connection.settings_dict: self.addCleanup(operator.setitem, connection.settings_dict, setting, original_value) else: self.addCleanup(operator.delitem, connection.settings_dict, setting) connection.settings_dict[setting] = kwargs[setting] yield
Example #19
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_delitem(self): a = [4, 3, 2, 1] self.failUnlessRaises(TypeError, operator.delitem, a) self.failUnlessRaises(TypeError, operator.delitem, a, None) self.failUnless(operator.delitem(a, 1) is None) self.assert_(a == [4, 2, 1])
Example #20
Source File: test_parser.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def test_load_packaged_grammar(self): modname = __name__ + '.load_test' class MyLoader: def get_data(self, where): return pickle.dumps({'elephant': 19}) class MyModule: __file__ = 'parsertestmodule' __spec__ = importlib.util.spec_from_loader(modname, MyLoader()) sys.modules[modname] = MyModule() self.addCleanup(operator.delitem, sys.modules, modname) g = pgen2_driver.load_packaged_grammar(modname, 'Grammar.txt') self.assertEqual(g.elephant, 19)
Example #21
Source File: test_pointers.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #22
Source File: test_operator.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_delitem(self): a = [4, 3, 2, 1] self.failUnlessRaises(TypeError, operator.delitem, a) self.failUnlessRaises(TypeError, operator.delitem, a, None) self.failUnless(operator.delitem(a, 1) is None) self.assert_(a == [4, 2, 1])
Example #23
Source File: test_server_side_cursors.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def override_db_setting(self, **kwargs): for setting in kwargs: original_value = connection.settings_dict.get(setting) if setting in connection.settings_dict: self.addCleanup(operator.setitem, connection.settings_dict, setting, original_value) else: self.addCleanup(operator.delitem, connection.settings_dict, setting) connection.settings_dict[setting] = kwargs[setting] yield
Example #24
Source File: test_server_side_cursors.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def override_db_setting(self, **kwargs): for setting in kwargs: original_value = connection.settings_dict.get(setting) if setting in connection.settings_dict: self.addCleanup(operator.setitem, connection.settings_dict, setting, original_value) else: self.addCleanup(operator.delitem, connection.settings_dict, setting) connection.settings_dict[setting] = kwargs[setting] yield
Example #25
Source File: test_config.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_immutable(self): database = sqlite3.connect(":memory:") config = ConfigurationDatabase(database, mutable=False) self.assertRaises(ConfigurationImmutable, setitem, config, "alice", 1) self.assertRaises(ConfigurationImmutable, delitem, config, "alice")
Example #26
Source File: test_pointers.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #27
Source File: test_parser.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_load_packaged_grammar(self): modname = __name__ + '.load_test' class MyLoader: def get_data(self, where): return pickle.dumps({'elephant': 19}) class MyModule(types.ModuleType): __file__ = 'parsertestmodule' __loader__ = MyLoader() sys.modules[modname] = MyModule(modname) self.addCleanup(operator.delitem, sys.modules, modname) g = pgen2_driver.load_packaged_grammar(modname, 'Grammar.txt') self.assertEqual(g.elephant, 19)
Example #28
Source File: test_parser.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_load_packaged_grammar(self): modname = __name__ + '.load_test' class MyLoader: def get_data(self, where): return pickle.dumps({'elephant': 19}) class MyModule(types.ModuleType): __file__ = 'parsertestmodule' __loader__ = MyLoader() sys.modules[modname] = MyModule(modname) self.addCleanup(operator.delitem, sys.modules, modname) g = pgen2_driver.load_packaged_grammar(modname, 'Grammar.txt') self.assertEqual(g.elephant, 19)
Example #29
Source File: test_pointers.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_basics(self): from operator import delitem for ct, pt in zip(ctype_types, python_types): i = ct(42) p = pointer(i) ## print type(p.contents), ct self.assertIs(type(p.contents), ct) # p.contents is the same as p[0] ## print p.contents ## self.assertEqual(p.contents, 42) ## self.assertEqual(p[0], 42) self.assertRaises(TypeError, delitem, p, 0)
Example #30
Source File: test_operator.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_delitem(self): a = [4, 3, 2, 1] self.assertRaises(TypeError, operator.delitem, a) self.assertRaises(TypeError, operator.delitem, a, None) self.assertTrue(operator.delitem(a, 1) is None) self.assertTrue(a == [4, 2, 1])