mirror of
https://github.com/beetbox/beets.git
synced 2026-01-03 22:42:44 +01:00
Centralize db setup on disk
This commit is contained in:
parent
7d7f16395c
commit
16cf8dd937
6 changed files with 23 additions and 15 deletions
|
|
@ -151,9 +151,11 @@ class TestHelper(_common.Assertions):
|
|||
fixtures.
|
||||
"""
|
||||
|
||||
db_on_disk: ClassVar[bool] = False
|
||||
|
||||
# TODO automate teardown through hook registration
|
||||
|
||||
def setup_beets(self, disk=False):
|
||||
def setup_beets(self):
|
||||
"""Setup pristine global configuration and library for testing.
|
||||
|
||||
Sets ``beets.config`` so we can safely use any functionality
|
||||
|
|
@ -199,7 +201,7 @@ class TestHelper(_common.Assertions):
|
|||
os.mkdir(syspath(self.libdir))
|
||||
self.config["directory"] = os.fsdecode(self.libdir)
|
||||
|
||||
if disk:
|
||||
if self.db_on_disk:
|
||||
dbpath = util.bytestring_path(self.config["library"].as_filename())
|
||||
else:
|
||||
dbpath = ":memory:"
|
||||
|
|
@ -538,8 +540,8 @@ class ImportHelper:
|
|||
|
||||
importer: importer.ImportSession
|
||||
|
||||
def setup_beets(self, disk=False):
|
||||
super().setup_beets(disk)
|
||||
def setup_beets(self):
|
||||
super().setup_beets()
|
||||
self.lib.path_formats = [
|
||||
("default", os.path.join("$artist", "$album", "$title")),
|
||||
("singleton:true", os.path.join("singletons", "$title")),
|
||||
|
|
|
|||
|
|
@ -85,13 +85,13 @@ class ConvertMixin:
|
|||
|
||||
|
||||
class ConvertTestCase(BeetsTestCase, ConvertMixin):
|
||||
pass
|
||||
db_on_disk = True
|
||||
|
||||
|
||||
@_common.slow_test()
|
||||
class ImportConvertTest(ConvertTestCase):
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True) # Converter is threaded
|
||||
super().setUp()
|
||||
self.importer = self.create_importer()
|
||||
self.load_plugins("convert")
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ class ConvertCommand:
|
|||
@_common.slow_test()
|
||||
class ConvertCliTest(ConvertTestCase, ConvertCommand):
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True) # Converter is threaded
|
||||
super().setUp()
|
||||
self.album = self.add_album_fixture(ext="ogg")
|
||||
self.item = self.album.items()[0]
|
||||
self.load_plugins("convert")
|
||||
|
|
@ -318,7 +318,7 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand):
|
|||
"""Test the effect of the `never_convert_lossy_files` option."""
|
||||
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True) # Converter is threaded
|
||||
super().setUp()
|
||||
self.load_plugins("convert")
|
||||
|
||||
self.convert_dest = os.path.join(self.temp_dir, b"convert_dest")
|
||||
|
|
|
|||
|
|
@ -278,8 +278,10 @@ def start_server(args, assigned_port, listener_patch):
|
|||
|
||||
|
||||
class BPDTestHelper(BeetsTestCase):
|
||||
db_on_disk = True
|
||||
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True)
|
||||
super().setUp()
|
||||
self.load_plugins("bpd")
|
||||
self.item1 = self.add_item(
|
||||
title="Track One Title",
|
||||
|
|
|
|||
|
|
@ -53,13 +53,14 @@ def reset_replaygain(item):
|
|||
|
||||
|
||||
class ReplayGainTestCase(BeetsTestCase):
|
||||
db_on_disk = True
|
||||
backend: ClassVar[str]
|
||||
|
||||
def setUp(self):
|
||||
# Implemented by Mixins, see above. This may decide to skip the test.
|
||||
self.test_backend()
|
||||
|
||||
self.setup_beets(disk=True)
|
||||
super().setUp()
|
||||
self.config["replaygain"]["backend"] = self.backend
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -45,8 +45,10 @@ from beets.util import bytestring_path, displayable_path, syspath
|
|||
|
||||
|
||||
class ScrubbedImportTest(ImportTestCase):
|
||||
db_on_disk = True
|
||||
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True)
|
||||
super().setUp()
|
||||
self.load_plugins("scrub")
|
||||
self._create_import_dir(2)
|
||||
self._setup_import_session(autotag=False)
|
||||
|
|
@ -100,8 +102,10 @@ class ScrubbedImportTest(ImportTestCase):
|
|||
|
||||
@_common.slow_test()
|
||||
class NonAutotaggedImportTest(ImportTestCase):
|
||||
db_on_disk = True
|
||||
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True)
|
||||
super().setUp()
|
||||
self._create_import_dir(2)
|
||||
self._setup_import_session(autotag=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,8 @@ class ConcurrentEventsTest(BeetsTestCase):
|
|||
LoggingLevelTest.
|
||||
"""
|
||||
|
||||
db_on_disk = True
|
||||
|
||||
class DummyPlugin(plugins.BeetsPlugin):
|
||||
def __init__(self, test_case):
|
||||
plugins.BeetsPlugin.__init__(self, "dummy")
|
||||
|
|
@ -204,9 +206,6 @@ class ConcurrentEventsTest(BeetsTestCase):
|
|||
except Exception as e:
|
||||
self.exc = e
|
||||
|
||||
def setUp(self):
|
||||
self.setup_beets(disk=True)
|
||||
|
||||
def test_concurrent_events(self):
|
||||
dp = self.DummyPlugin(self)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue