Add configurable library reference roots
This commit is contained in:
+37
-2
@@ -12,8 +12,8 @@ def test_cli_writes_reports_and_prints_counts(tmp_path, monkeypatch, capsys):
|
||||
music.mkdir()
|
||||
|
||||
crate_text = (
|
||||
"Users/djsplice/OneDrive/Jukebox/Found.mp漳牴k"
|
||||
"Users/djsplice/OneDrive/Jukebox/Missing.mp漳牴k"
|
||||
"Users/sample-user/OneDrive/Jukebox/Found.mp漳牴k"
|
||||
"Users/sample-user/OneDrive/Jukebox/Missing.mp漳牴k"
|
||||
)
|
||||
(subcrates / "Test.crate").write_bytes(crate_text.encode("utf-16-le"))
|
||||
(music / "Found.mp3").write_bytes(b"synthetic audio")
|
||||
@@ -47,3 +47,38 @@ def test_cli_writes_reports_and_prints_counts(tmp_path, monkeypatch, capsys):
|
||||
rows = list(csv.DictReader(csv_file))
|
||||
assert [row["exists_by_filename"] for row in rows] == ["True", "False"]
|
||||
assert "Total missing references: 1" in report_path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_cli_accepts_old_reference_root(tmp_path, monkeypatch, capsys):
|
||||
serato = tmp_path / "serato"
|
||||
subcrates = serato / "Subcrates"
|
||||
music = tmp_path / "music"
|
||||
subcrates.mkdir(parents=True)
|
||||
music.mkdir()
|
||||
(subcrates / "Test.crate").write_bytes(
|
||||
"Archive/Jukebox/Found.mp3otrk".encode("utf-16-le")
|
||||
)
|
||||
(music / "Found.mp3").write_bytes(b"synthetic audio")
|
||||
monkeypatch.setattr(
|
||||
sys,
|
||||
"argv",
|
||||
[
|
||||
"serato-doctor",
|
||||
"--serato",
|
||||
str(serato),
|
||||
"--music",
|
||||
str(music),
|
||||
"--out",
|
||||
str(tmp_path / "scan.csv"),
|
||||
"--report",
|
||||
str(tmp_path / "report.txt"),
|
||||
"--reference-root",
|
||||
"/Archive/Jukebox",
|
||||
],
|
||||
)
|
||||
|
||||
main()
|
||||
|
||||
output = capsys.readouterr().out
|
||||
assert "Crate references: 1" in output
|
||||
assert "Missing by filename: 0" in output
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from pathlib import Path
|
||||
|
||||
from serato_doctor.config import ScanConfig
|
||||
|
||||
|
||||
def test_scan_config_freezes_reference_roots():
|
||||
roots = (Path(root) for root in ["/old/one", "/old/two"])
|
||||
|
||||
config = ScanConfig.build(
|
||||
serato=Path("serato"),
|
||||
music=Path("music"),
|
||||
out=Path("scan.csv"),
|
||||
report=Path("report.txt"),
|
||||
reference_roots=roots,
|
||||
)
|
||||
|
||||
assert config.reference_roots == (Path("/old/one"), Path("/old/two"))
|
||||
+43
-4
@@ -2,7 +2,13 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from serato_doctor.crate_parser import clean_path, load_crate, parse_crate
|
||||
from serato_doctor.crate_parser import (
|
||||
clean_path,
|
||||
load_crate,
|
||||
parse_crate,
|
||||
parse_crates,
|
||||
path_markers,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -22,9 +28,9 @@ def test_parse_crate_extracts_references(tmp_path):
|
||||
crate_path = tmp_path / "House.crate"
|
||||
crate_text = (
|
||||
"header"
|
||||
"Users/djsplice/OneDrive/Jukebox/House/First.mp漳牴k"
|
||||
"Users/sample-user/OneDrive/Jukebox/House/First.mp漳牴k"
|
||||
"metadata"
|
||||
"Users/djsplice/OneDrive/Jukebox/House/Second.m4愠otrk"
|
||||
"Users/sample-user/OneDrive/Jukebox/House/Second.m4愠otrk"
|
||||
)
|
||||
crate_path.write_bytes(crate_text.encode("utf-16-le"))
|
||||
|
||||
@@ -41,7 +47,40 @@ def test_parse_crate_extracts_references(tmp_path):
|
||||
def test_parse_crate_ignores_record_without_stop_marker(tmp_path):
|
||||
crate_path = Path(tmp_path) / "Incomplete.crate"
|
||||
crate_path.write_bytes(
|
||||
"Users/djsplice/OneDrive/Jukebox/House/Incomplete.mp3".encode("utf-16-le")
|
||||
"Users/sample-user/OneDrive/Jukebox/House/Incomplete.mp3".encode(
|
||||
"utf-16-le"
|
||||
)
|
||||
)
|
||||
|
||||
assert parse_crate(crate_path) == []
|
||||
|
||||
|
||||
def test_parse_crate_uses_configured_reference_root(tmp_path):
|
||||
crate_path = tmp_path / "Migrated.crate"
|
||||
crate_path.write_bytes(
|
||||
"Archive/Old Library/House/Track.mp3otrk".encode("utf-16-le")
|
||||
)
|
||||
|
||||
references = parse_crate(crate_path, [Path("/Archive/Old Library")])
|
||||
|
||||
assert references[0].path == Path("/Archive/Old Library/House/Track.mp3")
|
||||
|
||||
|
||||
def test_default_path_markers_do_not_contain_a_username():
|
||||
assert path_markers([]) == ("Users/", "Volumes/")
|
||||
|
||||
|
||||
def test_parse_crates_reuses_configured_roots_for_every_crate(tmp_path):
|
||||
for name in ("First", "Second"):
|
||||
(tmp_path / f"{name}.crate").write_bytes(
|
||||
f"Archive/Jukebox/{name}.mp3otrk".encode("utf-16-le")
|
||||
)
|
||||
|
||||
references = parse_crates(
|
||||
tmp_path, (root for root in [Path("/Archive/Jukebox")])
|
||||
)
|
||||
|
||||
assert {reference.filename for reference in references} == {
|
||||
"First.mp3",
|
||||
"Second.mp3",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user