Skip to content

Commit a6fbf84

Browse files
authored
Merge pull request #161 from kayjan/neater-strings
Changed: Neater handling of strings for tests
2 parents 4d630c3 + deb10cb commit a6fbf84

File tree

4 files changed

+325
-40
lines changed

4 files changed

+325
-40
lines changed

tests/node/test_node.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,20 +423,44 @@ def assert_tree_structure_node_self(self):
423423
), f"Node should have path {expected}, but path is {actual}"
424424

425425
# Test show
426-
expected_str = """a\n├── b\n│ ├── d\n│ └── e\n│ ├── g\n│ └── h\n└── c\n └── f\n"""
426+
expected_str = (
427+
"a\n"
428+
"├── b\n"
429+
"│ ├── d\n"
430+
"│ └── e\n"
431+
"│ ├── g\n"
432+
"│ └── h\n"
433+
"└── c\n"
434+
" └── f\n"
435+
)
427436
assert_print_statement(
428437
self.a.show,
429438
expected_str,
430439
)
431440

432-
expected_str = """a\n|-- b\n| |-- d\n| `-- e\n| |-- g\n| `-- h\n`-- c\n `-- f\n"""
441+
expected_str = (
442+
"a\n"
443+
"|-- b\n"
444+
"| |-- d\n"
445+
"| `-- e\n"
446+
"| |-- g\n"
447+
"| `-- h\n"
448+
"`-- c\n"
449+
" `-- f\n"
450+
)
433451
assert_print_statement(
434452
self.a.show,
435453
expected_str,
436454
style="ansi",
437455
)
438456

439-
expected_str = " ┌─ d\n ┌─ b ─┤ ┌─ g\n─ a ─┤ └─ e ─┤\n │ └─ h\n └─ c ─── f\n"
457+
expected_str = (
458+
" ┌─ d\n"
459+
" ┌─ b ─┤ ┌─ g\n"
460+
"─ a ─┤ └─ e ─┤\n"
461+
" │ └─ h\n"
462+
" └─ c ─── f\n"
463+
)
440464
assert_print_statement(
441465
self.a.hshow,
442466
expected_str,

tests/tree/test_construct.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,19 @@ def test_list_to_tree_by_relation_duplicate_intermediate_node():
14271427
("e", "h"), # duplicate parent
14281428
]
14291429
root = list_to_tree_by_relation(relations, allow_duplicates=True)
1430-
expected = """a\n├── b\n│ ├── d\n│ └── e\n│ ├── g\n│ └── h\n└── c\n ├── e\n │ ├── g\n │ └── h\n └── f\n"""
1430+
expected = (
1431+
"a\n"
1432+
"├── b\n"
1433+
"│ ├── d\n"
1434+
"│ └── e\n"
1435+
"│ ├── g\n"
1436+
"│ └── h\n"
1437+
"└── c\n"
1438+
" ├── e\n"
1439+
" │ ├── g\n"
1440+
" │ └── h\n"
1441+
" └── f\n"
1442+
)
14311443
assert_print_statement(print_tree, expected, tree=root)
14321444

14331445
def test_list_to_tree_by_relation_empty_parent(self):
@@ -1444,12 +1456,32 @@ def test_list_to_tree_by_relation_one_tuple():
14441456

14451457
def test_list_to_tree_by_relation_switch_order(self):
14461458
root = list_to_tree_by_relation(self.relations_switch)
1447-
expected = """h\n├── g\n│ ├── e\n│ ├── d\n│ │ ├── b\n│ │ └── a\n│ └── a\n└── f\n └── a\n"""
1459+
expected = (
1460+
"h\n"
1461+
"├── g\n"
1462+
"│ ├── e\n"
1463+
"│ ├── d\n"
1464+
"│ │ ├── b\n"
1465+
"│ │ └── a\n"
1466+
"│ └── a\n"
1467+
"└── f\n"
1468+
" └── a\n"
1469+
)
14481470
assert_print_statement(print_tree, expected, root)
14491471

14501472
def test_list_to_tree_by_relation_switch_order_reverse(self):
14511473
root = list_to_tree_by_relation(self.relations_switch[::-1])
1452-
expected = """h\n├── f\n│ └── a\n└── g\n ├── a\n ├── d\n │ ├── a\n │ └── b\n └── e\n"""
1474+
expected = (
1475+
"h\n"
1476+
"├── f\n"
1477+
"│ └── a\n"
1478+
"└── g\n"
1479+
" ├── a\n"
1480+
" ├── d\n"
1481+
" │ ├── a\n"
1482+
" │ └── b\n"
1483+
" └── e\n"
1484+
)
14531485
assert_print_statement(print_tree, expected, root)
14541486

14551487

@@ -2245,7 +2277,17 @@ def test_dataframe_to_tree_by_relation_duplicate_leaf_node():
22452277
columns=["child", "parent", "age"],
22462278
)
22472279
root = dataframe_to_tree_by_relation(relation_data)
2248-
expected = """a\n├── b\n│ ├── d\n│ ├── e\n│ │ ├── g\n│ │ └── h\n│ └── h\n└── c\n └── h\n"""
2280+
expected = (
2281+
"a\n"
2282+
"├── b\n"
2283+
"│ ├── d\n"
2284+
"│ ├── e\n"
2285+
"│ │ ├── g\n"
2286+
"│ │ └── h\n"
2287+
"│ └── h\n"
2288+
"└── c\n"
2289+
" └── h\n"
2290+
)
22492291
assert_print_statement(print_tree, expected, tree=root, style="const")
22502292

22512293
@staticmethod

0 commit comments

Comments
 (0)