mirror of
https://github.com/beetbox/beets.git
synced 2026-03-27 07:43:38 +01:00
fix(smartplaylist): Resolve mypy type errors and update tests
This commit is contained in:
parent
b9de8f9aab
commit
002a051d06
2 changed files with 16 additions and 15 deletions
|
|
@ -57,8 +57,8 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
)
|
||||
|
||||
self.config["prefix"].redact = True # May contain username/password.
|
||||
self._matched_playlists = None
|
||||
self._unmatched_playlists = None
|
||||
self._matched_playlists: set[tuple[Any, Any, Any]] = set()
|
||||
self._unmatched_playlists: set[tuple[Any, Any, Any]] = set()
|
||||
|
||||
if self.config["auto"]:
|
||||
self.register_listener("database_change", self.db_change)
|
||||
|
|
@ -129,15 +129,15 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
def update_cmd(self, lib: Any, opts: Any, args: list[str]) -> None:
|
||||
self.build_queries()
|
||||
if args:
|
||||
args = set(args)
|
||||
for a in list(args):
|
||||
args_set = set(args)
|
||||
for a in list(args_set):
|
||||
if not a.endswith(".m3u"):
|
||||
args.add(f"{a}.m3u")
|
||||
args_set.add(f"{a}.m3u")
|
||||
|
||||
playlists = {
|
||||
(name, q, a_q)
|
||||
for name, q, a_q in self._unmatched_playlists
|
||||
if name in args
|
||||
if name in args_set
|
||||
}
|
||||
if not playlists:
|
||||
unmatched = [name for name, _, _ in self._unmatched_playlists]
|
||||
|
|
@ -185,6 +185,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
try:
|
||||
for key, model_cls in (("query", Item), ("album_query", Album)):
|
||||
qs = playlist.get(key)
|
||||
query_and_sort: tuple[Any, Any]
|
||||
if qs is None:
|
||||
query_and_sort = None, None
|
||||
elif isinstance(qs, str):
|
||||
|
|
@ -353,7 +354,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
|
|||
)
|
||||
f.write(comment.encode("utf-8") + entry.uri + b"\n")
|
||||
# Send an event when playlists were updated.
|
||||
send_event("smartplaylist_update")
|
||||
send_event("smartplaylist_update") # type: ignore
|
||||
|
||||
if pretend:
|
||||
self._log.info(
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ from beetsplug.smartplaylist import SmartPlaylistPlugin
|
|||
class SmartPlaylistTest(BeetsTestCase):
|
||||
def test_build_queries(self):
|
||||
spl = SmartPlaylistPlugin()
|
||||
assert spl._matched_playlists is None
|
||||
assert spl._unmatched_playlists is None
|
||||
assert spl._matched_playlists == set()
|
||||
assert spl._unmatched_playlists == set()
|
||||
|
||||
config["smartplaylist"]["playlists"].set([])
|
||||
spl.build_queries()
|
||||
|
|
@ -182,7 +182,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
q = Mock()
|
||||
a_q = Mock()
|
||||
pl = b"$title-my<playlist>.m3u", (q, None), (a_q, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
config["smartplaylist"]["relative_to"] = False
|
||||
|
|
@ -224,7 +224,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
q = Mock()
|
||||
a_q = Mock()
|
||||
pl = b"$title-my<playlist>.m3u", (q, None), (a_q, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
config["smartplaylist"]["output"] = "extm3u"
|
||||
|
|
@ -274,7 +274,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
q = Mock()
|
||||
a_q = Mock()
|
||||
pl = b"$title-my<playlist>.m3u", (q, None), (a_q, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
config["smartplaylist"]["output"] = "extm3u"
|
||||
|
|
@ -319,7 +319,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
q = Mock()
|
||||
a_q = Mock()
|
||||
pl = b"$title-my<playlist>.m3u", (q, None), (a_q, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
tpl = "http://beets:8337/item/$id/file"
|
||||
|
|
@ -380,7 +380,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
# Create playlist with multiple queries (stored as tuple)
|
||||
queries_and_sorts = ((q1, None), (q2, None), (q3, None))
|
||||
pl = "ordered.m3u", (queries_and_sorts, None), (None, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
config["smartplaylist"]["relative_to"] = False
|
||||
|
|
@ -435,7 +435,7 @@ class SmartPlaylistTest(BeetsTestCase):
|
|||
# Create playlist with multiple queries (stored as tuple)
|
||||
queries_and_sorts = ((q1, None), (q2, None))
|
||||
pl = "dedup.m3u", (queries_and_sorts, None), (None, None)
|
||||
spl._matched_playlists = [pl]
|
||||
spl._matched_playlists = {pl}
|
||||
|
||||
dir = mkdtemp()
|
||||
config["smartplaylist"]["relative_to"] = False
|
||||
|
|
|
|||
Loading…
Reference in a new issue