mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 13:33:02 +01:00
Deduplicate TerminalImportHelper and rename to TerminalImportMixin
This commit is contained in:
parent
6ccf33d79e
commit
91099d362e
5 changed files with 36 additions and 60 deletions
|
|
@ -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],
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue