Skip to content

Commit

Permalink
_resolve_genre as list tests, add test_to_delimited_string
Browse files Browse the repository at this point in the history
- 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!
  • Loading branch information
JOJ0 committed Jan 8, 2025
1 parent f230be7 commit 375b4a1
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions test/plugins/test_lastgenre.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,49 @@ def _setup_config(
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):
Expand All @@ -99,27 +102,27 @@ def test_count_c14n(self):
self.plugin._resolve_genres(
["jazz", "pop", "country blues", "rock"]
)
== "Jazz, Blues"
== ["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
Expand All @@ -133,13 +136,13 @@ def test_prefer_specific_without_canonical(self):
self._setup_config(prefer_specific=True, canonical=False, count=4)
assert (
self.plugin._resolve_genres(["math rock", "post-rock"])
== "Post-Rock, Math 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:
Expand Down

0 comments on commit 375b4a1

Please sign in to comment.