Skip to content

Commit

Permalink
Debug Tree JSON Reader (#11)
Browse files Browse the repository at this point in the history
Test:
* Update test_tree_reader.py - debug json test input

Treescriptify:
* Update tree_reader.py - debug method generate_from_json
* Update tree_runner.py - increase timeout from 3 to 5 seconds
  • Loading branch information
DK96-OS authored Apr 19, 2024
1 parent 3a2201d commit 9f12ac0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/test_tree_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def wrap_root_dir(inner_dirs: str) -> str:
return '{"type":"directory", "name":".", "contents":[' + inner_dirs + ']}'
return '[{"type":"directory", "name":".", "contents":[' + inner_dirs + ']}]'


def get_src_dir() -> str:
Expand Down
9 changes: 8 additions & 1 deletion treescriptify/tree_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
"""
import json
from sys import exit
from typing import Generator

from .tree_node_data import TreeNodeData
Expand All @@ -10,7 +11,13 @@ def generate_from_json(json_string: str) -> Generator[TreeNodeData, None, None]:
"""Read the JSON string and generate TreeNodeData for all elements.
"""
full_json = json.loads(json_string)
for i in full_json['contents']:
if len(full_json) == 1:
dirs_dict = full_json[0]
elif len(full_json) < 1:
exit('Tree Command Failed')
else:
exit('Additional unexpected data returned from Tree Command.')
for i in dirs_dict['contents']:
for node in _process_node(i, 0):
yield node

Expand Down
2 changes: 1 addition & 1 deletion treescriptify/tree_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_tree_json(data: InputData) -> str:
capture_output=True,
text=True,
shell=True,
timeout=3
timeout=5
)
#error = result.stderr
return result.stdout
Expand Down

0 comments on commit 9f12ac0

Please # to comment.