Skip to content

Commit 01b6ea7

Browse files
committed
Simplify and speed up plurality/album tags retrieval tests
1 parent 1c9aebd commit 01b6ea7

File tree

1 file changed

+27
-70
lines changed

1 file changed

+27
-70
lines changed

test/test_util.py

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
from beets import util
2727
from beets.library import Item
2828
from beets.test import _common
29-
from beets.test.helper import BeetsTestCase
30-
from beets.util import plurality
3129

3230

3331
class UtilTest(unittest.TestCase):
@@ -222,80 +220,39 @@ def test_replacements(
222220
)
223221

224222

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)
243234

244-
def test_plurality_empty_sequence_raises_error(self):
235+
def test_empty_sequence_raises_error(self):
245236
with pytest.raises(ValueError, match="must be non-empty"):
246-
plurality([])
237+
util.plurality([])
247238

248-
def test_current_metadata_finds_pluralities(self):
239+
def test_get_most_common_tags(self):
249240
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"),
253244
]
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"]
258245

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-
]
265246
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"]
269247

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
277251
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

Comments
 (0)