|
27 | 27 | TrackMatch, |
28 | 28 | correct_list_fields, |
29 | 29 | ) |
30 | | -from beets.autotag.match import assign_items |
31 | 30 | from beets.library import Item |
32 | 31 | from beets.test.helper import ConfigMixin |
33 | 32 |
|
34 | 33 |
|
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 | | - |
123 | 34 | class ApplyTest(TestCase): |
124 | 35 | def _apply(self, per_disc_numbering=False, artist_credit=False): |
125 | 36 | info = self.info |
|
0 commit comments