51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
from serato_doctor.scanner import scan_audio, scan_filesystem
|
|
|
|
|
|
def test_scan_audio_finds_supported_files(tmp_path):
|
|
music = tmp_path / "music"
|
|
nested = music / "House"
|
|
nested.mkdir(parents=True)
|
|
(nested / "First.MP3").write_bytes(b"synthetic audio")
|
|
(nested / "Second.flac").write_bytes(b"fixture")
|
|
(nested / "notes.txt").write_text("not audio", encoding="utf-8")
|
|
|
|
tracks = scan_audio(music)
|
|
|
|
assert {track.filename for track in tracks} == {"First.MP3", "Second.flac"}
|
|
first = next(track for track in tracks if track.filename == "First.MP3")
|
|
assert first.suffix == ".mp3"
|
|
assert first.size == len(b"synthetic audio")
|
|
|
|
|
|
def test_scan_filesystem_reports_broken_symlink(tmp_path):
|
|
music = tmp_path / "music"
|
|
music.mkdir()
|
|
link = music / "Missing.mp3"
|
|
link.symlink_to("not-there.mp3")
|
|
|
|
result = scan_filesystem(music)
|
|
|
|
assert result.tracks == ()
|
|
assert len(result.broken_symlinks) == 1
|
|
assert result.broken_symlinks[0].path == link
|
|
assert result.broken_symlinks[0].target == Path("not-there.mp3")
|
|
|
|
|
|
def test_valid_audio_symlink_is_scanned_normally(tmp_path):
|
|
music = tmp_path / "music"
|
|
music.mkdir()
|
|
target = music / "Target.mp3"
|
|
target.write_bytes(b"synthetic audio")
|
|
link = music / "Linked.mp3"
|
|
link.symlink_to(target)
|
|
|
|
result = scan_filesystem(music)
|
|
|
|
assert {track.filename for track in result.tracks} == {
|
|
"Linked.mp3",
|
|
"Target.mp3",
|
|
}
|
|
assert result.broken_symlinks == ()
|