Spaces:
Paused
Paused
Rafael Uzarowski commited on
File Tree: fix the manual test printing of nested structure
Browse files
tests/test_file_tree_visualize.py
CHANGED
|
@@ -92,9 +92,20 @@ def print_flat(items: List[Dict[str, Any]]) -> None:
|
|
| 92 |
|
| 93 |
def print_nested(items: List[Dict[str, Any]], root_label: str) -> None:
|
| 94 |
print(root_label)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
@contextmanager
|
|
|
|
| 92 |
|
| 93 |
def print_nested(items: List[Dict[str, Any]], root_label: str) -> None:
|
| 94 |
print(root_label)
|
| 95 |
+
|
| 96 |
+
def recurse(nodes: List[Dict[str, Any]], prefix: str) -> None:
|
| 97 |
+
total = len(nodes)
|
| 98 |
+
for index, node in enumerate(nodes):
|
| 99 |
+
is_last = index == total - 1
|
| 100 |
+
connector = "βββ " if is_last else "βββ "
|
| 101 |
+
label = node["name"] + ("/" if node["type"] == "folder" else "")
|
| 102 |
+
print(f"{prefix}{connector}{label} [{node['type']}]")
|
| 103 |
+
children = node.get("items") or []
|
| 104 |
+
if children:
|
| 105 |
+
child_prefix = prefix + (" " if is_last else "β ")
|
| 106 |
+
recurse(children, child_prefix)
|
| 107 |
+
|
| 108 |
+
recurse(items, "")
|
| 109 |
|
| 110 |
|
| 111 |
@contextmanager
|