Esempio n. 1
0
def test_node_remove_children_sequentially():
    """Test removing children one after the other"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

    assert parent.children[0] is child1
    assert parent.children[1] is child2
    assert child1.parent is parent
    assert child2.parent is parent

    parent.drop_children(child1)

    assert len(parent.children) == 1
    assert child1.parent is None
    assert parent.children[0] is child2
    assert child2.parent is parent

    parent.drop_children(child2)

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None
Esempio n. 2
0
def test_node_remove_child():
    """Test removing child"""
    parent = TreeNode("test")
    child = TreeNode("test")

    parent.add_children(child)

    assert child.parent is parent
    assert parent.children[0] is child

    parent.drop_children(child)

    assert len(parent.children) == 0
    assert child.parent is None
Esempio n. 3
0
def test_node_remove_all_children():
    """Test drop_children() drops all of them"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

    assert parent.children[0] is child1
    assert parent.children[1] is child2
    assert child1.parent is parent
    assert child2.parent is parent

    parent.drop_children()

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None
Esempio n. 4
0
def test_node_remove_children_in_batch():
    """Test removing children all at the same time"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

    assert parent.children[0] is child1
    assert parent.children[1] is child2
    assert child1.parent is parent
    assert child2.parent is parent

    parent.drop_children(child1, child2)

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None