Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions tests/node/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,44 @@ def assert_tree_structure_node_self(self):
), f"Node should have path {expected}, but path is {actual}"

# Test show
expected_str = """a\n├── b\n│ ├── d\n│ └── e\n│ ├── g\n│ └── h\n└── c\n └── f\n"""
expected_str = (
"a\n"
"├── b\n"
"│ ├── d\n"
"│ └── e\n"
"│ ├── g\n"
"│ └── h\n"
"└── c\n"
" └── f\n"
)
assert_print_statement(
self.a.show,
expected_str,
)

expected_str = """a\n|-- b\n| |-- d\n| `-- e\n| |-- g\n| `-- h\n`-- c\n `-- f\n"""
expected_str = (
"a\n"
"|-- b\n"
"| |-- d\n"
"| `-- e\n"
"| |-- g\n"
"| `-- h\n"
"`-- c\n"
" `-- f\n"
)
assert_print_statement(
self.a.show,
expected_str,
style="ansi",
)

expected_str = " ┌─ d\n ┌─ b ─┤ ┌─ g\n─ a ─┤ └─ e ─┤\n │ └─ h\n └─ c ─── f\n"
expected_str = (
" ┌─ d\n"
" ┌─ b ─┤ ┌─ g\n"
"─ a ─┤ └─ e ─┤\n"
" │ └─ h\n"
" └─ c ─── f\n"
)
assert_print_statement(
self.a.hshow,
expected_str,
Expand Down
50 changes: 46 additions & 4 deletions tests/tree/test_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,19 @@ def test_list_to_tree_by_relation_duplicate_intermediate_node():
("e", "h"), # duplicate parent
]
root = list_to_tree_by_relation(relations, allow_duplicates=True)
expected = """a\n├── b\n│ ├── d\n│ └── e\n│ ├── g\n│ └── h\n└── c\n ├── e\n │ ├── g\n │ └── h\n └── f\n"""
expected = (
"a\n"
"├── b\n"
"│ ├── d\n"
"│ └── e\n"
"│ ├── g\n"
"│ └── h\n"
"└── c\n"
" ├── e\n"
" │ ├── g\n"
" │ └── h\n"
" └── f\n"
)
assert_print_statement(print_tree, expected, tree=root)

def test_list_to_tree_by_relation_empty_parent(self):
Expand All @@ -1444,12 +1456,32 @@ def test_list_to_tree_by_relation_one_tuple():

def test_list_to_tree_by_relation_switch_order(self):
root = list_to_tree_by_relation(self.relations_switch)
expected = """h\n├── g\n│ ├── e\n│ ├── d\n│ │ ├── b\n│ │ └── a\n│ └── a\n└── f\n └── a\n"""
expected = (
"h\n"
"├── g\n"
"│ ├── e\n"
"│ ├── d\n"
"│ │ ├── b\n"
"│ │ └── a\n"
"│ └── a\n"
"└── f\n"
" └── a\n"
)
assert_print_statement(print_tree, expected, root)

def test_list_to_tree_by_relation_switch_order_reverse(self):
root = list_to_tree_by_relation(self.relations_switch[::-1])
expected = """h\n├── f\n│ └── a\n└── g\n ├── a\n ├── d\n │ ├── a\n │ └── b\n └── e\n"""
expected = (
"h\n"
"├── f\n"
"│ └── a\n"
"└── g\n"
" ├── a\n"
" ├── d\n"
" │ ├── a\n"
" │ └── b\n"
" └── e\n"
)
assert_print_statement(print_tree, expected, root)


Expand Down Expand Up @@ -2245,7 +2277,17 @@ def test_dataframe_to_tree_by_relation_duplicate_leaf_node():
columns=["child", "parent", "age"],
)
root = dataframe_to_tree_by_relation(relation_data)
expected = """a\n├── b\n│ ├── d\n│ ├── e\n│ │ ├── g\n│ │ └── h\n│ └── h\n└── c\n └── h\n"""
expected = (
"a\n"
"├── b\n"
"│ ├── d\n"
"│ ├── e\n"
"│ │ ├── g\n"
"│ │ └── h\n"
"│ └── h\n"
"└── c\n"
" └── h\n"
)
assert_print_statement(print_tree, expected, tree=root, style="const")

@staticmethod
Expand Down
Loading