Skip to content

Commit d544409

Browse files
committed
test(SimpleDjIA): cover library loading
1 parent 31ede2d commit d544409

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎SimpleDjIA/tests/test_library.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
3+
from simple_djia.library import load_library
4+
5+
6+
def test_load_library_resolves_relative_paths(tmp_path):
7+
data = [{
8+
"path": "music/a.ogg",
9+
"title": "A",
10+
"artist": "Artist",
11+
"bpm": 90,
12+
"energy": 0.4,
13+
"valence": 0.5,
14+
"acousticness": 0.6,
15+
"danceability": 0.3,
16+
"vocal_presence": 0.1,
17+
"familiarity": 0.4,
18+
"tags": ["piano"]
19+
}]
20+
source = tmp_path / "library.json"
21+
source.write_text(json.dumps(data), encoding="utf-8")
22+
tracks = load_library(source)
23+
assert tracks[0].path == (tmp_path / "music/a.ogg").resolve()
24+
assert tracks[0].tags == ("piano",)
25+
26+
27+
def test_library_must_be_list(tmp_path):
28+
source = tmp_path / "library.json"
29+
source.write_text("{}", encoding="utf-8")
30+
try:
31+
load_library(source)
32+
except ValueError as exc:
33+
assert "list" in str(exc)
34+
else:
35+
raise AssertionError("expected ValueError")

0 commit comments

Comments
 (0)