45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
|
|
"""Tests für Cover-Funktionen."""
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from musiksammlung.cover import find_cover
|
||
|
|
|
||
|
|
|
||
|
|
class TestFindCover:
|
||
|
|
"""Tests für find_cover."""
|
||
|
|
|
||
|
|
def test_finds_frontcover_jpg(self, tmp_path: Path) -> None:
|
||
|
|
(tmp_path / "frontcover.jpg").touch()
|
||
|
|
assert find_cover(tmp_path, "front") == tmp_path / "frontcover.jpg"
|
||
|
|
|
||
|
|
def test_finds_frontcover_png(self, tmp_path: Path) -> None:
|
||
|
|
(tmp_path / "frontcover.png").touch()
|
||
|
|
assert find_cover(tmp_path, "front") == tmp_path / "frontcover.png"
|
||
|
|
|
||
|
|
def test_jpg_preferred_over_png(self, tmp_path: Path) -> None:
|
||
|
|
(tmp_path / "frontcover.jpg").touch()
|
||
|
|
(tmp_path / "frontcover.png").touch()
|
||
|
|
# .jpg wird zuerst geprüft
|
||
|
|
assert find_cover(tmp_path, "front") == tmp_path / "frontcover.jpg"
|
||
|
|
|
||
|
|
def test_finds_backcover(self, tmp_path: Path) -> None:
|
||
|
|
(tmp_path / "backcover.jpg").touch()
|
||
|
|
assert find_cover(tmp_path, "back") == tmp_path / "backcover.jpg"
|
||
|
|
|
||
|
|
def test_returns_none_if_missing(self, tmp_path: Path) -> None:
|
||
|
|
assert find_cover(tmp_path, "front") is None
|
||
|
|
assert find_cover(tmp_path, "back") is None
|
||
|
|
|
||
|
|
def test_follows_symlink(self, tmp_path: Path) -> None:
|
||
|
|
real = tmp_path / "original.jpg"
|
||
|
|
real.touch()
|
||
|
|
link = tmp_path / "frontcover.jpg"
|
||
|
|
link.symlink_to(real)
|
||
|
|
assert find_cover(tmp_path, "front") == link
|
||
|
|
|
||
|
|
def test_ignores_wrong_names(self, tmp_path: Path) -> None:
|
||
|
|
(tmp_path / "cover.jpg").touch()
|
||
|
|
(tmp_path / "back.jpg").touch()
|
||
|
|
assert find_cover(tmp_path, "front") is None
|