diff --git a/beets/test/helper.py b/beets/test/helper.py index 241213ce4..c64998174 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -225,6 +225,7 @@ class TestHelper(_common.Assertions): sure you call ``unload_plugins()`` afterwards. """ # FIXME this should eventually be handled by a plugin manager + plugins = (self.plugin,) if hasattr(self, "plugin") else plugins beets.config["plugins"] = plugins beets.plugins.load_plugins(plugins) beets.plugins.find_plugins() @@ -242,7 +243,7 @@ class TestHelper(_common.Assertions): Album._queries.update(beets.plugins.named_queries(Album)) def unload_plugins(self): - """Unload all plugins and remove the from the configuration.""" + """Unload all plugins and remove them from the configuration.""" # FIXME this should eventually be handled by a plugin manager beets.config["plugins"] = [] beets.plugins._classes = set() @@ -532,6 +533,22 @@ class ItemInDBTestCase(BeetsTestCase): self.i = _common.item(self.lib) +class PluginMixin: + plugin: ClassVar[str] + + def setUp(self): + super().setUp() + self.load_plugins() + + def tearDown(self): + super().tearDown() + self.unload_plugins() + + +class PluginTestCase(PluginMixin, BeetsTestCase): + pass + + class ImportHelper: """Provides tools to setup a library, a directory containing files that are to be imported and an import session. The class also provides stubs for the diff --git a/test/plugins/test_albumtypes.py b/test/plugins/test_albumtypes.py index e436f5aae..a6dfafe65 100644 --- a/test/plugins/test_albumtypes.py +++ b/test/plugins/test_albumtypes.py @@ -18,22 +18,13 @@ from typing import Sequence, Tuple from beets.autotag.mb import VARIOUS_ARTISTS_ID -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug.albumtypes import AlbumTypesPlugin -class AlbumTypesPluginTest(BeetsTestCase): +class AlbumTypesPluginTest(PluginTestCase): """Tests for albumtypes plugin.""" - - def setUp(self): - """Set up tests.""" - super().setUp() - self.load_plugins("albumtypes") - - def tearDown(self): - """Tear down tests.""" - self.unload_plugins() - super().tearDown() + plugin = "albumtypes" def test_renames_types(self): """Tests if the plugin correctly renames the specified types.""" diff --git a/test/plugins/test_bareasc.py b/test/plugins/test_bareasc.py index b3833df3d..61c600bad 100644 --- a/test/plugins/test_bareasc.py +++ b/test/plugins/test_bareasc.py @@ -6,18 +6,18 @@ import unittest from beets import logging -from beets.test.helper import BeetsTestCase, capture_stdout +from beets.test.helper import PluginTestCase, capture_stdout -class BareascPluginTest(BeetsTestCase): +class BareascPluginTest(PluginTestCase): """Test bare ASCII query matching.""" + plugin = "bareasc" def setUp(self): """Set up test environment for bare ASCII query matching.""" super().setUp() self.log = logging.getLogger("beets.web") self.config["bareasc"]["prefix"] = "#" - self.load_plugins("bareasc") # Add library elements. Note that self.lib.add overrides any "id=" # and assigns the next free id number. diff --git a/test/plugins/test_beatport.py b/test/plugins/test_beatport.py index 6a4cc5216..5e5130a5d 100644 --- a/test/plugins/test_beatport.py +++ b/test/plugins/test_beatport.py @@ -450,7 +450,6 @@ class BeatportTest(BeetsTestCase): def setUp(self): super().setUp() - self.load_plugins("beatport") # Set up 'album'. response_release = self._make_release_response() @@ -466,10 +465,6 @@ class BeatportTest(BeetsTestCase): # Set up 'test_tracks' self.test_tracks = self.test_album.items() - def tearDown(self): - self.unload_plugins() - super().tearDown() - def mk_test_album(self): items = [_common.item() for _ in range(6)] for item in items: @@ -627,7 +622,6 @@ class BeatportResponseEmptyTest(BeetsTestCase): def setUp(self): super().setUp() - self.load_plugins("beatport") # Set up 'tracks'. self.response_tracks = self._make_tracks_response() @@ -636,10 +630,6 @@ class BeatportResponseEmptyTest(BeetsTestCase): # Make alias to be congruent with class `BeatportTest`. self.test_tracks = self.response_tracks - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_response_tracks_empty(self): response_tracks = [] tracks = [beatport.BeatportTrack(t) for t in response_tracks] diff --git a/test/plugins/test_convert.py b/test/plugins/test_convert.py index c15462a5b..1b864499a 100644 --- a/test/plugins/test_convert.py +++ b/test/plugins/test_convert.py @@ -23,7 +23,7 @@ from mediafile import MediaFile from beets import util from beets.test import _common -from beets.test.helper import BeetsTestCase, capture_log, control_stdin +from beets.test.helper import PluginTestCase, capture_log, control_stdin from beets.util import bytestring_path, displayable_path @@ -84,8 +84,9 @@ class ConvertMixin: ) -class ConvertTestCase(BeetsTestCase, ConvertMixin): +class ConvertTestCase(ConvertMixin, PluginTestCase): db_on_disk = True + plugin = "convert" @_common.slow_test() @@ -93,7 +94,6 @@ class ImportConvertTest(ConvertTestCase): def setUp(self): super().setUp() self.importer = self.create_importer() - self.load_plugins("convert") self.config["convert"] = { "dest": os.path.join(self.temp_dir, b"convert"), @@ -104,10 +104,6 @@ class ImportConvertTest(ConvertTestCase): "quiet": False, } - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_import_converted(self): self.importer.run() item = self.lib.items().get() @@ -172,7 +168,6 @@ class ConvertCliTest(ConvertTestCase, ConvertCommand): super().setUp() self.album = self.add_album_fixture(ext="ogg") self.item = self.album.items()[0] - self.load_plugins("convert") self.convert_dest = bytestring_path( os.path.join(self.temp_dir, b"convert_dest") @@ -191,10 +186,6 @@ class ConvertCliTest(ConvertTestCase, ConvertCommand): }, } - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_convert(self): with control_stdin("y"): self.run_convert() @@ -319,7 +310,6 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand): def setUp(self): super().setUp() - self.load_plugins("convert") self.convert_dest = os.path.join(self.temp_dir, b"convert_dest") self.config["convert"] = { @@ -332,10 +322,6 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand): }, } - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_transcode_from_lossless(self): [item] = self.add_item_fixtures(ext="flac") with control_stdin("y"): diff --git a/test/plugins/test_edit.py b/test/plugins/test_edit.py index c9bd85466..8244704d0 100644 --- a/test/plugins/test_edit.py +++ b/test/plugins/test_edit.py @@ -21,8 +21,8 @@ from beets.library import Item from beets.test import _common from beets.test.helper import ( AutotagStub, - BeetsTestCase, ImportTestCase, + PluginTestCase, TerminalImportMixin, control_stdin, ) @@ -73,9 +73,11 @@ class ModifyFileMocker: f.write(contents) -class EditMixin: +class EditMixin(PluginTestCase): """Helper containing some common functionality used for the Edit tests.""" + plugin = "edit" + def assertItemFieldsModified( # noqa self, library_items, items, fields=[], allowed=["path"] ): @@ -115,7 +117,7 @@ class EditMixin: @_common.slow_test() @patch("beets.library.Item.write") -class EditCommandTest(BeetsTestCase, EditMixin): +class EditCommandTest(EditMixin): """Black box tests for `beetsplug.edit`. Command line interaction is simulated using `test.helper.control_stdin()`, and yaml editing via an external editor is simulated using `ModifyFileMocker`. @@ -126,7 +128,6 @@ class EditCommandTest(BeetsTestCase, EditMixin): def setUp(self): super().setUp() - self.load_plugins("edit") # Add an album, storing the original fields for comparison. self.album = self.add_album_fixture(track_count=self.TRACK_COUNT) self.album_orig = {f: self.album[f] for f in self.album._fields} @@ -137,7 +138,6 @@ class EditCommandTest(BeetsTestCase, EditMixin): def tearDown(self): EditPlugin.listeners = None super().tearDown() - self.unload_plugins() def assertCounts( # noqa self, @@ -331,7 +331,6 @@ class EditDuringImporterTestCase( def setUp(self): super().setUp() - self.load_plugins("edit") # Create some mediafiles, and store them for comparison. self._create_import_dir(3) self.items_orig = [Item.from_path(f.path) for f in self.media_files] @@ -341,7 +340,6 @@ class EditDuringImporterTestCase( def tearDown(self): EditPlugin.listeners = None - self.unload_plugins() super().tearDown() self.matcher.restore() diff --git a/test/plugins/test_embedart.py b/test/plugins/test_embedart.py index c696ae85d..a58cd2f28 100644 --- a/test/plugins/test_embedart.py +++ b/test/plugins/test_embedart.py @@ -24,7 +24,7 @@ from mediafile import MediaFile from beets import art, config, logging, ui from beets.test import _common -from beets.test.helper import BeetsTestCase, FetchImageHelper +from beets.test.helper import BeetsTestCase, FetchImageHelper, PluginMixin from beets.util import bytestring_path, displayable_path, syspath from beets.util.artresizer import ArtResizer @@ -40,7 +40,8 @@ def require_artresizer_compare(test): return wrapper -class EmbedartCliTest(FetchImageHelper, BeetsTestCase): +class EmbedartCliTest(PluginMixin, FetchImageHelper, BeetsTestCase): + plugin = "embedart" small_artpath = os.path.join(_common.RSRC, b"image-2x3.jpg") abbey_artpath = os.path.join(_common.RSRC, b"abbey.jpg") abbey_similarpath = os.path.join(_common.RSRC, b"abbey-similar.jpg") @@ -49,7 +50,6 @@ class EmbedartCliTest(FetchImageHelper, BeetsTestCase): def setUp(self): super().setUp() # Converter is threaded self.io.install() - self.load_plugins("embedart") def _setup_data(self, artpath=None): if not artpath: @@ -57,10 +57,6 @@ class EmbedartCliTest(FetchImageHelper, BeetsTestCase): with open(syspath(artpath), "rb") as f: self.image_data = f.read() - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_embed_art_from_file_with_yes_input(self): self._setup_data() album = self.add_album_fixture() diff --git a/test/plugins/test_embyupdate.py b/test/plugins/test_embyupdate.py index d79c01a65..fe5fc6a81 100644 --- a/test/plugins/test_embyupdate.py +++ b/test/plugins/test_embyupdate.py @@ -2,14 +2,15 @@ import unittest import responses -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug import embyupdate -class EmbyUpdateTest(BeetsTestCase): +class EmbyUpdateTest(PluginTestCase): + plugin = "embyupdate" + def setUp(self): super().setUp() - self.load_plugins("embyupdate") self.config["emby"] = { "host": "localhost", @@ -18,10 +19,6 @@ class EmbyUpdateTest(BeetsTestCase): "password": "password", } - def tearDown(self): - super().tearDown() - self.unload_plugins() - def test_api_url_only_name(self): self.assertEqual( embyupdate.api_url( diff --git a/test/plugins/test_export.py b/test/plugins/test_export.py index acf76d48b..32d51a512 100644 --- a/test/plugins/test_export.py +++ b/test/plugins/test_export.py @@ -22,19 +22,16 @@ import unittest from xml.etree import ElementTree from xml.etree.ElementTree import Element -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase -class ExportPluginTest(BeetsTestCase): +class ExportPluginTest(PluginTestCase): + plugin = "export" + def setUp(self): super().setUp() - self.load_plugins("export") self.test_values = {"title": "xtitle", "album": "xalbum"} - def tearDown(self): - self.unload_plugins() - super().tearDown() - def execute_command(self, format_type, artist): query = ",".join(self.test_values.keys()) out = self.run_with_output( diff --git a/test/plugins/test_fetchart.py b/test/plugins/test_fetchart.py index ae1fcb96a..c64c6f63c 100644 --- a/test/plugins/test_fetchart.py +++ b/test/plugins/test_fetchart.py @@ -19,22 +19,19 @@ import sys import unittest from beets import util -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase -class FetchartCliTest(BeetsTestCase): +class FetchartCliTest(PluginTestCase): + plugin = "fetchart" + def setUp(self): super().setUp() - self.load_plugins("fetchart") self.config["fetchart"]["cover_names"] = "c\xc3\xb6ver.jpg" self.config["art_filename"] = "mycover" self.album = self.add_album() self.cover_path = os.path.join(self.album.path, b"mycover.jpg") - def tearDown(self): - self.unload_plugins() - super().tearDown() - def check_cover_is_stored(self): self.assertEqual(self.album["artpath"], self.cover_path) with open(util.syspath(self.cover_path)) as f: diff --git a/test/plugins/test_ftintitle.py b/test/plugins/test_ftintitle.py index 32c8e0e02..56a880b0b 100644 --- a/test/plugins/test_ftintitle.py +++ b/test/plugins/test_ftintitle.py @@ -17,19 +17,12 @@ import unittest -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug import ftintitle -class FtInTitlePluginFunctional(BeetsTestCase): - def setUp(self): - """Set up configuration""" - super().setUp() - self.load_plugins("ftintitle") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class FtInTitlePluginFunctional(PluginTestCase): + plugin = "ftintitle" def _ft_add_item(self, path, artist, title, aartist): return self.add_item( diff --git a/test/plugins/test_importadded.py b/test/plugins/test_importadded.py index b41b91eee..ea50e87cd 100644 --- a/test/plugins/test_importadded.py +++ b/test/plugins/test_importadded.py @@ -19,7 +19,7 @@ import os import unittest from beets import importer -from beets.test.helper import AutotagStub, ImportTestCase +from beets.test.helper import AutotagStub, ImportTestCase, PluginMixin from beets.util import displayable_path, syspath from beetsplug.importadded import ImportAddedPlugin @@ -40,14 +40,14 @@ def modify_mtimes(paths, offset=-60000): os.utime(syspath(path), (mstat.st_atime, mstat.st_mtime + offset * i)) -class ImportAddedTest(ImportTestCase): +class ImportAddedTest(PluginMixin, ImportTestCase): # The minimum mtime of the files to be imported + plugin = "importadded" min_mtime = None def setUp(self): preserve_plugin_listeners() super().setUp() - self.load_plugins("importadded") self._create_import_dir(2) # Different mtimes on the files to be imported in order to test the # plugin @@ -61,7 +61,6 @@ class ImportAddedTest(ImportTestCase): self.importer.add_choice(importer.action.APPLY) def tearDown(self): - self.unload_plugins() super().tearDown() self.matcher.restore() diff --git a/test/plugins/test_info.py b/test/plugins/test_info.py index 4ab8aa70c..7b2969264 100644 --- a/test/plugins/test_info.py +++ b/test/plugins/test_info.py @@ -17,18 +17,12 @@ import unittest from mediafile import MediaFile -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beets.util import displayable_path -class InfoTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("info") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class InfoTest(PluginTestCase): + plugin = "info" def test_path(self): path = self.create_mediafile_fixture() diff --git a/test/plugins/test_ipfs.py b/test/plugins/test_ipfs.py index 928b193f3..5924c1923 100644 --- a/test/plugins/test_ipfs.py +++ b/test/plugins/test_ipfs.py @@ -17,20 +17,14 @@ import unittest from unittest.mock import Mock, patch from beets.test import _common -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beets.util import _fsencoding, bytestring_path from beetsplug.ipfs import IPFSPlugin @patch("beets.util.command_output", Mock()) -class IPFSPluginTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("ipfs") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class IPFSPluginTest(PluginTestCase): + plugin = "ipfs" def test_stored_hashes(self): test_album = self.mk_test_album() diff --git a/test/plugins/test_keyfinder.py b/test/plugins/test_keyfinder.py index dfd35f61f..9afafe822 100644 --- a/test/plugins/test_keyfinder.py +++ b/test/plugins/test_keyfinder.py @@ -18,18 +18,12 @@ from unittest.mock import patch from beets import util from beets.library import Item -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase @patch("beets.util.command_output") -class KeyFinderTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("keyfinder") - - def tearDown(self): - super().tearDown() - self.unload_plugins() +class KeyFinderTest(PluginTestCase): + plugin = "keyfinder" def test_add_key(self, command_output): item = Item(path="/file") diff --git a/test/plugins/test_limit.py b/test/plugins/test_limit.py index 2c01dca76..f65607586 100644 --- a/test/plugins/test_limit.py +++ b/test/plugins/test_limit.py @@ -15,18 +15,19 @@ import unittest -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase -class LimitPluginTest(BeetsTestCase): +class LimitPluginTest(PluginTestCase): """Unit tests for LimitPlugin Note: query prefix tests do not work correctly with `run_with_output`. """ + plugin = "limit" + def setUp(self): super().setUp() - self.load_plugins("limit") # we'll create an even number of tracks in the library self.num_test_items = 10 @@ -46,10 +47,6 @@ class LimitPluginTest(BeetsTestCase): self.track_head_range = "track:.." + str(self.num_limit) self.track_tail_range = "track:" + str(self.num_limit + 1) + ".." - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_no_limit(self): """Returns all when there is no limit or filter.""" result = self.run_with_output("lslimit") diff --git a/test/plugins/test_mbsubmit.py b/test/plugins/test_mbsubmit.py index f82f8c851..e8774d610 100644 --- a/test/plugins/test_mbsubmit.py +++ b/test/plugins/test_mbsubmit.py @@ -18,22 +18,23 @@ import unittest from beets.test.helper import ( AutotagStub, ImportTestCase, + PluginMixin, TerminalImportMixin, capture_stdout, control_stdin, ) -class MBSubmitPluginTest(TerminalImportMixin, ImportTestCase): +class MBSubmitPluginTest(PluginMixin, TerminalImportMixin, ImportTestCase): + plugin = "mbsubmit" + def setUp(self): super().setUp() - self.load_plugins("mbsubmit") self._create_import_dir(2) self._setup_import_session() self.matcher = AutotagStub().install() def tearDown(self): - self.unload_plugins() super().tearDown() self.matcher.restore() diff --git a/test/plugins/test_mbsync.py b/test/plugins/test_mbsync.py index 62c08f685..538c372f6 100644 --- a/test/plugins/test_mbsync.py +++ b/test/plugins/test_mbsync.py @@ -19,21 +19,15 @@ from unittest.mock import patch from beets import config from beets.library import Item from beets.test.helper import ( - BeetsTestCase, + PluginTestCase, capture_log, generate_album_info, generate_track_info, ) -class MbsyncCliTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("mbsync") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class MbsyncCliTest(PluginTestCase): + plugin = "mbsync" @patch("beets.autotag.mb.album_for_id") @patch("beets.autotag.mb.track_for_id") diff --git a/test/plugins/test_mpdstats.py b/test/plugins/test_mpdstats.py index e60a32f4f..a0e00325d 100644 --- a/test/plugins/test_mpdstats.py +++ b/test/plugins/test_mpdstats.py @@ -18,18 +18,12 @@ from unittest.mock import ANY, Mock, call, patch from beets import util from beets.library import Item -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug.mpdstats import MPDStats -class MPDStatsTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("mpdstats") - - def tearDown(self): - super().tearDown() - self.unload_plugins() +class MPDStatsTest(PluginTestCase): + plugin = "mpdstats" def test_update_rating(self): item = Item(title="title", path="", id=1) diff --git a/test/plugins/test_parentwork.py b/test/plugins/test_parentwork.py index fedcc6ceb..b1fd7e669 100644 --- a/test/plugins/test_parentwork.py +++ b/test/plugins/test_parentwork.py @@ -20,7 +20,7 @@ import unittest from unittest.mock import patch from beets.library import Item -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug import parentwork work = { @@ -85,15 +85,8 @@ def mock_workid_response(mbid, includes): return p_work -class ParentWorkIntegrationTest(BeetsTestCase): - def setUp(self): - """Set up configuration""" - super().setUp() - self.load_plugins("parentwork") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class ParentWorkIntegrationTest(PluginTestCase): + plugin = "parentwork" # test how it works with real musicbrainz data @unittest.skipUnless( @@ -180,18 +173,18 @@ class ParentWorkIntegrationTest(BeetsTestCase): ) -class ParentWorkTest(BeetsTestCase): +class ParentWorkTest(PluginTestCase): + plugin = "parentwork" + def setUp(self): """Set up configuration""" super().setUp() - self.load_plugins("parentwork") self.patcher = patch( "musicbrainzngs.get_work_by_id", side_effect=mock_workid_response ) self.patcher.start() def tearDown(self): - self.unload_plugins() super().tearDown() self.patcher.stop() diff --git a/test/plugins/test_permissions.py b/test/plugins/test_permissions.py index 14ac77cfc..c1655ca11 100644 --- a/test/plugins/test_permissions.py +++ b/test/plugins/test_permissions.py @@ -7,7 +7,7 @@ import unittest from unittest.mock import Mock, patch from beets.test._common import touch -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beets.util import displayable_path from beetsplug.permissions import ( check_permissions, @@ -16,17 +16,14 @@ from beetsplug.permissions import ( ) -class PermissionsPluginTest(BeetsTestCase): +class PermissionsPluginTest(PluginTestCase): + plugin = "permissions" + def setUp(self): super().setUp() - self.load_plugins("permissions") self.config["permissions"] = {"file": "777", "dir": "777"} - def tearDown(self): - super().tearDown() - self.unload_plugins() - def test_permissions_on_album_imported(self): self.do_thing(True) diff --git a/test/plugins/test_play.py b/test/plugins/test_play.py index 563cb7f3a..9c15e8550 100644 --- a/test/plugins/test_play.py +++ b/test/plugins/test_play.py @@ -20,27 +20,23 @@ import sys import unittest from unittest.mock import ANY, patch -from beets.test.helper import BeetsTestCase, CleanupModulesMixin, control_stdin +from beets.test.helper import CleanupModulesMixin, PluginTestCase, control_stdin from beets.ui import UserError from beets.util import open_anything from beetsplug.play import PlayPlugin @patch("beetsplug.play.util.interactive_open") -class PlayPluginTest(CleanupModulesMixin, BeetsTestCase): +class PlayPluginTest(CleanupModulesMixin, PluginTestCase): modules = (PlayPlugin.__module__,) + plugin = "play" def setUp(self): super().setUp() - self.load_plugins("play") self.item = self.add_item(album="a nice älbum", title="aNiceTitle") self.lib.add_album([self.item]) self.config["play"]["command"] = "echo" - def tearDown(self): - super().tearDown() - self.unload_plugins() - def run_and_assert( self, open_mock, diff --git a/test/plugins/test_player.py b/test/plugins/test_player.py index f0a3f3b66..4b77d1f5b 100644 --- a/test/plugins/test_player.py +++ b/test/plugins/test_player.py @@ -32,7 +32,7 @@ from unittest import mock import confuse import yaml -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beets.util import bluelet from beetsplug import bpd @@ -277,12 +277,12 @@ def start_server(args, assigned_port, listener_patch): beets.ui.main(args) -class BPDTestHelper(BeetsTestCase): +class BPDTestHelper(PluginTestCase): db_on_disk = True + plugin = "bpd" def setUp(self): super().setUp() - self.load_plugins("bpd") self.item1 = self.add_item( title="Track One Title", track=1, @@ -297,10 +297,6 @@ class BPDTestHelper(BeetsTestCase): ) self.lib.add_album([self.item1, self.item2]) - def tearDown(self): - super().tearDown() - self.unload_plugins() - @contextmanager def run_bpd( self, diff --git a/test/plugins/test_plexupdate.py b/test/plugins/test_plexupdate.py index ba4890dbe..c27ff7fc3 100644 --- a/test/plugins/test_plexupdate.py +++ b/test/plugins/test_plexupdate.py @@ -2,11 +2,13 @@ import unittest import responses -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase from beetsplug.plexupdate import get_music_section, update_plex -class PlexUpdateTest(BeetsTestCase): +class PlexUpdateTest(PluginTestCase): + plugin = "plexupdate" + def add_response_get_music_section(self, section_name="Music"): """Create response for mocking the get_music_section function.""" @@ -74,14 +76,9 @@ class PlexUpdateTest(BeetsTestCase): def setUp(self): super().setUp() - self.load_plugins("plexupdate") self.config["plex"] = {"host": "localhost", "port": 32400} - def tearDown(self): - super().tearDown() - self.unload_plugins() - @responses.activate def test_get_music_section(self): # Adding response. diff --git a/test/plugins/test_smartplaylist.py b/test/plugins/test_smartplaylist.py index f2aa5e1ab..0c37f1bd1 100644 --- a/test/plugins/test_smartplaylist.py +++ b/test/plugins/test_smartplaylist.py @@ -23,7 +23,7 @@ from beets import config from beets.dbcore import OrQuery from beets.dbcore.query import FixedFieldSort, MultipleSort, NullSort from beets.library import Album, Item, parse_query_string -from beets.test.helper import BeetsTestCase +from beets.test.helper import BeetsTestCase, PluginTestCase from beets.ui import UserError from beets.util import CHAR_REPLACE, bytestring_path, syspath from beetsplug.smartplaylist import SmartPlaylistPlugin @@ -338,7 +338,9 @@ class SmartPlaylistTest(BeetsTestCase): self.assertEqual(content, b"http://beets:8337/item/3/file\n") -class SmartPlaylistCLITest(BeetsTestCase): +class SmartPlaylistCLITest(PluginTestCase): + plugin = "smartplaylist" + def setUp(self): super().setUp() @@ -350,11 +352,6 @@ class SmartPlaylistCLITest(BeetsTestCase): ] ) config["smartplaylist"]["playlist_dir"].set(fsdecode(self.temp_dir)) - self.load_plugins("smartplaylist") - - def tearDown(self): - self.unload_plugins() - super().tearDown() def test_splupdate(self): with self.assertRaises(UserError): diff --git a/test/plugins/test_types_plugin.py b/test/plugins/test_types_plugin.py index 2f00ec425..13f166932 100644 --- a/test/plugins/test_types_plugin.py +++ b/test/plugins/test_types_plugin.py @@ -19,17 +19,11 @@ from datetime import datetime from confuse import ConfigValueError -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase -class TypesPluginTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.load_plugins("types") - - def tearDown(self): - self.unload_plugins() - super().tearDown() +class TypesPluginTest(PluginTestCase): + plugin = "types" def test_integer_modify_and_query(self): self.config["types"] = {"myint": "int"} diff --git a/test/test_importer.py b/test/test_importer.py index 980060488..609887ced 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -38,25 +38,22 @@ from beets.test.helper import ( AutotagStub, BeetsTestCase, ImportTestCase, + PluginMixin, capture_log, has_program, ) from beets.util import bytestring_path, displayable_path, syspath -class ScrubbedImportTest(ImportTestCase): +class ScrubbedImportTest(PluginMixin, ImportTestCase): db_on_disk = True + plugin = "scrub" def setUp(self): super().setUp() - self.load_plugins("scrub") self._create_import_dir(2) self._setup_import_session(autotag=False) - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_tags_not_scrubbed(self): config["plugins"] = ["scrub"] config["scrub"]["auto"] = False diff --git a/test/test_logging.py b/test/test_logging.py index 97786ec18..e7a4a6cad 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -10,7 +10,7 @@ import beets.logging as blog import beetsplug from beets import plugins, ui from beets.test import _common, helper -from beets.test.helper import BeetsTestCase +from beets.test.helper import BeetsTestCase, PluginTestCase class LoggingTest(BeetsTestCase): @@ -47,7 +47,8 @@ class LoggingTest(BeetsTestCase): self.assertTrue(stream.getvalue(), "foo oof baz") -class LoggingLevelTest(BeetsTestCase): +class LoggingLevelTest(PluginTestCase): + plugin = "dummy" class DummyModule: class DummyPlugin(plugins.BeetsPlugin): def __init__(self): @@ -75,10 +76,8 @@ class LoggingLevelTest(BeetsTestCase): sys.modules["beetsplug.dummy"] = self.DummyModule beetsplug.dummy = self.DummyModule super().setUp() - self.load_plugins("dummy") def tearDown(self): - self.unload_plugins() super().tearDown() del beetsplug.dummy sys.modules.pop("beetsplug.dummy") diff --git a/test/test_metasync.py b/test/test_metasync.py index f320d4a5e..146d89943 100644 --- a/test/test_metasync.py +++ b/test/test_metasync.py @@ -21,7 +21,7 @@ from datetime import datetime from beets.library import Item from beets.test import _common -from beets.test.helper import BeetsTestCase +from beets.test.helper import PluginTestCase def _parsetime(s): @@ -32,7 +32,8 @@ def _is_windows(): return platform.system() == "Windows" -class MetaSyncTest(BeetsTestCase): +class MetaSyncTest(PluginTestCase): + plugin = "metasync" itunes_library_unix = os.path.join(_common.RSRC, b"itunes_library_unix.xml") itunes_library_windows = os.path.join( _common.RSRC, b"itunes_library_windows.xml" @@ -40,7 +41,6 @@ class MetaSyncTest(BeetsTestCase): def setUp(self): super().setUp() - self.load_plugins("metasync") self.config["metasync"]["source"] = "itunes" @@ -83,10 +83,6 @@ class MetaSyncTest(BeetsTestCase): for item in items: self.lib.add(item) - def tearDown(self): - self.unload_plugins() - super().tearDown() - def test_load_item_types(self): # This test also verifies that the MetaSources have loaded correctly self.assertIn("amarok_score", Item._types) diff --git a/test/test_plugins.py b/test/test_plugins.py index bda12c2d2..abc6a6968 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -31,12 +31,9 @@ from beets.importer import ( from beets.library import Item from beets.plugins import MetadataSourcePlugin from beets.test import helper -from beets.test.helper import ( - AutotagStub, - BeetsTestCase, - ImportHelper, - TerminalImportMixin, -) +from beets.test.helper import AutotagStub, ImportHelper +from beets.test.helper import PluginTestCase as BasePluginTestCase +from beets.test.helper import TerminalImportMixin from beets.util import displayable_path, syspath from beets.util.id_extractors import ( beatport_id_regex, @@ -45,11 +42,10 @@ from beets.util.id_extractors import ( ) -class PluginLoaderTestCase(BeetsTestCase): +class PluginLoaderTestCase(BasePluginTestCase): def setup_plugin_loader(self): # FIXME the mocking code is horrific, but this is the lowest and # earliest level of the plugin mechanism we can hook into. - self.load_plugins() self._plugin_loader_patch = patch("beets.plugins.load_plugins") self._plugin_classes = set() load_plugins = self._plugin_loader_patch.start() @@ -58,17 +54,16 @@ class PluginLoaderTestCase(BeetsTestCase): plugins._classes.update(self._plugin_classes) load_plugins.side_effect = myload - super().setUp() def teardown_plugin_loader(self): self._plugin_loader_patch.stop() - self.unload_plugins() def register_plugin(self, plugin_class): self._plugin_classes.add(plugin_class) def setUp(self): self.setup_plugin_loader() + super().setUp() def tearDown(self): self.teardown_plugin_loader() @@ -174,7 +169,6 @@ class EventsTest(PluginImportTestCase): with helper.capture_log() as logs: self.importer.run() - self.unload_plugins() # Exactly one event should have been imported (for the album). # Sentinels do not get emitted. @@ -226,7 +220,6 @@ class EventsTest(PluginImportTestCase): with helper.capture_log() as logs: self.importer.run() - self.unload_plugins() # Exactly one event should have been imported (for the album). # Sentinels do not get emitted.