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


Python uberdict.udict函数代码示例

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


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

示例1: test_values

def test_values():
    assert list(udict().values()) == []
    ud = udict(a='aa')
    assert list(ud.values()) == ['aa']
    ud['b'] = 'bb'
    assert sorted(ud.values()) == ['aa', 'bb']
    ud['a'] = udict(b='ab')
开发者ID:eukaryote,项目名称:uberdict,代码行数:7,代码来源:test_uberdict.py

示例2: test_setattr_dotted_key

def test_setattr_dotted_key():
    ud = udict(one=udict(two=2))
    setattr(ud, 'one.two', 'onetwo')
    assert ud['one.two'] == 2
    assert getattr(ud, 'one.two') == 'onetwo'
    assert ud['one'] == udict(two=2)
    assert getattr(ud, 'one') == udict(two=2)
开发者ID:eukaryote,项目名称:uberdict,代码行数:7,代码来源:test_uberdict.py

示例3: test_setdefault_value_plain_not_present

def test_setdefault_value_plain_not_present():
    ud = udict()
    child = udict()
    res = ud.setdefault('child', child)
    assert ud['child'] is res
    assert ud['child'] is child
    assert set(ud.keys()) == set(['child'])
开发者ID:eukaryote,项目名称:uberdict,代码行数:7,代码来源:test_uberdict.py

示例4: test_clear

def test_clear():
    ud = udict(a='')
    ud.clear()
    assert ud == udict()

    ud = udict({'a.b': ''})
    ud.clear()
    assert ud == udict()
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例5: test_contains_plain_not_present

def test_contains_plain_not_present():
    ud = udict(foo='bar')
    assert None not in ud
    assert 'foo' in ud
    assert 'bar' not in ud
    ud.pop('foo')
    assert ud == udict()
    assert 'foo' not in ud
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例6: test_contains_plain_present

def test_contains_plain_present():
    assert 'foo' in udict(foo='bar')
    assert 'bar' not in udict(foo='bar')
    assert None in udict.fromdict({None: ''})
    ud = udict.fromdict({1: 2, 3: 4})
    assert 1 in ud
    assert 2 not in ud
    assert 3 in ud
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例7: test_setattr_objectstyle

def test_setattr_objectstyle():
    ud = udict()
    ud.one = 1
    assert len(ud) == 1
    ud.one = udict()
    ud.one.two = 2
    assert ud.one.two == 2
    assert ud['one']['two'] == 2
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例8: test_todict_nested

def test_todict_nested():
    ud = udict(foo=udict(bar='barbar'))
    d = ud.todict()
    assert isinstance(d['foo'], dict)
    assert not isinstance(d['foo'], udict)
    assert items(d) == [
        ('foo', {'bar': 'barbar'})
    ]
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例9: test_getitem_nested_through_non_dict_typeerror

def test_getitem_nested_through_non_dict_typeerror():
    """
    TypeError should be raised when trying to traverse through
    an object that doesn't support `__getitem__`.
    """
    ud = udict(one=udict(two=2))
    with pytest.raises(TypeError):
        ud['one.two.three']
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例10: test_fromkeys_dotted_keys

def test_fromkeys_dotted_keys():
    elems = ['a.b', 'a', 'b']
    ud = udict.fromkeys(elems, udict())
    assert items(ud) == [
        ('a', udict()),
        ('a.b', udict()),
        ('b', udict())
    ]
开发者ID:eukaryote,项目名称:uberdict,代码行数:8,代码来源:test_uberdict.py

示例11: test_pop_dotted

def test_pop_dotted():
    d = {
        'a': udict(b='a->b'),
        'b': 'bb',
        'a.b': 'a.b'
    }
    ud = udict.fromdict(d)
    val = ud.pop('a.b')
    assert val == 'a->b'
    assert ud['a'] == udict()
开发者ID:eukaryote,项目名称:uberdict,代码行数:10,代码来源:test_uberdict.py

示例12: test_fromkeys_value

def test_fromkeys_value():
    ud = udict.fromkeys([], 1)
    assert ud == udict()
    assert ud == dict.fromkeys([], 1)

    ud = udict.fromkeys(range(1), 1)
    assert ud == udict.fromdict({0: 1})
    assert ud == dict.fromkeys(range(1), 1)

    ud = udict.fromkeys(range(10), 0)
    assert ud == udict((i, 0) for i in range(10))
    assert ud == dict.fromkeys(range(10), 0)
开发者ID:eukaryote,项目名称:uberdict,代码行数:12,代码来源:test_uberdict.py

示例13: test_init_udict_arg

def test_init_udict_arg():
    orig = udict({
        'a': {'b': 'a->b'},
        'c': udict({'d': 'c->d'})
    })
    ud = udict(orig)
    elems = items(ud)
    assert elems == [
        ('a', {'b': 'a->b'}),
        ('c', udict(d='c->d'))
    ]
    assert type(elems[0][1]) is dict
    assert type(elems[1][1]) is udict
开发者ID:eukaryote,项目名称:uberdict,代码行数:13,代码来源:test_uberdict.py

示例14: test_fromdict_nested_dicts

def test_fromdict_nested_dicts():
    d = {
        'a': {
            'b': {
                'c': 'a->b->c'
            }
        }
    }
    ud = udict.fromdict(d)
    elems = items(ud)
    assert elems == [
        ('a', udict({'b': udict({'c': 'a->b->c'})}))
    ]
    assert type(elems[0][1]) is udict
开发者ID:eukaryote,项目名称:uberdict,代码行数:14,代码来源:test_uberdict.py

示例15: test_delitem_second_level_success

def test_delitem_second_level_success():
    ud = udict.fromdict({
        'one': {
            'two': 2,
            'blah': {
                'three': 3
            }
        }
    })
    del ud['one.blah']
    assert items(ud) == [
        ('one', udict(two=2))
    ]
    del ud['one.two']
    assert items(ud) == [('one', udict())]
开发者ID:eukaryote,项目名称:uberdict,代码行数:15,代码来源:test_uberdict.py


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