Debian Codegraph @

test/plugins/test_albumtypes.py

raw
1 """Tests for the 'albumtypes' plugin."""
2
3 from __future__ import annotations
4
5 from typing import TYPE_CHECKING
6
7 from beets.test.helper import PluginTestCase
8 from beetsplug.albumtypes import AlbumTypesPlugin
9 from beetsplug.musicbrainz import VARIOUS_ARTISTS_ID
10
11 if TYPE_CHECKING:
12 from collections.abc import Sequence
13
14
15 class AlbumTypesPluginTest(PluginTestCase):
16 """Tests for albumtypes plugin."""
17
18 plugin = "albumtypes"
19
20 def test_renames_types(self):
21 """Tests if the plugin correctly renames the specified types."""
22 self._set_config(
23 types=[("ep", "EP"), ("remix", "Remix")], ignore_va=[], bracket="()"
24 )
25 album = self._create_album(album_types=["ep", "remix"])
26 subject = AlbumTypesPlugin()
27 result = subject._atypes(album)
28 assert "(EP)(Remix)" == result
29 return
30
31 def test_returns_only_specified_types(self):
32 """Tests if the plugin returns only non-blank types given in config."""
33 self._set_config(
34 types=[("ep", "EP"), ("soundtrack", "")], ignore_va=[], bracket="()"
35 )
36 album = self._create_album(album_types=["ep", "remix", "soundtrack"])
37 subject = AlbumTypesPlugin()
38 result = subject._atypes(album)
39 assert "(EP)" == result
40
41 def test_respects_type_order(self):
42 """Tests if the types are returned in the same order as config."""
43 self._set_config(
44 types=[("remix", "Remix"), ("ep", "EP")], ignore_va=[], bracket="()"
45 )
46 album = self._create_album(album_types=["ep", "remix"])
47 subject = AlbumTypesPlugin()
48 result = subject._atypes(album)
49 assert "(Remix)(EP)" == result
50 return
51
52 def test_ignores_va(self):
53 """Tests if the specified type is ignored for VA albums."""
54 self._set_config(
55 types=[("ep", "EP"), ("soundtrack", "OST")],
56 ignore_va=["ep"],
57 bracket="()",
58 )
59 album = self._create_album(
60 album_types=["ep", "soundtrack"], artist_id=VARIOUS_ARTISTS_ID
61 )
62 subject = AlbumTypesPlugin()
63 result = subject._atypes(album)
64 assert "(OST)" == result
65
66 def test_respects_defaults(self):
67 """Tests if the plugin uses the default values if config not given."""
68 album = self._create_album(
69 album_types=[
70 "ep",
71 "single",
72 "soundtrack",
73 "live",
74 "compilation",
75 "remix",
76 ],
77 artist_id=VARIOUS_ARTISTS_ID,
78 )
79 subject = AlbumTypesPlugin()
80 result = subject._atypes(album)
81 assert "[EP][Single][OST][Live][Remix]" == result
82
83 def _set_config(
84 self,
85 types: Sequence[tuple[str, str]],
86 ignore_va: Sequence[str],
87 bracket: str,
88 ):
89 self.config["albumtypes"]["types"] = types
90 self.config["albumtypes"]["ignore_va"] = ignore_va
91 self.config["albumtypes"]["bracket"] = bracket
92
93 def _create_album(self, album_types: Sequence[str], artist_id: str = "0"):
94 return self.add_album(
95 albumtypes=album_types, mb_albumartistid=artist_id
96 )