• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sleek_reffing.CuteSleekValueDict类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中python_toolbox.sleek_reffing.CuteSleekValueDict的典型用法代码示例。如果您正苦于以下问题:Python CuteSleekValueDict类的具体用法?Python CuteSleekValueDict怎么用?Python CuteSleekValueDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_none

def test_none():
    '''Test that `CuteSleekValueDict` can handle a value of `None`.'''

    d = {
        1: None,
        2: None,
        (1,): None,
        (1, (1,)): None,
        sum: None,
        None: None
    }
    
    csvd = CuteSleekValueDict(
        counter,
        d
    )
    

    assert sequence_tools.are_equal_regardless_of_order(csvd.keys(),
                                                        d.keys())
    
    assert sequence_tools.are_equal_regardless_of_order(csvd.values(),
                                                        d.values())
    
    assert sequence_tools.are_equal_regardless_of_order(csvd.items(),
                                                        d.items())
    

    for key in csvd.iterkeys():
        assert key in csvd
        assert csvd[key] is None
开发者ID:apddup,项目名称:python_toolbox,代码行数:31,代码来源:tests.py


示例2: test_values

    def test_values(self):
        d = CuteSleekValueDict(null_callback)
        self.assertEqual(list(d.values()), [])
        d = CuteSleekValueDict(null_callback, {1: 2})
        self.assertEqual(list(d.values()), [2])

        self.assertRaises(TypeError, d.values, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:7,代码来源:test_generic_dict_tests.py


示例3: test_popitem

    def test_popitem(self):
        if sys_tools.is_pypy:
            raise nose.SkipTest("Pypy doesn't maintain dict order.")
        for copymode in -1, +1:
            # -1: b has same structure as a
            # +1: b is a.copy()
            for log2size in range(12):
                size = 2**log2size
                a = CuteSleekValueDict(null_callback)
                b = CuteSleekValueDict(null_callback)
                for i in range(size):
                    a[repr(i)] = i
                    if copymode < 0:
                        b[repr(i)] = i
                if copymode > 0:
                    b = a.copy()
                for i in range(size):
                    ka, va = ta = a.popitem()
                    self.assertEqual(va, int(ka))
                    kb, vb = tb = b.popitem()
                    self.assertEqual(vb, int(kb))
                    if copymode < 0:
                        self.assertEqual(ta, tb)
                self.assertFalse(a)
                self.assertFalse(b)

        d = CuteSleekValueDict(null_callback)
        self.assertRaises(KeyError, d.popitem)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:28,代码来源:test_generic_dict_tests.py


示例4: test_items

    def test_items(self):
        d = CuteSleekValueDict(null_callback)
        self.assertEqual(d.items(), [])

        d = CuteSleekValueDict(null_callback, {1: 2})
        self.assertEqual(d.items(), [(1, 2)])

        self.assertRaises(TypeError, d.items, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:8,代码来源:test_generic_dict_tests.py


示例5: test_has_key

    def test_has_key(self):
        d = CuteSleekValueDict(null_callback)
        self.assertFalse('a' in d)
        d = CuteSleekValueDict(null_callback, {'a': 1, 'b': 2})
        k = list(d.keys())
        k.sort()
        self.assertEqual(k, ['a', 'b'])

        self.assertRaises(TypeError, d.has_key)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:9,代码来源:test_generic_dict_tests.py


示例6: test_keys

    def test_keys(self):
        d = CuteSleekValueDict(null_callback)
        self.assertEqual(list(d.keys()), [])
        d = CuteSleekValueDict(null_callback, {'a': 1, 'b': 2})
        k = list(d.keys())
        self.assertTrue('a' in d)
        self.assertTrue('b' in d)

        self.assertRaises(TypeError, d.keys, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:9,代码来源:test_generic_dict_tests.py


示例7: test_keys

    def test_keys(self):
        d = CuteSleekValueDict(null_callback)
        self.assertEqual(d.keys(), [])
        d = CuteSleekValueDict(null_callback, {'a': 1, 'b': 2})
        k = d.keys()
        self.assertTrue(d.has_key('a'))
        self.assertTrue(d.has_key('b'))

        self.assertRaises(TypeError, d.keys, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:9,代码来源:test_generic_dict_tests.py


示例8: test_setdefault

    def test_setdefault(self):
        d = CuteSleekValueDict(null_callback)
        self.assertIs(d.setdefault('key0'), None)
        d.setdefault('key0', [])
        self.assertIs(d.setdefault('key0'), None)
        d.setdefault('key', []).append(3)
        self.assertEqual(d['key'][0], 3)
        d.setdefault('key', []).append(4)
        self.assertEqual(len(d['key']), 2)
        self.assertRaises(TypeError, d.setdefault)

        class Exc(Exception): pass

        class BadHash(object):
            fail = False
            def __hash__(self):
                if self.fail:
                    raise Exc()
                else:
                    return 42

        x = BadHash()
        d[x] = 42
        x.fail = True
        self.assertRaises(Exc, d.setdefault, x, [])
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:25,代码来源:test_generic_dict_tests.py


示例9: test_copy

 def test_copy(self):
     d = CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     self.assertEqual(
         d.copy(),
         CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
     )
     self.assertEqual(
         CuteSleekValueDict(null_callback).copy(),
         CuteSleekValueDict(null_callback)
     )
     self.assertRaises(TypeError, d.copy, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:11,代码来源:test_generic_dict_tests.py


示例10: test_get

 def test_get(self):
     d = CuteSleekValueDict(null_callback)
     self.assertIs(d.get('c'), None)
     self.assertEqual(d.get('c', 3), 3)
     d = CuteSleekValueDict(null_callback, {'a': 1, 'b': 2})
     self.assertIs(d.get('c'), None)
     self.assertEqual(d.get('c', 3), 3)
     self.assertEqual(d.get('a'), 1)
     self.assertEqual(d.get('a', 3), 1)
     self.assertRaises(TypeError, d.get)
     self.assertRaises(TypeError, d.get, None, None, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:11,代码来源:test_generic_dict_tests.py


示例11: __init__

 class SimpleUserDict:
     def __init__(self):
         self.d = CuteSleekValueDict(
             null_callback,
             {1: 1, 2: 2, 3: 3}
         )
     def keys(self):
         return list(self.d.keys())
     def __getitem__(self, i):
         return self.d[i]
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:10,代码来源:test_generic_dict_tests.py


示例12: test_pop

    def test_pop(self):
        # Tests for pop with specified key
        d = CuteSleekValueDict(null_callback)
        k, v = 'abc', 'def'
        d[k] = v
        self.assertRaises(KeyError, d.pop, 'ghi')

        self.assertEqual(d.pop(k), v)
        self.assertEqual(len(d), 0)

        self.assertRaises(KeyError, d.pop, k)

        # verify longs/ints get same value when key > 32 bits
        # (for 64-bit archs).  See SF bug #689659. (MAKES NO SENSE ON PY3)
        x = 4503599627370496
        y = 4503599627370496
        h = CuteSleekValueDict(
            null_callback,
            {x: 'anything', y: 'something else'}
        )
        self.assertEqual(h[x], h[y])

        self.assertEqual(d.pop(k, v), v)
        d[k] = v
        self.assertEqual(d.pop(k, 1), v)

        self.assertRaises(TypeError, d.pop)

        class Exc(Exception): pass

        class BadHash(object):
            fail = False
            def __hash__(self):
                if self.fail:
                    raise Exc()
                else:
                    return 42

        x = BadHash()
        d[x] = 42
        x.fail = True
        self.assertRaises(Exc, d.pop, x)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:42,代码来源:test_generic_dict_tests.py


示例13: test_fromkeys

    def test_fromkeys(self):
        self.assertEqual(
            CuteSleekValueDict.fromkeys('abc'),
            CuteSleekValueDict(null_callback,
                                     {'a': None, 'b': None, 'c': None}
                                     )
        )
        
        d = CuteSleekValueDict(null_callback)
        self.assertIsNot(d.fromkeys('abc'), d)
        self.assertEqual(
            d.fromkeys('abc'),
            CuteSleekValueDict(null_callback,
                                     {'a': None, 'b': None, 'c': None})
        )
        self.assertEqual(
            d.fromkeys((4, 5), 0),
            CuteSleekValueDict(null_callback, {4: 0, 5: 0})
        )
        self.assertEqual(
            d.fromkeys([]),
            CuteSleekValueDict(null_callback)
        )
        
        def g():
            yield 1
        self.assertEqual(
            d.fromkeys(g()),
            CuteSleekValueDict(null_callback, {1: None})
        )
        
        self.assertRaises(
            TypeError,
            CuteSleekValueDict(null_callback).fromkeys,
            3
        )

        class CSVDoid(CuteSleekValueDict): pass
        self.assertEqual(
            CSVDoid.fromkeys('a'),
            CuteSleekValueDict(null_callback, {'a': None})
        )
        self.assertEqual(
            CSVDoid(null_callback).fromkeys('a'),
            CuteSleekValueDict(null_callback, {'a': None})
        )
        self.assertIsInstance(
            CSVDoid.fromkeys('a'),
            CSVDoid
        )
        self.assertIsInstance(
            CSVDoid(null_callback).fromkeys('a'),
            CSVDoid
        )

        #class myCSVD(CuteSleekValueDict):
            #def __new__(cls, callback):
                #return UserDict.UserDict()
        #ud = myCSVD.fromkeys('ab')
        #self.assertEqual(
            #ud,
            #CuteSleekValueDict(null_callback, {'a': None, 'b': None})
        #)
        #self.assertIsInstance(
            #ud,            
            #UserDict.UserDict
        #)
        self.assertRaises(TypeError, CuteSleekValueDict.fromkeys)

        class Exc(Exception): pass

        class badCSVD1(CuteSleekValueDict):
            def __init__(self, callback):
                raise Exc()

        self.assertRaises(Exc, badCSVD1.fromkeys, [1])

        class BadSeq(object):
            def __iter__(self):
                return self
            def __next__(self):
                raise Exc()

        self.assertRaises(Exc, CuteSleekValueDict.fromkeys, BadSeq())

        class badCSVD2(dict):
            def __setitem__(self, key, value):
                raise Exc()

        self.assertRaises(Exc, badCSVD2.fromkeys, [1])

        # test fast path for dictionary inputs
        d = CuteSleekValueDict(null_callback, list(zip(list(range(6)), list(range(6)))))
        self.assertEqual(
            CuteSleekValueDict.fromkeys(d, 0),
            CuteSleekValueDict(null_callback, list(zip(list(range(6)), [0]*6))))
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:96,代码来源:test_generic_dict_tests.py


示例14: test_update

    def test_update(self):
        d = CuteSleekValueDict(null_callback)
        d.update(CuteSleekValueDict(null_callback, {1: 100}))
        d.update({2: 20})
        d.update(CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3}))
        self.assertEqual(
            d,
            CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
        )

        d.update()
        self.assertEqual(
            d,
            CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
        )

        self.assertRaises((TypeError, AttributeError), d.update, None)

        class SimpleUserDict:
            def __init__(self):
                self.d = CuteSleekValueDict(
                    null_callback,
                    {1: 1, 2: 2, 3: 3}
                )
            def keys(self):
                return list(self.d.keys())
            def __getitem__(self, i):
                return self.d[i]
            
        d.clear()
        d.update(SimpleUserDict())
        self.assertEqual(
            d,
            CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
        )

        class Exc(Exception): pass

        d.clear()
        class FailingUserDict:
            def keys(self):
                raise Exc
        self.assertRaises(Exc, d.update, FailingUserDict())

        class FailingUserDict:
            def keys(self):
                class BogonIter:
                    def __init__(self):
                        self.i = 1
                    def __iter__(self):
                        return self
                    def __next__(self):
                        if self.i:
                            self.i = 0
                            return 'a'
                        raise Exc
                return BogonIter()
            def __getitem__(self, key):
                return key
        self.assertRaises(Exc, d.update, FailingUserDict())

        class FailingUserDict:
            def keys(self):
                class BogonIter:
                    def __init__(self):
                        self.i = ord('a')
                    def __iter__(self):
                        return self
                    def __next__(self):
                        if self.i <= ord('z'):
                            rtn = chr(self.i)
                            self.i += 1
                            return rtn
                        raise StopIteration
                return BogonIter()
            def __getitem__(self, key):
                raise Exc
        self.assertRaises(Exc, d.update, FailingUserDict())

        class badseq(object):
            def __iter__(self):
                return self
            def __next__(self):
                raise Exc()

        self.assertRaises(Exc,
                          CuteSleekValueDict(null_callback).update,
                          badseq())

        self.assertRaises(
            ValueError,
            CuteSleekValueDict(null_callback).update,
            [(1, 2, 3)]
        )
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:94,代码来源:test_generic_dict_tests.py


示例15: test_clear

    def test_clear(self):
        d = CuteSleekValueDict(null_callback, {1: 1, 2: 2, 3: 3})
        d.clear()
        self.assertEqual(d, CuteSleekValueDict(null_callback))

        self.assertRaises(TypeError, d.clear, None)
开发者ID:cool-RR,项目名称:python_toolbox,代码行数:6,代码来源:test_generic_dict_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python jobset.run函数代码示例发布时间:2022-05-27
下一篇:
Python gc_tools.collect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap