Rafael Uzarowski commited on
Commit
125ed21
Β·
unverified Β·
1 Parent(s): 442a6b2

File Tree: fix the manual test printing of nested structure

Browse files
Files changed (1) hide show
  1. tests/test_file_tree_visualize.py +14 -3
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
- for item in items:
96
- text = item["text"]
97
- print(f"{text} [{item['type']}]")
 
 
 
 
 
 
 
 
 
 
 
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