Skip to content

Commit

Permalink
test for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
epogrebnyak committed Feb 28, 2024
1 parent 199d7a3 commit b6097e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 7 additions & 3 deletions justpath/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
21 changes: 15 additions & 6 deletions tests/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -18,6 +18,7 @@
["--duplicates"],
["--purge-duplicates"],
["--correct"],
["--correct", "--follow-symlinks"],
]

# several commands give a fault with non-latin characters in subprocess call
Expand Down Expand Up @@ -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

0 comments on commit b6097e1

Please sign in to comment.