Fix and expand tests: 63 tests passing, covers all core modules
Remove tests/ from .gitignore (was accidentally excluded). - test_ripper.py: rewrite for current API (_parse_cddb_lines, _extract_tracks, _rename_files, _clean_input); fix default quality - test_organizer.py: update filename assertions (spaces→underscores); add TestSanitizeFilename, TestCheckDiscCounts, in-place mode - test_playlist.py: fix dummy filenames to underscore scheme; add multi-disc, filename sanitization, EXTINF and fallback tests Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
734bc80b79
commit
775f274d02
7 changed files with 637 additions and 1 deletions
98
tests/test_playlist.py
Normal file
98
tests/test_playlist.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
"""Tests für die Playlist-Generierung."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from musiksammlung.models import Album, Disc, Track
|
||||
from musiksammlung.playlist import generate_playlist
|
||||
|
||||
|
||||
def _make_album(n_tracks: int = 2, n_discs: int = 1) -> Album:
|
||||
discs = [
|
||||
Disc(
|
||||
disc_number=d,
|
||||
tracks=[Track(track_number=i, title=f"Disc{d} Song {i}") for i in range(1, n_tracks + 1)],
|
||||
)
|
||||
for d in range(1, n_discs + 1)
|
||||
]
|
||||
return Album(artist="Artist", album="TestAlbum", year=2000, discs=discs)
|
||||
|
||||
|
||||
def test_generate_playlist_single_disc(tmp_path: Path):
|
||||
"""M3U für Single-CD: keine CD-Prefix, korrekte Dateinamen."""
|
||||
album = _make_album(n_tracks=2, n_discs=1)
|
||||
|
||||
# Dummy-Audiodateien im neuen Unterstrich-Schema
|
||||
(tmp_path / "01_Disc1_Song_1.flac").touch()
|
||||
(tmp_path / "02_Disc1_Song_2.flac").touch()
|
||||
|
||||
playlist_path = generate_playlist(album, tmp_path)
|
||||
assert playlist_path.exists()
|
||||
|
||||
content = playlist_path.read_text()
|
||||
assert "#EXTM3U" in content
|
||||
assert "01_Disc1_Song_1.flac" in content
|
||||
assert "02_Disc1_Song_2.flac" in content
|
||||
# Kein CD-Prefix bei Single-Disc
|
||||
assert "CD1/" not in content
|
||||
|
||||
|
||||
def test_generate_playlist_multi_disc(tmp_path: Path):
|
||||
"""M3U für Multi-CD: CD-Prefix in Pfaden."""
|
||||
album = _make_album(n_tracks=2, n_discs=2)
|
||||
|
||||
cd1 = tmp_path / "CD1"
|
||||
cd2 = tmp_path / "CD2"
|
||||
cd1.mkdir()
|
||||
cd2.mkdir()
|
||||
(cd1 / "01_Disc1_Song_1.flac").touch()
|
||||
(cd1 / "02_Disc1_Song_2.flac").touch()
|
||||
(cd2 / "01_Disc2_Song_1.flac").touch()
|
||||
(cd2 / "02_Disc2_Song_2.flac").touch()
|
||||
|
||||
playlist_path = generate_playlist(album, tmp_path)
|
||||
content = playlist_path.read_text()
|
||||
|
||||
assert "CD1/01_Disc1_Song_1.flac" in content
|
||||
assert "CD2/01_Disc2_Song_1.flac" in content
|
||||
|
||||
|
||||
def test_generate_playlist_filename(tmp_path: Path):
|
||||
"""Playlist-Dateiname ist sanitierter Albumname."""
|
||||
album = Album(
|
||||
artist="A",
|
||||
album="Mein Album",
|
||||
discs=[Disc(disc_number=1, tracks=[Track(track_number=1, title="Song")])],
|
||||
)
|
||||
playlist_path = generate_playlist(album, tmp_path)
|
||||
assert playlist_path.name == "Mein_Album.m3u"
|
||||
|
||||
|
||||
def test_generate_playlist_extinf_contains_title(tmp_path: Path):
|
||||
"""#EXTINF-Einträge enthalten den originalen Titel."""
|
||||
album = Album(
|
||||
artist="A",
|
||||
album="X",
|
||||
discs=[
|
||||
Disc(
|
||||
disc_number=1,
|
||||
tracks=[Track(track_number=1, title="Für Elise")],
|
||||
)
|
||||
],
|
||||
)
|
||||
(tmp_path / "01_Für_Elise.flac").touch()
|
||||
playlist_path = generate_playlist(album, tmp_path)
|
||||
content = playlist_path.read_text()
|
||||
assert "#EXTINF:0,Für Elise" in content
|
||||
|
||||
|
||||
def test_generate_playlist_fallback_if_file_missing(tmp_path: Path):
|
||||
"""Wenn Audiodatei fehlt, wird Fallback-Name erzeugt (kein Absturz)."""
|
||||
album = Album(
|
||||
artist="A",
|
||||
album="X",
|
||||
discs=[Disc(disc_number=1, tracks=[Track(track_number=1, title="Ghost")])],
|
||||
)
|
||||
# Keine Audiodatei anlegen
|
||||
playlist_path = generate_playlist(album, tmp_path)
|
||||
content = playlist_path.read_text()
|
||||
assert "01_Ghost.flac" in content
|
||||
Loading…
Add table
Add a link
Reference in a new issue