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


Python List.named方法代码示例

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


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

示例1: test_mixed_all_children

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_mixed_all_children():
    data = {u'A1': u'1',
            u'A2': u'2',
            u'A3': {u'A3B1': {u'A3B1C1': u'1',
                              u'A3B1C2': u'2'},
                    u'A3B2': {u'A3B2C1': u'1'},
                    u'A3B3': [[u'A3B3C0D0', u'A3B3C0D1'],
                             [u'A3B3C1D0', u'A3B3C1D1'],
                             [u'A3B3C2D0', u'A3B3C2D1']]}}

    schema = (
        Dict.named(u'R').of(
            String.named(u'A1'),
            String.named(u'A2'),
            Dict.named(u'A3').of(
                Dict.named(u'A3B1').of(
                    String.named(u'A3B1C1'),
                    String.named(u'A3B1C2')),
                Dict.named(u'A3B2').of(
                    String.named(u'A3B2C1')),
                List.named(u'A3B3').of(
                    List.named(u'A3B3Cx').of(
                        String.named(u'A3B3x'))))))

    top = schema(data)

    names = list(e.name for e in top.all_children)

    assert set(names[0:3]) == set([u'A1', u'A2', u'A3'])
    assert set(names[3:6]) == set([u'A3B1', u'A3B2', u'A3B3'])
    assert set(names[6:12]) == set([u'A3B1C1', u'A3B1C2',
                                    u'A3B2C1', u'A3B3Cx'])
    assert set(names[12:]) == set([u'A3B3x'])
    assert len(names[12:]) == 6
开发者ID:dag,项目名称:flatland,代码行数:36,代码来源:test_containers.py

示例2: test_naming_list_list

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_naming_list_list():
    # make sure nested Slots-users don't bork
    for name, root_flat, leaf_flat in ((u'l', u'l', u'l_0_l2_0_s'),
                                       (None, u'', u'0_l2_0_s')):
        schema = List.named(name).of(List.named(u'l2').of(String.named(u's')))

        root = schema([u'x'])
        leaf = root[0][0]

        assert root.fq_name() == u'.'
        assert root.flattened_name() == root_flat
        assert root.el(u'.') is root

        assert leaf.fq_name() == u'.0.0'
        assert leaf.flattened_name() == leaf_flat
        assert root.el(u'.0.0') is leaf
        assert root.el(u'0.0') is leaf
        assert leaf.el(u'.0.0') is leaf
        with pytest.raises(LookupError):
            leaf.el(u'0')
        with pytest.raises(LookupError):
            leaf.el(u's')
        assert leaf.el(u'.') is root

        assert root.el([u'0', u'0']) is leaf
开发者ID:mbr,项目名称:flatland0,代码行数:27,代码来源:test_containers.py

示例3: form

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
    def form():
        schema = Dict.named(u'field0').of(
            String.named(u'field1'),
            String.named(u'field2'),
            List.named(u'field3').of(String.named(u'field4')),
            List.named(u'field5').of(
                List.named(u'field6').of(String.named(u'field7'))))

        element = schema(
            {u'field1': u'val1',
             u'field2': u'val2',
             u'field3': [u'val3'],
             u'field5': [[u'val4']]})
        element.set_prefix(u'form')
        return {'form': element, 'bound': element.bind}
开发者ID:dag,项目名称:flatland,代码行数:17,代码来源:test_expressions.py

示例4: test_access

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_access():
    pairs = ((u'l_0_i', u'10'), (u'l_1_i', u'11'), (u'l_2_i', u'12'),)

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    elements = list(Integer.named(u'i')(val)
                    for val in (u'10', u'11', u'12'))

    assert len(el) == 3
    assert el[0] == elements[0]
    assert el[1] == elements[1]
    assert el[2] == elements[2]

    assert el[0].value == 10

    assert el[:0] == elements[:0]
    assert el[:1] == elements[:1]
    assert el[0:5] == elements[0:5]
    assert el[-2:-1] == elements[-2:-1]

    assert el[0] in el
    assert elements[0] in el
    assert u'10' in el
    assert 10 in el

    assert el.count(elements[0]) == 1
    assert el.count(u'10') == 1
    assert el.count(10) == 1

    assert el.index(elements[0]) == 0
    assert el.index(u'10') == 0
    assert el.index(10) == 0
开发者ID:dag,项目名称:flatland,代码行数:35,代码来源:test_lists.py

示例5: test_no_duplicates_list_anon_dict

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_no_duplicates_list_anon_dict():
    nd = NotDuplicated(failure=u'%(container_label)s %(position)s')
    schema = (List.named('test').
              of(Dict.of(Integer.named('x'),
                         Integer.named('y')).
                 using(validators=[nd])))
    _test_no_duplicates(schema, {'x': 1, 'y': 2}, {'x': 3, 'y': 4})
开发者ID:mbr,项目名称:flatland0,代码行数:9,代码来源:test_containers.py

示例6: test_set_flat_linear

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_set_flat_linear():
    pairs = [(u'l_0_i', 1), (u'l_1_i', 2), (u'l_2_i', 3)]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), len(pairs))
    eq_(el.value, list(pair[1] for pair in pairs))
开发者ID:dag,项目名称:flatland,代码行数:10,代码来源:test_lists.py

示例7: test_set_flat_miss

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_set_flat_miss():
    pairs = [(u'l_galump', u'3'), (u'l_snorgle', u'4')]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), 0)
    eq_(el.value, [])
