diff --git a/beets/test/helper.py b/beets/test/helper.py index 24659d1d7..1499bd125 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -541,6 +541,8 @@ class ImportHelper: autotagging library and several assertions for the library. """ + importer: importer.ImportSession + def setup_beets(self, disk=False): super().setup_beets(disk) self.lib.path_formats = [ @@ -598,35 +600,33 @@ class ImportHelper: self.media_files.append(medium) self.import_media = self.media_files + def _get_import_session(self, import_dir: str) -> None: + self.importer = ImportSessionFixture( + self.lib, + loghandler=None, + query=None, + paths=[import_dir], + ) + def _setup_import_session( self, import_dir=None, - delete=False, - threaded=False, - copy=True, singletons=False, move=False, autotag=True, - link=False, - hardlink=False, ): - config["import"]["copy"] = copy - config["import"]["delete"] = delete + config["import"]["copy"] = True + config["import"]["delete"] = False config["import"]["timid"] = True config["threaded"] = False config["import"]["singletons"] = singletons config["import"]["move"] = move config["import"]["autotag"] = autotag config["import"]["resume"] = False - config["import"]["link"] = link - config["import"]["hardlink"] = hardlink + config["import"]["link"] = False + config["import"]["hardlink"] = False - self.importer = ImportSessionFixture( - self.lib, - loghandler=None, - query=None, - paths=[import_dir or self.import_dir], - ) + self._get_import_session(import_dir or self.import_dir) def assert_file_in_lib(self, *segments): """Join the ``segments`` and assert that this path exists in the @@ -759,37 +759,17 @@ class TerminalImportSessionFixture(TerminalImportSession): raise Exception("Unknown choice %s" % choice) -class TerminalImportSessionSetup: - """Overwrites ImportHelper._setup_import_session to provide a terminal importer""" +class TerminalImportMixin(ImportHelper): + """Provides_a terminal importer for the import session.""" - def _setup_import_session( - self, - import_dir=None, - delete=False, - threaded=False, - copy=True, - singletons=False, - move=False, - autotag=True, - ): - config["import"]["copy"] = copy - config["import"]["delete"] = delete - config["import"]["timid"] = True - config["threaded"] = False - config["import"]["singletons"] = singletons - config["import"]["move"] = move - config["import"]["autotag"] = autotag - config["import"]["resume"] = False - - if not hasattr(self, "io"): - self.io = _common.DummyIO() + def _get_import_session(self, import_dir: str) -> None: self.io.install() self.importer = TerminalImportSessionFixture( self.lib, loghandler=None, query=None, io=self.io, - paths=[import_dir or self.import_dir], + paths=[import_dir], ) diff --git a/test/plugins/test_edit.py b/test/plugins/test_edit.py index 7e06e7a1c..2e6ae0745 100644 --- a/test/plugins/test_edit.py +++ b/test/plugins/test_edit.py @@ -23,7 +23,7 @@ from beets.test.helper import ( AutotagStub, BeetsTestCase, ImportTestCase, - TerminalImportSessionSetup, + TerminalImportMixin, control_stdin, ) from beetsplug.edit import EditPlugin @@ -322,8 +322,8 @@ class EditCommandTest(BeetsTestCase, EditMixin): @_common.slow_test() -class EditDuringImporterTest( - TerminalImportSessionSetup, ImportTestCase, EditMixin +class EditDuringImporterTestCase( + EditMixin, TerminalImportMixin, ImportTestCase ): """TODO""" diff --git a/test/plugins/test_mbsubmit.py b/test/plugins/test_mbsubmit.py index f97e389c5..83cfb1b92 100644 --- a/test/plugins/test_mbsubmit.py +++ b/test/plugins/test_mbsubmit.py @@ -18,13 +18,13 @@ import unittest from beets.test.helper import ( AutotagStub, ImportTestCase, - TerminalImportSessionSetup, + TerminalImportMixin, capture_stdout, control_stdin, ) -class MBSubmitPluginTest(TerminalImportSessionSetup, ImportTestCase): +class MBSubmitPluginTest(TerminalImportMixin, ImportTestCase): def setUp(self): self.setup_beets() self.load_plugins("mbsubmit") diff --git a/test/test_plugins.py b/test/test_plugins.py index acf703e46..2ea24b02c 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -35,7 +35,7 @@ from beets.test.helper import ( AutotagStub, BeetsTestCase, ImportHelper, - TerminalImportSessionSetup, + TerminalImportMixin, ) from beets.util import displayable_path, syspath from beets.util.id_extractors import ( @@ -377,7 +377,7 @@ class ListenersTest(PluginLoaderTestCase): plugins.send("event9", foo=5) -class PromptChoicesTest(TerminalImportSessionSetup, PluginImportTestCase): +class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase): def setUp(self): super().setUp() self._setup_import_session() diff --git a/test/test_ui_importer.py b/test/test_ui_importer.py index 3991376ac..7dfcc205e 100644 --- a/test/test_ui_importer.py +++ b/test/test_ui_importer.py @@ -21,57 +21,53 @@ test_importer module. But here the test importer inherits from import unittest from test import test_importer -from beets.test.helper import TerminalImportSessionSetup +from beets.test.helper import TerminalImportMixin class NonAutotaggedImportTest( - TerminalImportSessionSetup, test_importer.NonAutotaggedImportTest + TerminalImportMixin, test_importer.NonAutotaggedImportTest ): pass -class ImportTest(TerminalImportSessionSetup, test_importer.ImportTest): +class ImportTest(TerminalImportMixin, test_importer.ImportTest): pass class ImportSingletonTest( - TerminalImportSessionSetup, test_importer.ImportSingletonTest + TerminalImportMixin, test_importer.ImportSingletonTest ): pass -class ImportTracksTest( - TerminalImportSessionSetup, test_importer.ImportTracksTest -): +class ImportTracksTest(TerminalImportMixin, test_importer.ImportTracksTest): pass class ImportCompilationTest( - TerminalImportSessionSetup, test_importer.ImportCompilationTest + TerminalImportMixin, test_importer.ImportCompilationTest ): pass -class ImportExistingTest( - TerminalImportSessionSetup, test_importer.ImportExistingTest -): +class ImportExistingTest(TerminalImportMixin, test_importer.ImportExistingTest): pass class ChooseCandidateTest( - TerminalImportSessionSetup, test_importer.ChooseCandidateTest + TerminalImportMixin, test_importer.ChooseCandidateTest ): pass class GroupAlbumsImportTest( - TerminalImportSessionSetup, test_importer.GroupAlbumsImportTest + TerminalImportMixin, test_importer.GroupAlbumsImportTest ): pass class GlobalGroupAlbumsImportTest( - TerminalImportSessionSetup, test_importer.GlobalGroupAlbumsImportTest + TerminalImportMixin, test_importer.GlobalGroupAlbumsImportTest ): pass