def test_deletion(): child = SpedNode('child', []) parent = SpedNode('parent', []) parent.insert(child) child.delete() assert not parent.children
def test_insert_order_mixed_pos(): children = [SpedNode('a'), SpedNode('a')] parent = SpedNode('', children=children) parent.insert(SpedNode('b')) assert parent.children == [ SpedNode('a'), SpedNode('a'), SpedNode('b') ]
def test_iter_wont_raise_recursion_error(): "this test setup used to raise a RecursiveErrror due to list.insert method" parent = SpedNode('parent') son = SpedNode('son', children=[SpedNode('grandchild')]) assert parent.count() == 1 assert son.count() == 2 parent.insert(son) assert parent.count() == 3
def test_parent_iteration(): child = SpedNode('child', []) parent = SpedNode('parent', []) parent.insert(child) assert child.parent is parent assert list(child.ancestors()) == [child, parent] # test another insertion method child2 = SpedNode('child2', []) parent2 = SpedNode('parent2', [child2]) assert child2.parent is parent2 assert list(child2.ancestors()) == [child2, parent2] # yet another insertion method parent3 = SpedNode('parent3', []) child3 = SpedNode('child3', [], parent=parent3) assert child3.parent is parent3 assert list(child3.ancestors()) == [child3, parent3]