from pathlib import Path import pytest from serato_doctor.crate_parser import clean_path, load_crate, parse_crate @pytest.mark.parametrize( ("artifact", "expected"), [ ("song.mp漳", "song.mp3"), ("song.m4愠", "song.m4a"), ("song.wa瘠", "song.wav"), ("song.ai映", "song.aif"), ], ) def test_clean_path_repairs_known_extension_artifacts(artifact, expected): assert clean_path(artifact) == expected 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" "metadata" "Users/djsplice/OneDrive/Jukebox/House/Second.m4愠otrk" ) crate_path.write_bytes(crate_text.encode("utf-16-le")) crate = load_crate(crate_path) assert crate.path == crate_path assert [reference.filename for reference in crate.references] == [ "First.mp3", "Second.m4a", ] assert parse_crate(crate_path) == list(crate.references) 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") ) assert parse_crate(crate_path) == []