def test_cannot_operate_on_rootless(): """ Verify that operations do not work on a TreeBuilder when no root is created. """ builder = TreeBuilder() with pytest.raises(ValueError): builder.move_to_root() with pytest.raises(ValueError): builder.move_to_parent() with pytest.raises(ValueError): builder.build()
def test_after_creation_copy(): """ Test that a single TreeBuilder can be used multiple times properly. """ builder = TreeBuilder() builder.create_root(0) builder.add_child(2, move=True) builder.add_child(13) builder.move_to_parent() builder.add_child(7) t1 = builder.build() builder.move_to_root() builder.set_data(4) builder.add_child(3, move=True) builder.add_child(15) t2 = builder.build() assert t2 is not t1 assert t2[0] is not t1[0] assert t2[0][0] is not t1[0][0] assert t2[1] is not t1[1] assert t2.data == 4 assert t2[0].data == 2 assert t2[0][0].data == 13 assert t2[1].data == 7 assert t2[2].data == 3 assert t2[2][0].data == 15 assert len(t2) == 3 assert len(t2[0]) == 1 assert len(t2[1]) == 0 assert len(t2[2]) == 1