def test_structural_copy_copies_branches_but_not_leaves(example_tree): result = structural_copy(example_tree) for path, value in walk(example_tree): assert get_at(result, path[:-1]) is not get_at(example_tree, path[:-1]) assert get_at(result, path) is value
def test_get_at_can_get_a_leaf(example_tree): assert get_at(example_tree, ('foo', 'bar', 'baz')) == sentinel.foobarbaz
def test_get_at_non_existent_path(example_tree): with pytest.raises(AttributeError): get_at(example_tree, ('does', 'not', 'exist'))
def test_get_at_empty_path_in_empty_tree(): assert get_at(Tree(), []) == Tree()
def test_get_at_empty_path(example_tree): assert get_at(example_tree, []) == example_tree
def test_get_at_can_get_a_subtree(example_tree): assert get_at(example_tree, ('foo', 'bar')) == example_tree.foo.bar