Skip to content

Commit 1cca6b5

Browse files
committed
autotag: split tests into test_match.py and test_hooks.py
1 parent 44c3213 commit 1cca6b5

File tree

2 files changed

+94
-89
lines changed

2 files changed

+94
-89
lines changed

test/test_autotag.py renamed to test/autotag/test_hooks.py

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -27,99 +27,10 @@
2727
TrackMatch,
2828
correct_list_fields,
2929
)
30-
from beets.autotag.match import assign_items
3130
from beets.library import Item
3231
from beets.test.helper import ConfigMixin
3332

3433

35-
class TestAssignment(ConfigMixin):
36-
A = "one"
37-
B = "two"
38-
C = "three"
39-
40-
@pytest.fixture(scope="class", autouse=True)
41-
def _setup_config(self):
42-
self.config["match"]["track_length_grace"] = 10
43-
self.config["match"]["track_length_max"] = 30
44-
45-
@pytest.mark.parametrize(
46-
# 'expected' is a tuple of expected (mapping, extra_items, extra_tracks)
47-
"item_titles, track_titles, expected",
48-
[
49-
# items ordering gets corrected
50-
([A, C, B], [A, B, C], ({A: A, B: B, C: C}, [], [])),
51-
# unmatched tracks are returned as 'extra_tracks'
52-
# the first track is unmatched
53-
([B, C], [A, B, C], ({B: B, C: C}, [], [A])),
54-
# the middle track is unmatched
55-
([A, C], [A, B, C], ({A: A, C: C}, [], [B])),
56-
# the last track is unmatched
57-
([A, B], [A, B, C], ({A: A, B: B}, [], [C])),
58-
# unmatched items are returned as 'extra_items'
59-
([A, C, B], [A, C], ({A: A, C: C}, [B], [])),
60-
],
61-
)
62-
def test_assign_tracks(self, item_titles, track_titles, expected):
63-
expected_mapping, expected_extra_items, expected_extra_tracks = expected
64-
65-
items = [Item(title=title) for title in item_titles]
66-
tracks = [TrackInfo(title=title) for title in track_titles]
67-
68-
item_info_pairs, extra_items, extra_tracks = assign_items(items, tracks)
69-
70-
assert (
71-
{i.title: t.title for i, t in item_info_pairs},
72-
[i.title for i in extra_items],
73-
[t.title for t in extra_tracks],
74-
) == (expected_mapping, expected_extra_items, expected_extra_tracks)
75-
76-
def test_order_works_when_track_names_are_entirely_wrong(self):
77-
# A real-world test case contributed by a user.
78-
def item(i, length):
79-
return Item(
80-
artist="ben harper",
81-
album="burn to shine",
82-
title=f"ben harper - Burn to Shine {i}",
83-
track=i,
84-
length=length,
85-
)
86-
87-
items = []
88-
items.append(item(1, 241.37243007106997))
89-
items.append(item(2, 342.27781704375036))
90-
items.append(item(3, 245.95070222338137))
91-
items.append(item(4, 472.87662515485437))
92-
items.append(item(5, 279.1759535763187))
93-
items.append(item(6, 270.33333768012))
94-
items.append(item(7, 247.83435613222923))
95-
items.append(item(8, 216.54504531525072))
96-
items.append(item(9, 225.72775379800484))
97-
items.append(item(10, 317.7643606963552))
98-
items.append(item(11, 243.57001238834192))
99-
items.append(item(12, 186.45916150485752))
100-
101-
def info(index, title, length):
102-
return TrackInfo(title=title, length=length, index=index)
103-
104-
trackinfo = []
105-
trackinfo.append(info(1, "Alone", 238.893))
106-
trackinfo.append(info(2, "The Woman in You", 341.44))
107-
trackinfo.append(info(3, "Less", 245.59999999999999))
108-
trackinfo.append(info(4, "Two Hands of a Prayer", 470.49299999999999))
109-
trackinfo.append(info(5, "Please Bleed", 277.86599999999999))
110-
trackinfo.append(info(6, "Suzie Blue", 269.30599999999998))
111-
trackinfo.append(info(7, "Steal My Kisses", 245.36000000000001))
112-
trackinfo.append(info(8, "Burn to Shine", 214.90600000000001))
113-
trackinfo.append(info(9, "Show Me a Little Shame", 224.0929999999999))
114-
trackinfo.append(info(10, "Forgiven", 317.19999999999999))
115-
trackinfo.append(info(11, "Beloved One", 243.733))
116-
trackinfo.append(info(12, "In the Lord's Arms", 186.13300000000001))
117-
118-
expected = list(zip(items, trackinfo)), [], []
119-
120-
assert assign_items(items, trackinfo) == expected
121-
122-
12334
class ApplyTest(TestCase):
12435
def _apply(self, per_disc_numbering=False, artist_credit=False):
12536
info = self.info

