|
26 | 26 | from beets import util
|
27 | 27 | from beets.library import Item
|
28 | 28 | from beets.test import _common
|
29 |
| -from beets.test.helper import BeetsTestCase |
30 |
| -from beets.util import plurality |
31 | 29 |
|
32 | 30 |
|
33 | 31 | class UtilTest(unittest.TestCase):
|
@@ -222,80 +220,39 @@ def test_replacements(
|
222 | 220 | )
|
223 | 221 |
|
224 | 222 |
|
225 |
| -class PluralityTest(BeetsTestCase): |
226 |
| - def test_plurality_consensus(self): |
227 |
| - objs = [1, 1, 1, 1] |
228 |
| - obj, freq = plurality(objs) |
229 |
| - assert obj == 1 |
230 |
| - assert freq == 4 |
231 |
| - |
232 |
| - def test_plurality_near_consensus(self): |
233 |
| - objs = [1, 1, 2, 1] |
234 |
| - obj, freq = plurality(objs) |
235 |
| - assert obj == 1 |
236 |
| - assert freq == 3 |
237 |
| - |
238 |
| - def test_plurality_conflict(self): |
239 |
| - objs = [1, 1, 2, 2, 3] |
240 |
| - obj, freq = plurality(objs) |
241 |
| - assert obj in (1, 2) |
242 |
| - assert freq == 2 |
| 223 | +class TestPlurality: |
| 224 | + @pytest.mark.parametrize( |
| 225 | + "objs, expected_obj, expected_freq", |
| 226 | + [ |
| 227 | + pytest.param([1, 1, 1, 1], 1, 4, id="consensus"), |
| 228 | + pytest.param([1, 1, 2, 1], 1, 3, id="near consensus"), |
| 229 | + pytest.param([1, 1, 2, 2, 3], 1, 2, id="conflict-first-wins"), |
| 230 | + ], |
| 231 | + ) |
| 232 | + def test_plurality(self, objs, expected_obj, expected_freq): |
| 233 | + assert (expected_obj, expected_freq) == util.plurality(objs) |
243 | 234 |
|
244 |
| - def test_plurality_empty_sequence_raises_error(self): |
| 235 | + def test_empty_sequence_raises_error(self): |
245 | 236 | with pytest.raises(ValueError, match="must be non-empty"):
|
246 |
| - plurality([]) |
| 237 | + util.plurality([]) |
247 | 238 |
|
248 |
| - def test_current_metadata_finds_pluralities(self): |
| 239 | + def test_get_most_common_tags(self): |
249 | 240 | items = [
|
250 |
| - Item(artist="The Beetles", album="The White Album"), |
251 |
| - Item(artist="The Beatles", album="The White Album"), |
252 |
| - Item(artist="The Beatles", album="Teh White Album"), |
| 241 | + Item(albumartist="aartist", label="label 1", album="album"), |
| 242 | + Item(albumartist="aartist", label="label 2", album="album"), |
| 243 | + Item(albumartist="aartist", label="label 3", album="another album"), |
253 | 244 | ]
|
254 |
| - likelies, consensus = util.get_most_common_tags(items) |
255 |
| - assert likelies["artist"] == "The Beatles" |
256 |
| - assert likelies["album"] == "The White Album" |
257 |
| - assert not consensus["artist"] |
258 | 245 |
|
259 |
| - def test_current_metadata_artist_consensus(self): |
260 |
| - items = [ |
261 |
| - Item(artist="The Beatles", album="The White Album"), |
262 |
| - Item(artist="The Beatles", album="The White Album"), |
263 |
| - Item(artist="The Beatles", album="Teh White Album"), |
264 |
| - ] |
265 | 246 | likelies, consensus = util.get_most_common_tags(items)
|
266 |
| - assert likelies["artist"] == "The Beatles" |
267 |
| - assert likelies["album"] == "The White Album" |
268 |
| - assert consensus["artist"] |
269 | 247 |
|
270 |
| - def test_albumartist_consensus(self): |
271 |
| - items = [ |
272 |
| - Item(artist="tartist1", album="album", albumartist="aartist"), |
273 |
| - Item(artist="tartist2", album="album", albumartist="aartist"), |
274 |
| - Item(artist="tartist3", album="album", albumartist="aartist"), |
275 |
| - ] |
276 |
| - likelies, consensus = util.get_most_common_tags(items) |
| 248 | + assert likelies["albumartist"] == "aartist" |
| 249 | + assert likelies["album"] == "album" |
| 250 | + # albumartist consensus overrides artist |
277 | 251 | assert likelies["artist"] == "aartist"
|
278 |
| - assert not consensus["artist"] |
279 |
| - |
280 |
| - def test_current_metadata_likelies(self): |
281 |
| - fields = [ |
282 |
| - "artist", |
283 |
| - "album", |
284 |
| - "albumartist", |
285 |
| - "year", |
286 |
| - "disctotal", |
287 |
| - "mb_albumid", |
288 |
| - "label", |
289 |
| - "barcode", |
290 |
| - "catalognum", |
291 |
| - "country", |
292 |
| - "media", |
293 |
| - "albumdisambig", |
294 |
| - ] |
295 |
| - items = [Item(**{f: f"{f}_{i or 1}" for f in fields}) for i in range(5)] |
296 |
| - likelies, _ = util.get_most_common_tags(items) |
297 |
| - for f in fields: |
298 |
| - if isinstance(likelies[f], int): |
299 |
| - assert likelies[f] == 0 |
300 |
| - else: |
301 |
| - assert likelies[f] == f"{f}_1" |
| 252 | + assert likelies["label"] == "label 1" |
| 253 | + assert likelies["year"] == 0 |
| 254 | + |
| 255 | + assert consensus["year"] |
| 256 | + assert consensus["albumartist"] |
| 257 | + assert not consensus["album"] |
| 258 | + assert not consensus["label"] |
0 commit comments