mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 23:03:26 +01:00
Create PluginImportTestCase in test_plugins
This involves making EventsTest use _create_import_dir from TestHelper.
This commit is contained in:
parent
0b5b94460a
commit
8373181e02
1 changed files with 20 additions and 49 deletions
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
import itertools
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
from unittest.mock import ANY, Mock, patch
|
||||
|
||||
|
|
@ -32,14 +31,13 @@ from beets.importer import (
|
|||
from beets.library import Item
|
||||
from beets.plugins import MetadataSourcePlugin
|
||||
from beets.test import helper
|
||||
from beets.test._common import RSRC
|
||||
from beets.test.helper import (
|
||||
AutotagStub,
|
||||
BeetsTestCase,
|
||||
ImportHelper,
|
||||
TerminalImportSessionSetup,
|
||||
)
|
||||
from beets.util import bytestring_path, displayable_path, syspath
|
||||
from beets.util import displayable_path, syspath
|
||||
from beets.util.id_extractors import (
|
||||
beatport_id_regex,
|
||||
deezer_id_regex,
|
||||
|
|
@ -77,6 +75,12 @@ class PluginLoaderTestCase(BeetsTestCase):
|
|||
self.teardown_beets()
|
||||
|
||||
|
||||
class PluginImportTestCase(ImportHelper, PluginLoaderTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self._create_import_dir(2)
|
||||
|
||||
|
||||
class ItemTypesTest(PluginLoaderTestCase):
|
||||
def test_flex_field_type(self):
|
||||
class RatingPlugin(plugins.BeetsPlugin):
|
||||
|
|
@ -158,47 +162,11 @@ class ItemTypeConflictTest(PluginLoaderTestCase):
|
|||
self.assertIsNotNone(plugins.types(Item))
|
||||
|
||||
|
||||
class EventsTest(ImportHelper, PluginLoaderTestCase):
|
||||
class EventsTest(PluginImportTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.__create_import_dir(2)
|
||||
config["import"]["pretend"] = True
|
||||
|
||||
def __copy_file(self, dest_path, metadata):
|
||||
# Copy files
|
||||
resource_path = os.path.join(RSRC, b"full.mp3")
|
||||
shutil.copy(syspath(resource_path), syspath(dest_path))
|
||||
medium = MediaFile(dest_path)
|
||||
# Set metadata
|
||||
for attr in metadata:
|
||||
setattr(medium, attr, metadata[attr])
|
||||
medium.save()
|
||||
|
||||
def __create_import_dir(self, count):
|
||||
self.import_dir = os.path.join(self.temp_dir, b"testsrcdir")
|
||||
if os.path.isdir(syspath(self.import_dir)):
|
||||
shutil.rmtree(syspath(self.import_dir))
|
||||
|
||||
self.album_path = os.path.join(self.import_dir, b"album")
|
||||
os.makedirs(self.album_path)
|
||||
|
||||
metadata = {
|
||||
"artist": "Tag Artist",
|
||||
"album": "Tag Album",
|
||||
"albumartist": None,
|
||||
"mb_trackid": None,
|
||||
"mb_albumid": None,
|
||||
"comp": None,
|
||||
}
|
||||
self.file_paths = []
|
||||
for i in range(count):
|
||||
metadata["track"] = i + 1
|
||||
metadata["title"] = "Tag Title Album %d" % (i + 1)
|
||||
track_file = bytestring_path("%02d - track.mp3" % (i + 1))
|
||||
dest_path = os.path.join(self.album_path, track_file)
|
||||
self.__copy_file(dest_path, metadata)
|
||||
self.file_paths.append(dest_path)
|
||||
|
||||
def test_import_task_created(self):
|
||||
import_files = [self.import_dir]
|
||||
self._setup_import_session(singletons=False)
|
||||
|
|
@ -217,10 +185,12 @@ class EventsTest(ImportHelper, PluginLoaderTestCase):
|
|||
logs,
|
||||
[
|
||||
"Album: {}".format(
|
||||
displayable_path(os.path.join(self.import_dir, b"album"))
|
||||
displayable_path(
|
||||
os.path.join(self.import_dir, b"the_album")
|
||||
)
|
||||
),
|
||||
" {}".format(displayable_path(self.file_paths[0])),
|
||||
" {}".format(displayable_path(self.file_paths[1])),
|
||||
" {}".format(displayable_path(self.media_files[0].path)),
|
||||
" {}".format(displayable_path(self.media_files[1].path)),
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -266,8 +236,12 @@ class EventsTest(ImportHelper, PluginLoaderTestCase):
|
|||
self.assertEqual(
|
||||
logs,
|
||||
[
|
||||
"Singleton: {}".format(displayable_path(self.file_paths[0])),
|
||||
"Singleton: {}".format(displayable_path(self.file_paths[1])),
|
||||
"Singleton: {}".format(
|
||||
displayable_path(self.media_files[0].path)
|
||||
),
|
||||
"Singleton: {}".format(
|
||||
displayable_path(self.media_files[1].path)
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -403,12 +377,9 @@ class ListenersTest(PluginLoaderTestCase):
|
|||
plugins.send("event9", foo=5)
|
||||
|
||||
|
||||
class PromptChoicesTest(
|
||||
TerminalImportSessionSetup, ImportHelper, PluginLoaderTestCase
|
||||
):
|
||||
class PromptChoicesTest(TerminalImportSessionSetup, PluginImportTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self._create_import_dir(3)
|
||||
self._setup_import_session()
|
||||
self.matcher = AutotagStub().install()
|
||||
# keep track of ui.input_option() calls
|
||||
|
|
|
|||
Loading…
Reference in a new issue