From 16cf8dd937b9a135201123ac31b979cd56bc5a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Sat, 6 Jul 2024 20:14:56 +0100 Subject: [PATCH] Centralize db setup on disk --- beets/test/helper.py | 10 ++++++---- test/plugins/test_convert.py | 8 ++++---- test/plugins/test_player.py | 4 +++- test/plugins/test_replaygain.py | 3 ++- test/test_importer.py | 8 ++++++-- test/test_logging.py | 5 ++--- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/beets/test/helper.py b/beets/test/helper.py index 4f62055e7..241213ce4 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -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")), diff --git a/test/plugins/test_convert.py b/test/plugins/test_convert.py index 9aa98f4c1..c15462a5b 100644 --- a/test/plugins/test_convert.py +++ b/test/plugins/test_convert.py @@ -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") diff --git a/test/plugins/test_player.py b/test/plugins/test_player.py index b7735ff10..f0a3f3b66 100644 --- a/test/plugins/test_player.py +++ b/test/plugins/test_player.py @@ -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", diff --git a/test/plugins/test_replaygain.py b/test/plugins/test_replaygain.py index d8082b0af..94846c968 100644 --- a/test/plugins/test_replaygain.py +++ b/test/plugins/test_replaygain.py @@ -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: diff --git a/test/test_importer.py b/test/test_importer.py index f510b81ac..980060488 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -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) diff --git a/test/test_logging.py b/test/test_logging.py index ad5346186..97786ec18 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -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)