开发者ID:dag,项目名称:flatland,代码行数:10,代码来源:test_lists.py

示例8: test_reverse

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_reverse():
    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema([2, 1])
    assert el.flatten() == [(u'l_0_i', u'2'), (u'l_1_i', u'1')]

    el.reverse()
    assert el.value == [1, 2]
    assert el.flatten() == [(u'l_0_i', u'1'), (u'l_1_i', u'2')]
开发者ID:dag,项目名称:flatland,代码行数:10,代码来源:test_lists.py

示例9: test_values_equal_resolution

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_values_equal_resolution():
    v = ValuesEqual('x', '/sub/xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el, None)

    v = ValuesEqual('/x', 'xx')
    el = form(dict(x='a', sub=dict(xx='a')))
    assert v.validate(el['sub'], None)

    # unhashable
    v = ValuesEqual('a', 'b')
    schema = Dict.of(List.named('a').of(String.named('x')),
                     List.named('b').of(String.named('x')))

    el = schema(dict(a=['a', 'b'], b=['a', 'b']))
    assert v.validate(el, None)

    el = schema(dict(a=['a', 'b'], b=['x', 'y']))
    assert not v.validate(el, None)
开发者ID:mbr,项目名称:flatland0,代码行数:21,代码来源:test_scalars.py

示例10: test_slots

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_slots():
    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema([1, 2])

    assert len(list(el._slots)) == 2
    for slot in el._slots:
        # don't really care what it says, just no crashy.
        assert repr(slot)

    assert [slot.value for slot in el._slots] == [1, 2]
开发者ID:dag,项目名称:flatland,代码行数:12,代码来源:test_lists.py

示例11: test_sort

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_sort():
    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema([2, 1])

    el.sort(key=lambda el: el.value)
    assert el.value == [1, 2]
    assert el.flatten() == [(u'l_0_i', u'1'), (u'l_1_i', u'2')]

    el.sort(key=lambda el: el.value, reverse=True)
    assert el.value == [2, 1]
    assert el.flatten() == [(u'l_0_i', u'2'), (u'l_1_i', u'1')]
开发者ID:dag,项目名称:flatland,代码行数:13,代码来源:test_lists.py

示例12: test_set_flat_anonymous_dict

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_set_flat_anonymous_dict():
    pairs = ((u'l_0_x', u'x0'), (u'l_0_y', u'y0'),
             (u'l_1_x', u'x1'), (u'l_1_y', u'y1'),
             (u'l_2_x', u'x2'), )

    schema = List.named(u'l').of(String.named(u'x'), String.named(u'y'))
    el = schema.from_flat(pairs)

    eq_(len(el), 3)
    eq_(el[0].value, dict((k[-1], v) for k, v in pairs[0:2]))
    eq_(el[1].value, dict((k[-1], v) for k, v in pairs[2:4]))
    eq_(el[2].value, {u'x': u'x2', u'y': None})
开发者ID:dag,项目名称:flatland,代码行数:14,代码来源:test_lists.py

示例13: test_mutation

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_mutation():
    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema()

    new_element = Integer.named(u'i')

    def order_ok():
        slot_names = list(_.name for _ in el._slots)
        for idx, name in enumerate(slot_names):
            assert name == str(idx).decode('ascii')

    assert not el
    order_ok()

    # FIXME:? seems to want parsable data, not elements
    el.append(new_element(u'0'))
    assert el.value == [0]
    order_ok()

    el.append(u'123')
    assert el.value == [0, 123]
    order_ok()

    el.extend([u'4', u'5'])
    assert el.value == [0, 123, 4, 5]
    order_ok()

    el[0] = u'3'
    assert el.value == [3, 123, 4, 5]
    order_ok()

    el.insert(0, u'2')
    assert el.value == [2, 3, 123, 4, 5]
    order_ok()

    v = el.pop()
    assert v.value == 5
    assert not v.parent
    order_ok()

    v = el.pop(0)
    assert v.value == 2
    assert el.value == [3, 123, 4]
    order_ok()

    el.remove(u'3')
    assert el.value == [123, 4]
    order_ok()

    del el[:]
    assert el.value == []
    order_ok()
开发者ID:dag,项目名称:flatland,代码行数:54,代码来源:test_lists.py

示例14: test_set_flat_unpruned

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_set_flat_unpruned():
    pairs = [(u'l_0_i', u'0'), (u'l_2_i', u''), (u'l_3_i', u'3')]

    schema = List.named(u'l').of(Integer.named(u'i')).using(prune_empty=False)
    el = schema.from_flat(pairs)

    eq_(len(el), 4)
    eq_(el.value, [0, None, None, 3])

    schema2 = schema.using(maximum_set_flat_members=2)
    el = schema2.from_flat(pairs)

    eq_(len(el), 2)
    eq_(el.value, [0, None])
开发者ID:dag,项目名称:flatland,代码行数:16,代码来源:test_lists.py

示例15: test_set_flat_pruned

# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import named [as 别名]
def test_set_flat_pruned():
    # pruned won't insert empty elements for a skipped index or empty rhs
    pairs = [(u'l_0_i', u'0'), (u'l_2_i', u''), (u'l_3_i', u'3')]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), 2)
    eq_(el.value, [0, 3])

    schema2 = schema.using(maximum_set_flat_members=1)
    el = schema2.from_flat(pairs)

    eq_(len(el), 1)
    eq_(el.value, [0])
开发者ID:dag,项目名称:flatland,代码行数:17,代码来源:test_lists.py


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