mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Simplify and speed up plurality/album tags retrieval tests
This commit is contained in:
parent
1c9aebd36c
commit
01b6ea7898
1 changed files with 26 additions and 69 deletions
|
|
@ -26,8 +26,6 @@ import pytest
|
|||
from beets import util
|
||||
from beets.library import Item
|
||||
from beets.test import _common
|
||||
from beets.test.helper import BeetsTestCase
|
||||
from beets.util import plurality
|
||||
|
||||
|
||||
class UtilTest(unittest.TestCase):
|
||||
|
|
@ -222,80 +220,39 @@ class TestPathLegalization:
|
|||
)
|
||||
|
||||
|
||||
class PluralityTest(BeetsTestCase):
|
||||
def test_plurality_consensus(self):
|
||||
objs = [1, 1, 1, 1]
|
||||
obj, freq = plurality(objs)
|
||||
assert obj == 1
|
||||
assert freq == 4
|
||||
class TestPlurality:
|
||||
@pytest.mark.parametrize(
|
||||
"objs, expected_obj, expected_freq",
|
||||
[
|
||||
pytest.param([1, 1, 1, 1], 1, 4, id="consensus"),
|
||||
pytest.param([1, 1, 2, 1], 1, 3, id="near consensus"),
|
||||
pytest.param([1, 1, 2, 2, 3], 1, 2, id="conflict-first-wins"),
|
||||
],
|
||||
)
|
||||
def test_plurality(self, objs, expected_obj, expected_freq):
|
||||
assert (expected_obj, expected_freq) == util.plurality(objs)
|
||||
|
||||
def test_plurality_near_consensus(self):
|
||||
objs = [1, 1, 2, 1]
|
||||
obj, freq = plurality(objs)
|
||||
assert obj == 1
|
||||
assert freq == 3
|
||||
|
||||
def test_plurality_conflict(self):
|
||||
objs = [1, 1, 2, 2, 3]
|
||||
obj, freq = plurality(objs)
|
||||
assert obj in (1, 2)
|
||||
assert freq == 2
|
||||
|
||||
def test_plurality_empty_sequence_raises_error(self):
|
||||
def test_empty_sequence_raises_error(self):
|
||||
with pytest.raises(ValueError, match="must be non-empty"):
|
||||
plurality([])
|
||||
util.plurality([])
|
||||
|
||||
def test_current_metadata_finds_pluralities(self):
|
||||
def test_get_most_common_tags(self):
|
||||
items = [
|
||||
Item(artist="The Beetles", album="The White Album"),
|
||||
Item(artist="The Beatles", album="The White Album"),
|
||||
Item(artist="The Beatles", album="Teh White Album"),
|
||||
Item(albumartist="aartist", label="label 1", album="album"),
|
||||
Item(albumartist="aartist", label="label 2", album="album"),
|
||||
Item(albumartist="aartist", label="label 3", album="another album"),
|
||||
]
|
||||
likelies, consensus = util.get_most_common_tags(items)
|
||||
assert likelies["artist"] == "The Beatles"
|
||||
assert likelies["album"] == "The White Album"
|
||||
assert not consensus["artist"]
|
||||
|
||||
def test_current_metadata_artist_consensus(self):
|
||||
items = [
|
||||
Item(artist="The Beatles", album="The White Album"),
|
||||
Item(artist="The Beatles", album="The White Album"),
|
||||
Item(artist="The Beatles", album="Teh White Album"),
|
||||
]
|
||||
likelies, consensus = util.get_most_common_tags(items)
|
||||
assert likelies["artist"] == "The Beatles"
|
||||
assert likelies["album"] == "The White Album"
|
||||
assert consensus["artist"]
|
||||
|
||||
def test_albumartist_consensus(self):
|
||||
items = [
|
||||
Item(artist="tartist1", album="album", albumartist="aartist"),
|
||||
Item(artist="tartist2", album="album", albumartist="aartist"),
|
||||
Item(artist="tartist3", album="album", albumartist="aartist"),
|
||||
]
|
||||
likelies, consensus = util.get_most_common_tags(items)
|
||||
assert likelies["albumartist"] == "aartist"
|
||||
assert likelies["album"] == "album"
|
||||
# albumartist consensus overrides artist
|
||||
assert likelies["artist"] == "aartist"
|
||||
assert not consensus["artist"]
|
||||
assert likelies["label"] == "label 1"
|
||||
assert likelies["year"] == 0
|
||||
|
||||
def test_current_metadata_likelies(self):
|
||||
fields = [
|
||||
"artist",
|
||||
"album",
|
||||
"albumartist",
|
||||
"year",
|
||||
"disctotal",
|
||||
"mb_albumid",
|
||||
"label",
|
||||
"barcode",
|
||||
"catalognum",
|
||||
"country",
|
||||
"media",
|
||||
"albumdisambig",
|
||||
]
|
||||
items = [Item(**{f: f"{f}_{i or 1}" for f in fields}) for i in range(5)]
|
||||
likelies, _ = util.get_most_common_tags(items)
|
||||
for f in fields:
|
||||
if isinstance(likelies[f], int):
|
||||
assert likelies[f] == 0
|
||||
else:
|
||||
assert likelies[f] == f"{f}_1"
|
||||
assert consensus["year"]
|
||||
assert consensus["albumartist"]
|
||||
assert not consensus["album"]
|
||||
assert not consensus["label"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue