Add "Tipy dne" folder and fix stale genre folder cleanup

This commit is contained in:
2026-06-29 15:33:44 +02:00
parent a71b209539
commit ee99fc957d
7 changed files with 165 additions and 302 deletions
+55 -2
View File
@@ -136,11 +136,30 @@ class TestHardlinkManager:
mirror_link = mirror / "file1.txt"
os.link(temp_source_dir / "file1.txt", mirror_link)
manager.sync_structure(files_with_tags, category_roots=roots)
manager.sync_structure(
files_with_tags, category_roots=roots,
reserved_subfolders={"Seriály"})
# The mirror (not a managed tag folder) is left alone
# The mirror (reserved folder) is left alone
assert mirror_link.exists()
def test_sync_removes_root_genre_folder_when_last_movie_drops_tag(
self, temp_source_dir, temp_output_dir, tag_manager
):
"""A genre folder at the output root is cleaned when no movie has it."""
f = File(temp_source_dir / "file1.txt", tag_manager)
f.tags.clear()
f.add_tag(Tag("žánr", "Akční"))
roots = {"žánr": ""}
manager = HardlinkManager(temp_output_dir)
manager.sync_structure([f], category_roots=roots)
assert (temp_output_dir / "Akční").is_dir()
# last movie with the tag loses it → folder must go
f.tags.clear()
manager.sync_structure([f], category_roots=roots)
assert not (temp_output_dir / "Akční").exists()
def test_category_transform_groups_folder_by_band(
self, temp_source_dir, temp_output_dir, tag_manager
):
@@ -202,6 +221,40 @@ class TestHardlinkManager:
assert [p.name for p in folder.iterdir()] == ["1962 - Dr. No.txt"]
assert removed == 0 # nothing treated as obsolete on the second run
def test_generate_random_tips_creates_hardlinks(
self, files_with_tags, temp_output_dir
):
"""Tips folder gets `count` random pool files as hardlinks."""
manager = HardlinkManager(temp_output_dir)
created, fail = manager.generate_random_tips(files_with_tags, count=2)
tips = temp_output_dir / "Tipy dne"
assert created == 2
assert fail == 0
links = sorted(p.name for p in tips.iterdir())
assert len(links) == 2
# each is a hardlink to one of the source files
srcs = {f.filename for f in files_with_tags}
assert set(links) <= srcs
def test_generate_random_tips_caps_at_available(
self, files_with_tags, temp_output_dir
):
"""Asking for more than available yields all of them, no error."""
manager = HardlinkManager(temp_output_dir)
created, _ = manager.generate_random_tips(files_with_tags, count=99)
assert created == len(files_with_tags)
def test_generate_random_tips_refreshes_each_run(
self, files_with_tags, temp_output_dir
):
"""A second run replaces the previous selection (folder is emptied)."""
manager = HardlinkManager(temp_output_dir)
manager.generate_random_tips(files_with_tags, count=1)
manager.generate_random_tips(files_with_tags, count=1)
tips = temp_output_dir / "Tipy dne"
assert len(list(tips.iterdir())) == 1 # not accumulated to 2
def test_dry_run(self, files_with_tags, temp_output_dir):
"""Test dry run (bez skutečného vytváření)"""
manager = HardlinkManager(temp_output_dir)