Skip to content

Commit 3d0414c

Browse files
committed
fix(lastgenre): Reset plugin config in fixtured tests
Fixes a bug in the lastgenre, where test state bled into the following fixtures. Each plugin has a view to the global persisted beets.config field. As a result, variables that aren't explicitly overwritten are persisted in that global config view. This commit exposes the default config as a static method and uses that default config to reset the state in between fixture calls. There were 5 tests that depended on count: 10 being set on previous test fixtures, which I adjusted accordingly.
1 parent dcef1f4 commit 3d0414c

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

beetsplug/lastgenre/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,27 @@ class LastGenrePlugin(plugins.BeetsPlugin):
100100
def __init__(self) -> None:
101101
super().__init__()
102102

103-
self.config.add(
104-
{
105-
"whitelist": True,
106-
"min_weight": 10,
107-
"count": 1,
108-
"fallback": None,
109-
"canonical": False,
110-
"source": "album",
111-
"force": False,
112-
"keep_existing": False,
113-
"auto": True,
114-
"separator": ", ",
115-
"prefer_specific": False,
116-
"title_case": True,
117-
"pretend": False,
118-
}
119-
)
103+
self.config.add(LastGenrePlugin.default_configuration())
120104
self.setup()
121105

106+
@staticmethod
107+
def default_configuration() -> dict[str, Any]:
108+
return {
109+
"whitelist": True,
110+
"min_weight": 10,
111+
"count": 1,
112+
"fallback": None,
113+
"canonical": False,
114+
"source": "album",
115+
"force": False,
116+
"keep_existing": False,
117+
"auto": True,
118+
"separator": ", ",
119+
"prefer_specific": False,
120+
"title_case": True,
121+
"pretend": False,
122+
}
123+
122124
def setup(self) -> None:
123125
"""Setup plugin from config options"""
124126
if self.config["auto"]:

test/plugins/test_lastgenre.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def test_sort_by_depth(self):
230230
"whitelist": True,
231231
"canonical": False,
232232
"prefer_specific": False,
233+
"count": 10,
233234
},
234235
"original unknown, Blues",
235236
{
@@ -262,6 +263,7 @@ def test_sort_by_depth(self):
262263
"whitelist": True,
263264
"canonical": False,
264265
"prefer_specific": False,
266+
"count": 10,
265267
},
266268
"original unknown, Blues",
267269
{
@@ -311,6 +313,7 @@ def test_sort_by_depth(self):
311313
"whitelist": False,
312314
"canonical": False,
313315
"prefer_specific": False,
316+
"count": 10,
314317
},
315318
"unknown genre",
316319
{
@@ -409,6 +412,7 @@ def test_sort_by_depth(self):
409412
"separator": "\u0000",
410413
"canonical": False,
411414
"prefer_specific": False,
415+
"count": 10,
412416
},
413417
"Blues",
414418
{
@@ -590,6 +594,7 @@ def mock_fetch_artist_genre(self, artist):
590594
# Initialize plugin instance and item
591595
plugin = lastgenre.LastGenrePlugin()
592596
# Configure
597+
plugin.config.set(lastgenre.LastGenrePlugin.default_configuration())
593598
plugin.config.set(config_values)
594599
plugin.setup() # Loads default whitelist and canonicalization tree
595600
item = _common.item()

0 commit comments

Comments
 (0)