Skip to content

Commit

Permalink
#29 fix tree for some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve authored and filiplajszczak committed May 21, 2021
1 parent 3de1ff5 commit 7b76709
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions cli/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _format_tree(data, current):
chunks = [cc for cc in entry.split('/') if cc]
item = chunks[-1].replace("\0", "/")
level = len(chunks) - 1
level_tracker = set([lvl for lvl in level_tracker if lvl <= level])
indents = [connector if lvl in level_tracker else filler for lvl in range(level)]
indents.append(last_child if level not in level_tracker else next_child)
level_tracker.add(level)
Expand Down
18 changes: 13 additions & 5 deletions tests/test_cli_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,37 @@ def test_prints_formatted_tree_when_successfull_api_call(self, mock_path, home_d
f'{home_dir}/README.txt',
f'{home_dir}/dir_one/',
f'{home_dir}/dir_one/bar.txt',
f'{home_dir}/dir_one/foo.txt',
f'{home_dir}/dir_one/nested_one/',
f'{home_dir}/dir_one/nested_one/foo.txt',
f'{home_dir}/dir_one/nested_two/',
f'{home_dir}/empty/',
f'{home_dir}/dir_two/',
f'{home_dir}/file.py'
f'{home_dir}/dir_two/quux',
f'{home_dir}/dir_two/baz/',
f'{home_dir}/dir_three/',
f'{home_dir}/dir_three/last.txt',
]

result = runner.invoke(app, ["tree", "~"])

print(result.stdout)
expected = dedent(f"""\
{home_dir}:
.
├── README.txt
├── dir_one/
│ ├── bar.txt
│ ├── foo.txt
│ ├── nested_one/
│ │ └── foo.txt
│ └── nested_two/
├── empty/
├── dir_two/
└── file.py
""")
│ ├── quux
│ └── baz/
└── dir_three/
└── last.txt
""")

assert result.stdout == expected

def test_does_not_print_tree_when_path_is_incorrect(self, mock_path):
Expand Down

0 comments on commit 7b76709

Please sign in to comment.