Skip to content

Commit 9df4734

Browse files
committed
fix: print tree for subtrees
1 parent 93cc179 commit 9df4734

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed:
9+
- Tree Export: Print tree to display correctly for subtrees / non-root nodes.
810

911
## [1.0.0] - 2025-09-26
1012
### Added:

bigtree/tree/export/_yield_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def yield_tree(self, strip: bool = True) -> Iterable[tuple[str, str, T]]:
147147
for _node in iterators.preorder_iter(self.tree):
148148
pre_str = ""
149149
fill_str = ""
150-
if not _node.is_root:
150+
if _node != self.tree:
151151
node_depth = _node.depth - initial_depth
152152

153153
# Get fill_str (style_branch or style_stem_final)

tests/tree/export/test_stdout.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,37 @@ def test_print_tree(tree_node):
8282
tree=tree_node,
8383
)
8484

85+
@staticmethod
86+
def test_print_tree_subtree_b(tree_node):
87+
# fmt: off
88+
expected_str = (
89+
"b\n"
90+
"├── d\n"
91+
"└── e\n"
92+
" ├── g\n"
93+
" └── h\n"
94+
)
95+
# fmt: on
96+
assert_print_statement(
97+
export.print_tree,
98+
expected_str,
99+
tree=tree_node["b"],
100+
)
101+
102+
@staticmethod
103+
def test_print_tree_subtree_c(tree_node):
104+
# fmt: off
105+
expected_str = (
106+
"c\n"
107+
"└── f\n"
108+
)
109+
# fmt: on
110+
assert_print_statement(
111+
export.print_tree,
112+
expected_str,
113+
tree=tree_node["c"],
114+
)
115+
85116
@staticmethod
86117
def test_print_tree_alias(tree_node):
87118
expected_str = (

0 commit comments

Comments
 (0)