Migrate from Poetry and pyenv to uv
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import pytest
|
||||
import os
|
||||
from src.core.hardlink_manager import HardlinkManager, create_hardlink_structure
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core.file import File
|
||||
from src.core.hardlink_manager import HardlinkManager, create_hardlink_structure
|
||||
from src.core.tag import Tag
|
||||
from src.core.tag_manager import TagManager
|
||||
|
||||
@@ -84,7 +86,9 @@ class TestHardlinkManager:
|
||||
assert (temp_output_dir / "rok" / "1988" / "file1.txt").exists()
|
||||
assert (temp_output_dir / "žánr" / "Drama" / "file2.txt").exists()
|
||||
|
||||
def test_hardlinks_are_same_inode(self, files_with_tags, temp_output_dir, temp_source_dir):
|
||||
def test_hardlinks_are_same_inode(
|
||||
self, files_with_tags, temp_output_dir, temp_source_dir
|
||||
):
|
||||
"""Test že vytvořené soubory jsou opravdu hardlinky (stejný inode)"""
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
manager.create_structure_for_files(files_with_tags)
|
||||
@@ -95,10 +99,14 @@ class TestHardlinkManager:
|
||||
# Same inode = hardlink
|
||||
assert original.stat().st_ino == hardlink.stat().st_ino
|
||||
|
||||
def test_create_structure_with_category_filter(self, files_with_tags, temp_output_dir):
|
||||
def test_create_structure_with_category_filter(
|
||||
self, files_with_tags, temp_output_dir
|
||||
):
|
||||
"""Test vytvoření struktury jen pro vybrané kategorie"""
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
success, fail = manager.create_structure_for_files(files_with_tags, categories=["žánr"])
|
||||
success, fail = manager.create_structure_for_files(
|
||||
files_with_tags, categories=["žánr"]
|
||||
)
|
||||
|
||||
# Only "žánr" tags should be processed (3 links)
|
||||
assert success == 3
|
||||
@@ -107,7 +115,9 @@ class TestHardlinkManager:
|
||||
assert (temp_output_dir / "žánr" / "Komedie" / "file1.txt").exists()
|
||||
assert not (temp_output_dir / "rok").exists()
|
||||
|
||||
def test_create_structure_with_category_roots(self, files_with_tags, temp_output_dir):
|
||||
def test_create_structure_with_category_roots(
|
||||
self, files_with_tags, temp_output_dir
|
||||
):
|
||||
"""category_roots: genres sit at the output root, rok under 'Dle roku'."""
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
roots = {"žánr": "", "rok": "Dle roku"}
|
||||
@@ -137,8 +147,8 @@ class TestHardlinkManager:
|
||||
os.link(temp_source_dir / "file1.txt", mirror_link)
|
||||
|
||||
manager.sync_structure(
|
||||
files_with_tags, category_roots=roots,
|
||||
reserved_subfolders={"Seriály"})
|
||||
files_with_tags, category_roots=roots, reserved_subfolders={"Seriály"}
|
||||
)
|
||||
|
||||
# The mirror (reserved folder) is left alone
|
||||
assert mirror_link.exists()
|
||||
@@ -208,9 +218,7 @@ class TestHardlinkManager:
|
||||
created2, _, removed2, _ = manager.sync_structure([f], category_roots=roots)
|
||||
assert (created2, removed2) == (0, 0)
|
||||
|
||||
def test_link_name_strips_year_by_default(
|
||||
self, tmp_path, tag_manager
|
||||
):
|
||||
def test_link_name_strips_year_by_default(self, tmp_path, tag_manager):
|
||||
"""A pooled 'Title (YYYY).ext' hardlinks into the tag tree as 'Title.ext'."""
|
||||
source = tmp_path / "source"
|
||||
source.mkdir()
|
||||
@@ -242,9 +250,7 @@ class TestHardlinkManager:
|
||||
|
||||
assert (output / "Sci-Fi" / "Matrix.mkv").exists() # year + id stripped
|
||||
|
||||
def test_link_name_keeps_year_on_collision(
|
||||
self, tmp_path, tag_manager
|
||||
):
|
||||
def test_link_name_keeps_year_on_collision(self, tmp_path, tag_manager):
|
||||
"""Two same-title films in one folder keep the year to disambiguate."""
|
||||
source = tmp_path / "source"
|
||||
source.mkdir()
|
||||
@@ -276,9 +282,7 @@ class TestHardlinkManager:
|
||||
assert (output / "Dle roku" / "1972" / "Solaris.mkv").exists()
|
||||
assert (output / "Dle roku" / "2002" / "Solaris.mkv").exists()
|
||||
|
||||
def test_clean_naming_cleanup_is_consistent(
|
||||
self, tmp_path, tag_manager
|
||||
):
|
||||
def test_clean_naming_cleanup_is_consistent(self, tmp_path, tag_manager):
|
||||
"""Clean-named links are stable: a second sync removes/creates nothing."""
|
||||
source = tmp_path / "source"
|
||||
source.mkdir()
|
||||
@@ -349,7 +353,9 @@ class TestHardlinkManager:
|
||||
)
|
||||
|
||||
# Templated name inside the collection folder
|
||||
assert (temp_output_dir / "Dle kolekce" / "James Bond" / "1962 - Dr. No.txt").exists()
|
||||
assert (
|
||||
temp_output_dir / "Dle kolekce" / "James Bond" / "1962 - Dr. No.txt"
|
||||
).exists()
|
||||
# Other categories use the default clean title (no year, not the pool name)
|
||||
assert (temp_output_dir / "Akční" / "Dr. No.txt").exists()
|
||||
|
||||
@@ -365,9 +371,12 @@ class TestHardlinkManager:
|
||||
roots = {"Kolekce": "Dle kolekce"}
|
||||
templates = {"Kolekce": "{year} - {title}{ext}"}
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
manager.sync_structure([f], category_roots=roots, category_filename_templates=templates)
|
||||
created, _, removed, _ = manager.sync_structure(
|
||||
[f], category_roots=roots, category_filename_templates=templates)
|
||||
manager.sync_structure(
|
||||
[f], category_roots=roots, category_filename_templates=templates
|
||||
)
|
||||
_created, _, removed, _ = manager.sync_structure(
|
||||
[f], category_roots=roots, category_filename_templates=templates
|
||||
)
|
||||
|
||||
folder = temp_output_dir / "Dle kolekce" / "James Bond"
|
||||
assert [p.name for p in folder.iterdir()] == ["1962 - Dr. No.txt"]
|
||||
@@ -417,7 +426,8 @@ class TestHardlinkManager:
|
||||
files_with_tags[2].added = "2026-01-01T00:00:00"
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
created, fail = manager.generate_recently_added(
|
||||
files_with_tags, count=2, subfolder="- Nově přidané")
|
||||
files_with_tags, count=2, subfolder="- Nově přidané"
|
||||
)
|
||||
|
||||
recent = temp_output_dir / "- Nově přidané"
|
||||
assert created == 2 and fail == 0
|
||||
@@ -427,7 +437,9 @@ class TestHardlinkManager:
|
||||
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)
|
||||
success, fail = manager.create_structure_for_files(files_with_tags, dry_run=True)
|
||||
success, fail = manager.create_structure_for_files(
|
||||
files_with_tags, dry_run=True
|
||||
)
|
||||
|
||||
assert success == 4
|
||||
assert fail == 0
|
||||
@@ -497,7 +509,7 @@ class TestHardlinkManager:
|
||||
manager = HardlinkManager(temp_output_dir)
|
||||
|
||||
# Create first time
|
||||
success1, _ = manager.create_structure_for_files(files_with_tags)
|
||||
_success1, _ = manager.create_structure_for_files(files_with_tags)
|
||||
|
||||
# Create second time - should skip existing
|
||||
manager2 = HardlinkManager(temp_output_dir)
|
||||
@@ -507,7 +519,9 @@ class TestHardlinkManager:
|
||||
assert success2 == 0
|
||||
assert fail2 == 0
|
||||
|
||||
def test_unique_name_on_conflict(self, temp_source_dir, temp_output_dir, tag_manager):
|
||||
def test_unique_name_on_conflict(
|
||||
self, temp_source_dir, temp_output_dir, tag_manager
|
||||
):
|
||||
"""Two different movies with the same clean name (no year to tell them
|
||||
apart) in one folder get distinct links via a numeric suffix."""
|
||||
f1 = File(temp_source_dir / "file1.txt", tag_manager)
|
||||
@@ -530,7 +544,9 @@ class TestHardlinkManager:
|
||||
assert (folder / "file1.txt").exists()
|
||||
assert (folder / "file1_2.txt").exists()
|
||||
|
||||
def test_czech_characters_in_tags(self, temp_source_dir, temp_output_dir, tag_manager):
|
||||
def test_czech_characters_in_tags(
|
||||
self, temp_source_dir, temp_output_dir, tag_manager
|
||||
):
|
||||
"""Test českých znaků v názvech tagů"""
|
||||
f1 = File(temp_source_dir / "file1.txt", tag_manager)
|
||||
f1.tags.clear()
|
||||
@@ -593,7 +609,9 @@ class TestConvenienceFunction:
|
||||
output = tmp_path / "output"
|
||||
output.mkdir()
|
||||
|
||||
success, fail, errors = create_hardlink_structure([f], output, categories=["include"])
|
||||
success, _fail, _errors = create_hardlink_structure(
|
||||
[f], output, categories=["include"]
|
||||
)
|
||||
|
||||
assert success == 1
|
||||
assert (output / "include" / "yes" / "file.txt").exists()
|
||||
@@ -677,7 +695,7 @@ class TestSyncStructure:
|
||||
f.add_tag(Tag("cat", "tag1"))
|
||||
|
||||
# Remove obsolete links
|
||||
removed, paths = manager.remove_obsolete_links([f])
|
||||
removed, _paths = manager.remove_obsolete_links([f])
|
||||
|
||||
assert removed == 1
|
||||
assert not (output / "cat" / "tag2" / "file.txt").exists()
|
||||
@@ -699,7 +717,7 @@ class TestSyncStructure:
|
||||
f.tags.clear()
|
||||
f.add_tag(Tag("cat", "tag1"))
|
||||
|
||||
removed, paths = manager.remove_obsolete_links([f], dry_run=True)
|
||||
removed, _paths = manager.remove_obsolete_links([f], dry_run=True)
|
||||
|
||||
assert removed == 1
|
||||
# File should still exist (dry run)
|
||||
@@ -747,7 +765,7 @@ class TestSyncStructure:
|
||||
manager.create_structure_for_files([f])
|
||||
|
||||
# Sync again without changes
|
||||
created, c_fail, removed, r_fail = manager.sync_structure([f])
|
||||
_created, _c_fail, removed, _r_fail = manager.sync_structure([f])
|
||||
|
||||
# Nothing should change (existing links are skipped)
|
||||
assert removed == 0
|
||||
@@ -821,7 +839,7 @@ class TestEdgeCases:
|
||||
# output doesn't exist
|
||||
|
||||
manager = HardlinkManager(output)
|
||||
success, fail = manager.create_structure_for_files([f])
|
||||
success, _fail = manager.create_structure_for_files([f])
|
||||
|
||||
assert success == 1
|
||||
assert (output / "cat" / "tag" / "file.txt").exists()
|
||||
@@ -842,7 +860,7 @@ class TestEdgeCases:
|
||||
output.mkdir()
|
||||
|
||||
manager = HardlinkManager(output)
|
||||
success, fail = manager.create_structure_for_files([f])
|
||||
success, _fail = manager.create_structure_for_files([f])
|
||||
|
||||
assert success == 1
|
||||
assert (output / "test" / "tag" / "file with spaces (part 2).txt").exists()
|
||||
@@ -862,7 +880,7 @@ class TestEdgeCases:
|
||||
|
||||
manager = HardlinkManager(output)
|
||||
# Empty list = no categories = no links
|
||||
success, fail = manager.create_structure_for_files([f], categories=[])
|
||||
success, _fail = manager.create_structure_for_files([f], categories=[])
|
||||
|
||||
assert success == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user