diff --git a/justpath/show.py b/justpath/show.py index 5071dfe..5741a12 100644 --- a/justpath/show.py +++ b/justpath/show.py @@ -100,7 +100,10 @@ def show_stats(json: bool, follow_symlinks: bool): print(dumps(info)) else: print(t, "directories in your PATH") - print(e, "do" if e > 1 else "does", "not exist") + if e == 0: + print("All directories exist") + else: + print(e, "do" if e > 1 else "does", "not exist") print(d, "duplicate" + "s" if d > 1 else "") @@ -181,7 +184,7 @@ def modify_rows( if duplicates: rows = [row for row in rows if row.count > 1] if purge_duplicates: - rows = no_duplicates(rows, follow_symlinks) + rows = remove_duplicates(rows, follow_symlinks) if invalid: rows = [row for row in rows if row.has_error] if purge_invalid: @@ -226,7 +229,7 @@ def print_row(row: Row, color: bool, n: int): print(modifier + str(row.i).rjust(n), str(row.path), comment) -def no_duplicates(rows, follow_symlinks): +def remove_duplicates(rows, follow_symlinks): seen = set() result = [] for row in rows: @@ -236,5 +239,6 @@ def no_duplicates(rows, follow_symlinks): p = identity(row.path) if p not in seen: seen.add(p) + row.count = 1 result.append(row) return result diff --git a/tests/test_show.py b/tests/test_show.py index 665517b..a33a08d 100644 --- a/tests/test_show.py +++ b/tests/test_show.py @@ -4,7 +4,7 @@ import pytest from typer.testing import CliRunner -from justpath.show import typer_app, PathVar +from justpath.show import typer_app, PathVar, remove_duplicates commands = [ @@ -18,6 +18,7 @@ ["--duplicates"], ["--purge-duplicates"], ["--correct"], + ["--correct", "--follow-symlinks"], ] # several commands give a fault with non-latin characters in subprocess call @@ -45,15 +46,23 @@ def test_from_list(tmp_path): assert len(pv) == 2 -def test_with_simlink_setup(tmp_path): +def test_with_simlinks(tmp_path): a = tmp_path / "a" a.mkdir() b = Path(tmp_path / "b") b.symlink_to(a, target_is_directory=True) - print(a.exists()) - print(b.exists()) + assert a.exists() + assert b.exists() print(a) print(b) print(b.resolve()) - print(PathVar.from_list([a, b]).to_rows(True)) - assert True + rows = PathVar.from_list([a, b]).to_rows(follow_symlinks=False) + assert rows[0].count == 1 + assert rows[0].count == 1 + rows = PathVar.from_list([a, b]).to_rows(follow_symlinks=True) + assert rows[0].count == 2 + assert rows[1].count == 2 + rows1 = remove_duplicates(rows, follow_symlinks=True) + assert len(rows1) == 1 + rows2 = remove_duplicates(rows, follow_symlinks=False) + assert len(rows2) == 2