_resolve_genre as list tests, add test_to_delimited_string

- Adapt tests to _resolve_genres returning a list with not yet formatted genres.
- Rename and adapt test_count -> test_to_delimited_string. Note that the
  new function does not apply whitelist, prefer anything. It just cuts
  to count and formats!
This commit is contained in:
J0J0 Todos 2025-01-06 11:23:01 +01:00
parent 13ae699230
commit 6cd000750a

View file

@ -46,46 +46,49 @@ class LastGenrePluginTest(BeetsTestCase):
def test_default(self):
"""Fetch genres with whitelist and c14n deactivated"""
self._setup_config()
assert self.plugin._resolve_genres(["delta blues"]) == "Delta Blues"
assert self.plugin._resolve_genres(["delta blues"]) == ["delta blues"]
def test_c14n_only(self):
"""Default c14n tree funnels up to most common genre except for *wrong*
genres that stay unchanged.
"""
self._setup_config(canonical=True, count=99)
assert self.plugin._resolve_genres(["delta blues"]) == "Blues"
assert self.plugin._resolve_genres(["iota blues"]) == "Iota Blues"
assert self.plugin._resolve_genres(["delta blues"]) == ["blues"]
assert self.plugin._resolve_genres(["iota blues"]) == ["iota blues"]
def test_whitelist_only(self):
"""Default whitelist rejects *wrong* (non existing) genres."""
self._setup_config(whitelist=True)
assert self.plugin._resolve_genres(["iota blues"]) == ""
assert self.plugin._resolve_genres(["iota blues"]) == []
def test_whitelist_c14n(self):
"""Default whitelist and c14n both activated result in all parents
genres being selected (from specific to common).
"""
self._setup_config(canonical=True, whitelist=True, count=99)
assert (
self.plugin._resolve_genres(["delta blues"]) == "Delta Blues, Blues"
)
assert self.plugin._resolve_genres(["delta blues"]) == [
"delta blues",
"blues",
]
def test_whitelist_custom(self):
"""Keep only genres that are in the whitelist."""
self._setup_config(whitelist={"blues", "rock", "jazz"}, count=2)
assert self.plugin._resolve_genres(["pop", "blues"]) == "Blues"
assert self.plugin._resolve_genres(["pop", "blues"]) == ["blues"]
self._setup_config(canonical="", whitelist={"rock"})
assert self.plugin._resolve_genres(["delta blues"]) == ""
assert self.plugin._resolve_genres(["delta blues"]) == []
def test_count(self):
"""Keep the n first genres, as we expect them to be sorted from more to
less popular.
def test_to_delimited_string(self):
"""Keep the n first genres, format them and return a
separator-delimited string.
"""
self._setup_config(whitelist={"blues", "rock", "jazz"}, count=2)
self._setup_config(count=2)
assert (
self.plugin._resolve_genres(["jazz", "pop", "rock", "blues"])
== "Jazz, Rock"
self.plugin._to_delimited_genre_string(
["jazz", "pop", "rock", "blues"]
)
== "Jazz, Pop"
)
def test_count_c14n(self):
@ -95,31 +98,28 @@ class LastGenrePluginTest(BeetsTestCase):
)
# thanks to c14n, 'blues' superseeds 'country blues' and takes the
# second slot
assert (
self.plugin._resolve_genres(
["jazz", "pop", "country blues", "rock"]
)
== "Jazz, Blues"
)
assert self.plugin._resolve_genres(
["jazz", "pop", "country blues", "rock"]
) == ["jazz", "blues"]
def test_c14n_whitelist(self):
"""Genres first pass through c14n and are then filtered"""
self._setup_config(canonical=True, whitelist={"rock"})
assert self.plugin._resolve_genres(["delta blues"]) == ""
assert self.plugin._resolve_genres(["delta blues"]) == []
def test_empty_string_enables_canonical(self):
"""For backwards compatibility, setting the `canonical` option
to the empty string enables it using the default tree.
"""
self._setup_config(canonical="", count=99)
assert self.plugin._resolve_genres(["delta blues"]) == "Blues"
assert self.plugin._resolve_genres(["delta blues"]) == ["blues"]
def test_empty_string_enables_whitelist(self):
"""Again for backwards compatibility, setting the `whitelist`
option to the empty string enables the default set of genres.
"""
self._setup_config(whitelist="")
assert self.plugin._resolve_genres(["iota blues"]) == ""
assert self.plugin._resolve_genres(["iota blues"]) == []
def test_prefer_specific_loads_tree(self):
"""When prefer_specific is enabled but canonical is not the
@ -131,15 +131,15 @@ class LastGenrePluginTest(BeetsTestCase):
def test_prefer_specific_without_canonical(self):
"""Prefer_specific works without canonical."""
self._setup_config(prefer_specific=True, canonical=False, count=4)
assert (
self.plugin._resolve_genres(["math rock", "post-rock"])
== "Post-Rock, Math Rock"
)
assert self.plugin._resolve_genres(["math rock", "post-rock"]) == [
"post-rock",
"math rock",
]
def test_no_duplicate(self):
"""Remove duplicated genres."""
self._setup_config(count=99)
assert self.plugin._resolve_genres(["blues", "blues"]) == "Blues"
assert self.plugin._resolve_genres(["blues", "blues"]) == ["blues"]
def test_tags_for(self):
class MockPylastElem: