File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
77## [ Unreleased]
88### Added:
9- - Misc: Pull request template
9+ - Misc: Pull request template.
10+ ### Fixed:
11+ - Tree Helper: Subtree to inherit ` sep ` property from root node.
1012
1113## [ 0.21.1] - 2024-08-29
1214### Changed:
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ def get_subtree(
9292 Returns:
9393 (Node)
9494 """
95+ tree_sep = tree .sep
9596 tree = tree .copy ()
9697
9798 if node_name_or_path :
@@ -104,6 +105,9 @@ def get_subtree(
104105
105106 if max_depth :
106107 tree = prune_tree (tree , max_depth = max_depth )
108+
109+ # Assign original tree's sep to subtree
110+ tree .sep = tree_sep
107111 return tree
108112
109113
Original file line number Diff line number Diff line change @@ -47,6 +47,25 @@ class NodeA(node.Node):
4747 assert_tree_structure_basenode_root_attr (root_clone )
4848
4949
50+ class TestGetSubtree :
51+ @staticmethod
52+ def test_get_subtree (tree_node ):
53+ # Subtree is b/d, b/e/g, b/e/h
54+ tree_subtree = helper .get_subtree (tree_node , "a/b" )
55+ assert tree_subtree .node_name == "b"
56+ assert len (tree_subtree .children ) == 2
57+ assert not len (tree_subtree .children [0 ].children )
58+ assert len (tree_subtree .children [1 ].children ) == 2
59+
60+ @staticmethod
61+ def test_get_subtree_sep (tree_node ):
62+ # Subtree is b/d, b/e/g, b/e/h
63+ tree_node .sep = "."
64+ tree_subtree = helper .get_subtree (tree_node , "a.b" )
65+ assert tree_subtree .children [0 ].path_name == ".b.d"
66+ assert tree_subtree .children [1 ].path_name == ".b.e"
67+
68+
5069class TestPruneTree :
5170 @staticmethod
5271 def test_prune_tree (tree_node ):
You can’t perform that action at this time.
0 commit comments