Skip to content

Commit

Permalink
test: add test for overriding/merge_attribute with delete_children
Browse files Browse the repository at this point in the history
  • Loading branch information
kayjan committed Dec 26, 2024
1 parent 5588922 commit 5dd3f63
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/tree/test_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,55 @@ def test_copy_nodes_merge_children_and_leaf_error(self):
str(exc_info.value) == Constants.ERROR_MODIFY_PARAM_MERGE_CHILDREN_OR_LEAVES
)

# overriding, delete_children
def test_copy_nodes_overriding_and_delete_children(self):
from_paths = ["a/aa/bb"]
to_paths = ["a/bb"]

# Set attribute for node
self.root_manual["aa"]["bb"].set_attrs({"age": 2})

modify.copy_nodes(
self.root_manual,
from_paths,
to_paths,
overriding=True,
delete_children=True,
)
assert (
self.root_manual["bb"].get_attr("age") == 2
), "Original node not overridden"

assert not len(self.root_manual["bb"].children), "Children present"
assert search.find_path(self.root_manual, "/a/aa/bb"), "Origin node not present"

# merge_attribute, delete_children
def test_copy_nodes_merge_attribute_and_delete_children(self):
from_paths = ["a/aa/bb"]
to_paths = ["a/bb"]

# Set attribute for node
self.root_manual["aa"]["bb"].set_attrs({"age": 2, "gender": "b"})
self.root_manual["bb"].set_attrs({"age": 1, "hello": "world"})
modify.copy_nodes(
self.root_manual,
from_paths,
to_paths,
merge_attribute=True,
delete_children=True,
)
assert (
self.root_manual["bb"].get_attr("age") == 2
), "Original attribute not updated"
assert (
self.root_manual["bb"].get_attr("hello") == "world"
), "Original attribute not present"
assert (
self.root_manual["bb"].get_attr("gender") == "b"
), "New attribute not present"
assert not len(self.root_manual["bb"].children), "Children present"
assert search.find_path(self.root_manual, "/a/aa/bb"), "Origin node not present"

# merge_children, delete_children
def test_copy_nodes_merge_children_and_delete_children(self):
from_paths = ["d", "e", "g", "f"]
Expand Down Expand Up @@ -1389,6 +1438,55 @@ def test_shift_nodes_merge_children_and_leaf_error(self):
str(exc_info.value) == Constants.ERROR_MODIFY_PARAM_MERGE_CHILDREN_OR_LEAVES
)

# overriding, delete_children
def test_shift_nodes_overriding_and_delete_children(self):
from_paths = ["a/aa/bb"]
to_paths = ["a/bb"]

# Set attribute for node
self.root_manual["aa"]["bb"].set_attrs({"age": 2})

modify.shift_nodes(
self.root_manual,
from_paths,
to_paths,
overriding=True,
delete_children=True,
)
assert (
self.root_manual["bb"].get_attr("age") == 2
), "Original node not overridden"

assert not len(self.root_manual["bb"].children), "Children present"
assert not search.find_path(self.root_manual, "/a/aa/bb"), "Origin node present"

# merge_attribute, delete_children
def test_shift_nodes_merge_attribute_and_delete_children(self):
from_paths = ["a/aa/bb"]
to_paths = ["a/bb"]

# Set attribute for node
self.root_manual["aa"]["bb"].set_attrs({"age": 2, "gender": "b"})
self.root_manual["bb"].set_attrs({"age": 1, "hello": "world"})
modify.shift_nodes(
self.root_manual,
from_paths,
to_paths,
merge_attribute=True,
delete_children=True,
)
assert (
self.root_manual["bb"].get_attr("age") == 2
), "Original attribute not updated"
assert (
self.root_manual["bb"].get_attr("hello") == "world"
), "Original attribute not present"
assert (
self.root_manual["bb"].get_attr("gender") == "b"
), "New attribute not present"
assert not len(self.root_manual["bb"].children), "Children present"
assert not search.find_path(self.root_manual, "/a/aa/bb"), "Origin node present"

# merge_children, delete_children
def test_shift_nodes_merge_children_and_delete_children(self):
from_paths = ["d", "e", "g", "f"]
Expand Down

0 comments on commit 5dd3f63

Please sign in to comment.