Exemplo n.º 1
0
    def test_detach_noop(self):
        tracker = self.tracker()

        node = Node("node", None, None)
        node = node.detach()
        assert not node.parent
        assert not node.root

        parent2 = Node("parent2", None, tracker.root)
        parent2.addchild(node)

        assert list(parent2.children) == [node]
        assert node.root is tracker.root
        assert node.parent is parent2
Exemplo n.º 2
0
    def test_remove_child(self):
        tracker = self.tracker()

        parent1 = Node("parent1", None, tracker.root)
        parent2 = Node("parent2", None, tracker.root)

        child = Node("child", None, parent1)
        parent1.addchild(child)
        assert list(parent1.children) == [child]
        assert child.parent is parent1

        child = child.detach()
        assert child.parent is None
        assert list(parent1.children) == []

        child.parent = parent2
        parent2.addchild(child)
        assert list(parent2.children) == [child]
        assert child.parent is parent2