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


Python operator.delitem方法代码示例

本文整理汇总了Python中operator.delitem方法的典型用法代码示例。如果您正苦于以下问题:Python operator.delitem方法的具体用法?Python operator.delitem怎么用?Python operator.delitem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.delitem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_encodableUnicodeEnvironment

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_process.py

示例2: test_check_closed

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_dbm_dumb.py

示例3: test_load_packaged_grammar

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:test_parser.py

示例4: test_load_packaged_grammar

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:test_parser.py

示例5: test_basics

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_pointers.py

示例6: test_delitem

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_operator.py

示例7: test_basics

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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.assertTrue(type(p.contents) is ct)
            # p.contents is the same as p[0]
##            print p.contents
##            self.assertTrue(p.contents == 42)
##            self.assertTrue(p[0] == 42)

            self.assertRaises(TypeError, delitem, p, 0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:15,代码来源:test_pointers.py

示例8: __init__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
def __init__(self, key_file):
        """
        Start an `ssh-agent` and add its socket path and pid to the global
        environment so that SSH sub-processes can use it for authentication.

        :param FilePath key_file: An SSH private key file which can be used
            when authenticating with SSH servers.
        """
        self._cleanups = []

        output = check_output([b"ssh-agent", b"-c"]).splitlines()
        # setenv SSH_AUTH_SOCK /tmp/ssh-5EfGti8RPQbQ/agent.6390;
        # setenv SSH_AGENT_PID 6391;
        # echo Agent pid 6391;
        sock = output[0].split()[2][:-1]
        pid = output[1].split()[2][:-1]
        self._pid = int(pid)

        def patchdict(k, v):
            if k in os.environ:
                self._cleanups.append(
                    lambda old=os.environ[k]: setitem(os.environ, k, old))
            else:
                self._cleanups.append(lambda: delitem(os.environ, k))

            os.environ[k] = v

        patchdict(b"SSH_AUTH_SOCK", sock)
        patchdict(b"SSH_AGENT_PID", pid)

        with open(os.devnull, "w") as discard:
            # See https://clusterhq.atlassian.net/browse/FLOC-192
            check_call(
                [b"ssh-add", key_file.path],
                stdout=discard, stderr=discard) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:37,代码来源:ssh.py

示例9: test_buffer

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:test_array.py

示例10: __delitem__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
def __delitem__(self, key):
        return Expression((self, key), operator.delitem) 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:4,代码来源:expr.py

示例11: test_delitem

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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]) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:8,代码来源:test_operator.py

示例12: override_db_setting

# 需要导入模块: import operator [as 别名]
# 或者: from operator import delitem [as 别名]
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 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:12,代码来源:test_postgresql.py


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