From 0b5b94460a7bb8cf8b8a74eee26ae95d208b701a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 3 Jul 2024 12:01:41 +0100 Subject: [PATCH] Replace unittest.TestCase, ImportHelper by ImportTestCase --- beets/test/helper.py | 6 +++++- test/plugins/test_edit.py | 4 ++-- test/plugins/test_filefilter.py | 4 ++-- test/plugins/test_importadded.py | 4 ++-- test/plugins/test_mbsubmit.py | 7 ++----- test/test_importer.py | 30 +++++++++++++++--------------- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/beets/test/helper.py b/beets/test/helper.py index 6cb45e828..24659d1d7 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -535,7 +535,7 @@ class LibTestCase(BeetsTestCase): super().tearDown() -class ImportHelper(TestHelper): +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 autotagging library and several assertions for the library. @@ -644,6 +644,10 @@ class ImportHelper(TestHelper): self.assertEqual(len(os.listdir(syspath(self.libdir))), 0) +class ImportTestCase(ImportHelper, BeetsTestCase): + pass + + class ImportSessionFixture(importer.ImportSession): """ImportSession that can be controlled programaticaly. diff --git a/test/plugins/test_edit.py b/test/plugins/test_edit.py index 32095748f..7e06e7a1c 100644 --- a/test/plugins/test_edit.py +++ b/test/plugins/test_edit.py @@ -22,7 +22,7 @@ from beets.test import _common from beets.test.helper import ( AutotagStub, BeetsTestCase, - ImportHelper, + ImportTestCase, TerminalImportSessionSetup, control_stdin, ) @@ -323,7 +323,7 @@ class EditCommandTest(BeetsTestCase, EditMixin): @_common.slow_test() class EditDuringImporterTest( - TerminalImportSessionSetup, BeetsTestCase, ImportHelper, EditMixin + TerminalImportSessionSetup, ImportTestCase, EditMixin ): """TODO""" diff --git a/test/plugins/test_filefilter.py b/test/plugins/test_filefilter.py index 10eed77c4..a97fc5f32 100644 --- a/test/plugins/test_filefilter.py +++ b/test/plugins/test_filefilter.py @@ -24,12 +24,12 @@ from mediafile import MediaFile from beets import config from beets.test import _common -from beets.test.helper import ImportHelper, capture_log +from beets.test.helper import ImportTestCase, capture_log from beets.util import bytestring_path, displayable_path, syspath from beetsplug.filefilter import FileFilterPlugin -class FileFilterPluginTest(unittest.TestCase, ImportHelper): +class FileFilterPluginTest(ImportTestCase): def setUp(self): self.setup_beets() self.__create_import_dir(2) diff --git a/test/plugins/test_importadded.py b/test/plugins/test_importadded.py index 647892e1d..baa9f880b 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, ImportHelper +from beets.test.helper import AutotagStub, ImportTestCase from beets.util import displayable_path, syspath from beetsplug.importadded import ImportAddedPlugin @@ -40,7 +40,7 @@ def modify_mtimes(paths, offset=-60000): os.utime(syspath(path), (mstat.st_atime, mstat.st_mtime + offset * i)) -class ImportAddedTest(unittest.TestCase, ImportHelper): +class ImportAddedTest(ImportTestCase): # The minimum mtime of the files to be imported min_mtime = None diff --git a/test/plugins/test_mbsubmit.py b/test/plugins/test_mbsubmit.py index e0821557b..f97e389c5 100644 --- a/test/plugins/test_mbsubmit.py +++ b/test/plugins/test_mbsubmit.py @@ -17,17 +17,14 @@ import unittest from beets.test.helper import ( AutotagStub, - BeetsTestCase, - ImportHelper, + ImportTestCase, TerminalImportSessionSetup, capture_stdout, control_stdin, ) -class MBSubmitPluginTest( - TerminalImportSessionSetup, BeetsTestCase, ImportHelper -): +class MBSubmitPluginTest(TerminalImportSessionSetup, ImportTestCase): def setUp(self): self.setup_beets() self.load_plugins("mbsubmit") diff --git a/test/test_importer.py b/test/test_importer.py index f3a255e4e..95e8fd933 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -37,14 +37,14 @@ from beets.test import _common from beets.test.helper import ( AutotagStub, BeetsTestCase, - ImportHelper, + ImportTestCase, capture_log, has_program, ) from beets.util import bytestring_path, displayable_path, syspath -class ScrubbedImportTest(BeetsTestCase, ImportHelper): +class ScrubbedImportTest(ImportTestCase): def setUp(self): self.setup_beets(disk=True) self.load_plugins("scrub") @@ -99,7 +99,7 @@ class ScrubbedImportTest(BeetsTestCase, ImportHelper): @_common.slow_test() -class NonAutotaggedImportTest(BeetsTestCase, ImportHelper): +class NonAutotaggedImportTest(ImportTestCase): def setUp(self): self.setup_beets(disk=True) self._create_import_dir(2) @@ -271,7 +271,7 @@ def create_archive(session): return path -class RmTempTest(unittest.TestCase, ImportHelper): +class RmTempTest(ImportTestCase): """Tests that temporarily extracted archives are properly removed after usage. """ @@ -296,7 +296,7 @@ class RmTempTest(unittest.TestCase, ImportHelper): self.assertNotExists(tmp_path) -class ImportZipTest(unittest.TestCase, ImportHelper): +class ImportZipTest(ImportTestCase): def setUp(self): self.setup_beets() @@ -344,7 +344,7 @@ class ImportPasswordRarTest(ImportZipTest): return os.path.join(_common.RSRC, b"password.rar") -class ImportSingletonTest(BeetsTestCase, ImportHelper): +class ImportSingletonTest(ImportTestCase): """Test ``APPLY`` and ``ASIS`` choices for an import session with singletons config set to True. """ @@ -467,7 +467,7 @@ class ImportSingletonTest(BeetsTestCase, ImportHelper): self.assertEqual(item.title, "Applied Title 1 - formatted") -class ImportTest(BeetsTestCase, ImportHelper): +class ImportTest(ImportTestCase): """Test APPLY, ASIS and SKIP choices.""" def setUp(self): @@ -681,7 +681,7 @@ class ImportTest(BeetsTestCase, ImportHelper): ) -class ImportTracksTest(BeetsTestCase, ImportHelper): +class ImportTracksTest(ImportTestCase): """Test TRACKS and APPLY choice.""" def setUp(self): @@ -715,7 +715,7 @@ class ImportTracksTest(BeetsTestCase, ImportHelper): self.assert_file_in_lib(b"singletons", b"Applied Title 1.mp3") -class ImportCompilationTest(BeetsTestCase, ImportHelper): +class ImportCompilationTest(ImportTestCase): """Test ASIS import of a folder containing tracks with different artists.""" def setUp(self): @@ -834,7 +834,7 @@ class ImportCompilationTest(BeetsTestCase, ImportHelper): self.assertTrue(asserted_multi_artists_0 and asserted_multi_artists_1) -class ImportExistingTest(BeetsTestCase, ImportHelper): +class ImportExistingTest(ImportTestCase): """Test importing files that are already in the library directory.""" def setUp(self): @@ -959,7 +959,7 @@ class ImportExistingTest(BeetsTestCase, ImportHelper): self.assertNotExists(self.import_media[0].path) -class GroupAlbumsImportTest(BeetsTestCase, ImportHelper): +class GroupAlbumsImportTest(ImportTestCase): def setUp(self): self.setup_beets() self._create_import_dir(3) @@ -1031,7 +1031,7 @@ class GlobalGroupAlbumsImportTest(GroupAlbumsImportTest): config["import"]["group_albums"] = True -class ChooseCandidateTest(BeetsTestCase, ImportHelper): +class ChooseCandidateTest(ImportTestCase): def setUp(self): self.setup_beets() self._create_import_dir(1) @@ -1646,7 +1646,7 @@ class MultiDiscAlbumsInDirTest(BeetsTestCase): self.assertEqual(len(items), 3) -class ReimportTest(unittest.TestCase, ImportHelper): +class ReimportTest(ImportTestCase): """Test "re-imports", in which the autotagging machinery is used for music that's already in the library. @@ -1751,7 +1751,7 @@ class ReimportTest(unittest.TestCase, ImportHelper): self.assertEqual(self._album().data_source, "match_source") -class ImportPretendTest(BeetsTestCase, ImportHelper): +class ImportPretendTest(ImportTestCase): """Test the pretend commandline option""" def __init__(self, method_name="runTest"): @@ -1944,7 +1944,7 @@ def mocked_get_recording_by_id( "musicbrainzngs.get_release_by_id", Mock(side_effect=mocked_get_release_by_id), ) -class ImportMusicBrainzIdTest(BeetsTestCase, ImportHelper): +class ImportMusicBrainzIdTest(ImportTestCase): """Test the --musicbrainzid argument.""" MB_RELEASE_PREFIX = "https://musicbrainz.org/release/"