mirror of
https://github.com/beetbox/beets.git
synced 2026-01-02 14:03:12 +01:00
item assignment: set track distance configuration in tests explicitly
These tests depend on certain `track_length_grace` and `track_length_max` configuration which was set by other tests in this module. I discovered this issue when I tried to run `test_order_works_when_track_names_are_entirely_wrong` test only - I found that my local configuration was read and the test failed.
This commit is contained in:
parent
084cf6490e
commit
ef902ea14f
2 changed files with 29 additions and 22 deletions
|
|
@ -48,7 +48,7 @@ from mediafile import Image, MediaFile
|
|||
|
||||
import beets
|
||||
import beets.plugins
|
||||
from beets import autotag, config, importer, logging, util
|
||||
from beets import autotag, importer, logging, util
|
||||
from beets.autotag.hooks import AlbumInfo, TrackInfo
|
||||
from beets.importer import ImportSession
|
||||
from beets.library import Album, Item, Library
|
||||
|
|
@ -153,12 +153,27 @@ def check_reflink_support(path: str) -> bool:
|
|||
return reflink.supported_at(path)
|
||||
|
||||
|
||||
class ConfigMixin:
|
||||
@cached_property
|
||||
def config(self) -> beets.IncludeLazyConfig:
|
||||
"""Base beets configuration for tests."""
|
||||
config = beets.config
|
||||
config.sources = []
|
||||
config.read(user=False, defaults=True)
|
||||
|
||||
config["plugins"] = []
|
||||
config["verbose"] = 1
|
||||
config["ui"]["color"] = False
|
||||
config["threaded"] = False
|
||||
return config
|
||||
|
||||
|
||||
NEEDS_REFLINK = unittest.skipUnless(
|
||||
check_reflink_support(gettempdir()), "no reflink support for libdir"
|
||||
)
|
||||
|
||||
|
||||
class TestHelper(_common.Assertions):
|
||||
class TestHelper(_common.Assertions, ConfigMixin):
|
||||
"""Helper mixin for high-level cli and plugin tests.
|
||||
|
||||
This mixin provides methods to isolate beets' global state provide
|
||||
|
|
@ -184,8 +199,6 @@ class TestHelper(_common.Assertions):
|
|||
- ``libdir`` Path to a subfolder of ``temp_dir``, containing the
|
||||
library's media files. Same as ``config['directory']``.
|
||||
|
||||
- ``config`` The global configuration used by beets.
|
||||
|
||||
- ``lib`` Library instance created with the settings from
|
||||
``config``.
|
||||
|
||||
|
|
@ -202,15 +215,6 @@ class TestHelper(_common.Assertions):
|
|||
)
|
||||
self.env_patcher.start()
|
||||
|
||||
self.config = beets.config
|
||||
self.config.sources = []
|
||||
self.config.read(user=False, defaults=True)
|
||||
|
||||
self.config["plugins"] = []
|
||||
self.config["verbose"] = 1
|
||||
self.config["ui"]["color"] = False
|
||||
self.config["threaded"] = False
|
||||
|
||||
self.libdir = os.path.join(self.temp_dir, b"libdir")
|
||||
os.mkdir(syspath(self.libdir))
|
||||
self.config["directory"] = os.fsdecode(self.libdir)
|
||||
|
|
@ -229,8 +233,6 @@ class TestHelper(_common.Assertions):
|
|||
self.io.restore()
|
||||
self.lib._close()
|
||||
self.remove_temp_dir()
|
||||
beets.config.clear()
|
||||
beets.config._materialized = False
|
||||
|
||||
# Library fixtures methods
|
||||
|
||||
|
|
@ -452,7 +454,7 @@ class ItemInDBTestCase(BeetsTestCase):
|
|||
self.i = _common.item(self.lib)
|
||||
|
||||
|
||||
class PluginMixin:
|
||||
class PluginMixin(ConfigMixin):
|
||||
plugin: ClassVar[str]
|
||||
preload_plugin: ClassVar[bool] = True
|
||||
|
||||
|
|
@ -473,7 +475,7 @@ class PluginMixin:
|
|||
"""
|
||||
# FIXME this should eventually be handled by a plugin manager
|
||||
plugins = (self.plugin,) if hasattr(self, "plugin") else plugins
|
||||
beets.config["plugins"] = plugins
|
||||
self.config["plugins"] = plugins
|
||||
beets.plugins.load_plugins(plugins)
|
||||
beets.plugins.find_plugins()
|
||||
|
||||
|
|
@ -494,7 +496,7 @@ class PluginMixin:
|
|||
# FIXME this should eventually be handled by a plugin manager
|
||||
for plugin_class in beets.plugins._instances:
|
||||
plugin_class.listeners = None
|
||||
beets.config["plugins"] = []
|
||||
self.config["plugins"] = []
|
||||
beets.plugins._classes = set()
|
||||
beets.plugins._instances = {}
|
||||
Item._types = getattr(Item, "_original_types", {})
|
||||
|
|
@ -504,7 +506,7 @@ class PluginMixin:
|
|||
|
||||
@contextmanager
|
||||
def configure_plugin(self, config: Any):
|
||||
beets.config[self.plugin].set(config)
|
||||
self.config[self.plugin].set(config)
|
||||
self.load_plugins(self.plugin)
|
||||
|
||||
yield
|
||||
|
|
@ -624,7 +626,7 @@ class ImportHelper(TestHelper):
|
|||
def setup_importer(
|
||||
self, import_dir: bytes | None = None, **kwargs
|
||||
) -> ImportSession:
|
||||
config["import"].set_args({**self.default_import_config, **kwargs})
|
||||
self.config["import"].set_args({**self.default_import_config, **kwargs})
|
||||
self.importer = self._get_import_session(import_dir or self.import_dir)
|
||||
return self.importer
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from beets import autotag, config
|
|||
from beets.autotag import AlbumInfo, TrackInfo, correct_list_fields, match
|
||||
from beets.autotag.hooks import Distance, string_dist
|
||||
from beets.library import Item
|
||||
from beets.test.helper import BeetsTestCase
|
||||
from beets.test.helper import BeetsTestCase, ConfigMixin
|
||||
from beets.util import plurality
|
||||
|
||||
|
||||
|
|
@ -498,11 +498,16 @@ class AlbumDistanceTest(BeetsTestCase):
|
|||
assert dist == 0
|
||||
|
||||
|
||||
class TestAssignment:
|
||||
class TestAssignment(ConfigMixin):
|
||||
A = "one"
|
||||
B = "two"
|
||||
C = "three"
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _setup_config(self):
|
||||
self.config["match"]["track_length_grace"] = 10
|
||||
self.config["match"]["track_length_max"] = 30
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
# 'expected' is a tuple of expected (mapping, extra_items, extra_tracks)
|
||||
"item_titles, track_titles, expected",
|
||||
|
|
|
|||
Loading…
Reference in a new issue