コード例 #1
0
def test_element_type_change_children_must_recalculate_hash():
    element_type = ElementType('xsd:string')
    children = [Element(name='Name', element_type=element_type)]

    f = ElementType(name='ModelType', children=children)
    current_hash = hash(f)

    owner = Element(name='Owner', element_type=element_type)
    f.add_child(owner)

    assert hash(f) != current_hash
コード例 #2
0
def test_element_type_add_child_must_add_item_properly():
    element_type = ElementType('xsd:string')
    children = [Element(name='Name', element_type=element_type)]

    f = ElementType(name='ModelType', children=children)
    current_hash = hash(f)

    code = Element(name='Code', element_type=element_type)
    f.add_child(code)

    assert hash(f) != current_hash

    assert f.children[0] == code
コード例 #3
0
def test_element_children_original_order_must_keep_order_when_added_child():
    element_type = ElementType('xsd:string')

    # A not alphabetical order...
    children = [
        Element(name='Surname', element_type=element_type),
        Element(name='Name', element_type=element_type),
        Element(name='City', element_type=element_type),
    ]

    f = ElementType(name='ModelType', children=children)

    nick = Element(name='Nickname', element_type=element_type)

    f.add_child(nick)

    expected_children = children + [nick]

    assert f.children != expected_children
    assert f.children_original_order == expected_children