test/autotag/test_match.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import pytest
2+
3+
from beets.autotag.hooks import TrackInfo
4+
from beets.autotag.match import assign_items
5+
from beets.library import Item
6+
from beets.test.helper import ConfigMixin
7+
8+
9+
class TestAssignment(ConfigMixin):
10+
A = "one"
11+
B = "two"
12+
C = "three"
13+
14+
@pytest.fixture(scope="class", autouse=True)
15+
def _setup_config(self):
16+
self.config["match"]["track_length_grace"] = 10
17+
self.config["match"]["track_length_max"] = 30
18+
19+
@pytest.mark.parametrize(
20+
# 'expected' is a tuple of expected (mapping, extra_items, extra_tracks)
21+
"item_titles, track_titles, expected",
22+
[
23+
# items ordering gets corrected
24+
([A, C, B], [A, B, C], ({A: A, B: B, C: C}, [], [])),
25+
# unmatched tracks are returned as 'extra_tracks'
26+
# the first track is unmatched
27+
([B, C], [A, B, C], ({B: B, C: C}, [], [A])),
28+
# the middle track is unmatched
29+
([A, C], [A, B, C], ({A: A, C: C}, [], [B])),
30+
# the last track is unmatched
31+
([A, B], [A, B, C], ({A: A, B: B}, [], [C])),
32+
# unmatched items are returned as 'extra_items'
33+
([A, C, B], [A, C], ({A: A, C: C}, [B], [])),
34+
],
35+
)
36+
def test_assign_tracks(self, item_titles, track_titles, expected):
37+
expected_mapping, expected_extra_items, expected_extra_tracks = expected
38+
39+
items = [Item(title=title) for title in item_titles]
40+
tracks = [TrackInfo(title=title) for title in track_titles]
41+
42+
item_info_pairs, extra_items, extra_tracks = assign_items(items, tracks)
43+
44+
assert (
45+
{i.title: t.title for i, t in item_info_pairs},
46+
[i.title for i in extra_items],
47+
[t.title for t in extra_tracks],
48+
) == (expected_mapping, expected_extra_items, expected_extra_tracks)
49+
50+
def test_order_works_when_track_names_are_entirely_wrong(self):
51+
# A real-world test case contributed by a user.
52+
def item(i, length):
53+
return Item(
54+
artist="ben harper",
55+
album="burn to shine",
56+
title=f"ben harper - Burn to Shine {i}",
57+
track=i,
58+
length=length,
59+
)
60+
61+
items = []
62+
items.append(item(1, 241.37243007106997))
63+
items.append(item(2, 342.27781704375036))
64+
items.append(item(3, 245.95070222338137))
65+
items.append(item(4, 472.87662515485437))
66+
items.append(item(5, 279.1759535763187))
67+
items.append(item(6, 270.33333768012))
68+
items.append(item(7, 247.83435613222923))
69+
items.append(item(8, 216.54504531525072))
70+
items.append(item(9, 225.72775379800484))
71+
items.append(item(10, 317.7643606963552))
72+
items.append(item(11, 243.57001238834192))
73+
items.append(item(12, 186.45916150485752))
74+
75+
def info(index, title, length):
76+
return TrackInfo(title=title, length=length, index=index)
77+
78+
trackinfo = []
79+
trackinfo.append(info(1, "Alone", 238.893))
80+
trackinfo.append(info(2, "The Woman in You", 341.44))
81+
trackinfo.append(info(3, "Less", 245.59999999999999))
82+
trackinfo.append(info(4, "Two Hands of a Prayer", 470.49299999999999))
83+
trackinfo.append(info(5, "Please Bleed", 277.86599999999999))
84+
trackinfo.append(info(6, "Suzie Blue", 269.30599999999998))
85+
trackinfo.append(info(7, "Steal My Kisses", 245.36000000000001))
86+
trackinfo.append(info(8, "Burn to Shine", 214.90600000000001))
87+
trackinfo.append(info(9, "Show Me a Little Shame", 224.0929999999999))
88+
trackinfo.append(info(10, "Forgiven", 317.19999999999999))
89+
trackinfo.append(info(11, "Beloved One", 243.733))
90+
trackinfo.append(info(12, "In the Lord's Arms", 186.13300000000001))
91+
92+
expected = list(zip(items, trackinfo)), [], []
93+
94+
assert assign_items(items, trackinfo) == expected

0 commit comments

Comments
 (0)