/
/
/
1"""Tests for the pure helper functions of the Metadata Controller."""
2
3import pytest
4
5from music_assistant.controllers.metadata.helpers import (
6 _detect_image_format,
7 _normalize_imageproxy_format,
8)
9
10
11class TestDetectImageFormat:
12 """`_detect_image_format` maps a path/extension to a served image format."""
13
14 @pytest.mark.parametrize(
15 ("path", "expected"),
16 [
17 ("cover.svg", "svg"),
18 ("cover.png", "png"),
19 ("cover.jpg", "jpg"),
20 ("cover.jpeg", "jpg"),
21 ("cover.webp", "jpg"),
22 ("noextension", "jpg"),
23 ("http://host/path/IMAGE.PNG", "png"),
24 ("http://host/path/art.png?cs=abc123", "png"),
25 ],
26 )
27 def test_detect(self, path: str, expected: str) -> None:
28 """The extension (after stripping any query suffix) drives the format."""
29 assert _detect_image_format(path) == expected
30
31
32class TestNormalizeImageproxyFormat:
33 """`_normalize_imageproxy_format` validates the client-supplied `fmt` value."""
34
35 @pytest.mark.parametrize("value", ["jpg", "JPG", " png ", "jpeg", "svg"])
36 def test_valid(self, value: str) -> None:
37 """Known formats normalize to their lowercase, trimmed form."""
38 assert _normalize_imageproxy_format(value) == value.strip().lower()
39
40 @pytest.mark.parametrize("value", [None, "", "gif", "bmp", "exe"])
41 def test_invalid(self, value: str | None) -> None:
42 """Unknown or empty formats return None."""
43 assert _normalize_imageproxy_format(value) is None
44