Debian Codegraph @

test/plugins/test_acousticbrainz.py

raw
1 """Tests for the 'acousticbrainz' plugin."""
2
3 import json
4
5 from beets.test._common import RSRC
6 from beetsplug.acousticbrainz import ABSCHEME, AcousticPlugin
7
8
9 class TestMapDataToScheme:
10 def test_basic(self):
11 ab = AcousticPlugin()
12 data = {"key 1": "value 1", "key 2": "value 2"}
13 scheme = {"key 1": "attribute 1", "key 2": "attribute 2"}
14 mapping = set(ab._map_data_to_scheme(data, scheme))
15 assert mapping == {
16 ("attribute 1", "value 1"),
17 ("attribute 2", "value 2"),
18 }
19
20 def test_recurse(self):
21 ab = AcousticPlugin()
22 data = {
23 "key": "value",
24 "group": {
25 "subkey": "subvalue",
26 "subgroup": {"subsubkey": "subsubvalue"},
27 },
28 }
29 scheme = {
30 "key": "attribute 1",
31 "group": {
32 "subkey": "attribute 2",
33 "subgroup": {"subsubkey": "attribute 3"},
34 },
35 }
36 mapping = set(ab._map_data_to_scheme(data, scheme))
37 assert mapping == {
38 ("attribute 1", "value"),
39 ("attribute 2", "subvalue"),
40 ("attribute 3", "subsubvalue"),
41 }
42
43 def test_composite(self):
44 ab = AcousticPlugin()
45 data = {"key 1": "part 1", "key 2": "part 2"}
46 scheme = {"key 1": ("attribute", 0), "key 2": ("attribute", 1)}
47 mapping = set(ab._map_data_to_scheme(data, scheme))
48 assert mapping == {("attribute", "part 1 part 2")}
49
50 def test_realistic(self):
51 ab = AcousticPlugin()
52 data_path = RSRC / "acousticbrainz/data.json"
53 data = json.loads(data_path.read_text())
54 mapping = set(ab._map_data_to_scheme(data, ABSCHEME))
55 expected = {
56 ("chords_key", "A"),
57 ("average_loudness", 0.815025985241),
58 ("mood_acoustic", 0.415711194277),
59 ("chords_changes_rate", 0.0445116683841),
60 ("tonal", 0.874250173569),
61 ("mood_sad", 0.299694597721),
62 ("bpm", 162.532119751),
63 ("gender", "female"),
64 ("initial_key", "A minor"),
65 ("chords_number_rate", 0.00194468453992),
66 ("mood_relaxed", 0.123632438481),
67 ("chords_scale", "minor"),
68 ("voice_instrumental", "instrumental"),
69 ("key_strength", 0.636936545372),
70 ("genre_rosamerica", "roc"),
71 ("mood_party", 0.234383180737),
72 ("mood_aggressive", 0.0779221653938),
73 ("danceable", 0.143928021193),
74 ("rhythm", "VienneseWaltz"),
75 ("mood_electronic", 0.339881360531),
76 ("mood_happy", 0.0894767045975),
77 ("moods_mirex", "Cluster3"),
78 ("timbre", "bright"),
79 }
80 assert mapping == expected