From c9f98fca5550add0942cbaf10d16b0e753002fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 26 May 2025 12:40:38 +0100 Subject: [PATCH] Use unittest.TestCase for tests that don't require the dir setup --- test/plugins/test_art.py | 5 +++-- test/plugins/test_beatport.py | 3 ++- test/plugins/test_lastgenre.py | 4 ++-- test/plugins/test_musicbrainz.py | 3 ++- test/plugins/test_subsonicupdate.py | 4 ++-- test/plugins/test_the.py | 5 +++-- test/test_files.py | 2 +- test/test_importer.py | 4 ++-- test/test_logging.py | 10 +++------- test/test_query.py | 4 ++-- test/test_sort.py | 2 +- test/test_ui.py | 8 ++++---- test/test_util.py | 3 +-- 13 files changed, 28 insertions(+), 29 deletions(-) diff --git a/test/plugins/test_art.py b/test/plugins/test_art.py index b8a9a3bda..6577b54fc 100644 --- a/test/plugins/test_art.py +++ b/test/plugins/test_art.py @@ -18,6 +18,7 @@ from __future__ import annotations import os import shutil +import unittest from typing import TYPE_CHECKING from unittest.mock import patch @@ -1012,7 +1013,7 @@ class ArtForAlbumTest(UseThePlugin): self._assert_image_operated(self.IMG_348x348, self.RESIZE_OP, True) -class DeprecatedConfigTest(BeetsTestCase): +class DeprecatedConfigTest(unittest.TestCase): """While refactoring the plugin, the remote_priority option was deprecated, and a new codepath should translate its effect. Check that it actually does so. @@ -1030,7 +1031,7 @@ class DeprecatedConfigTest(BeetsTestCase): assert isinstance(self.plugin.sources[-1], fetchart.FileSystem) -class EnforceRatioConfigTest(BeetsTestCase): +class EnforceRatioConfigTest(unittest.TestCase): """Throw some data at the regexes.""" def _load_with_config(self, values, should_raise): diff --git a/test/plugins/test_beatport.py b/test/plugins/test_beatport.py index d072340b5..b92a3bf15 100644 --- a/test/plugins/test_beatport.py +++ b/test/plugins/test_beatport.py @@ -14,6 +14,7 @@ """Tests for the 'beatport' plugin.""" +import unittest from datetime import timedelta from beets.test import _common @@ -585,7 +586,7 @@ class BeatportTest(BeetsTestCase): assert track.genre == test_track.genre -class BeatportResponseEmptyTest(BeetsTestCase): +class BeatportResponseEmptyTest(unittest.TestCase): def _make_tracks_response(self): results = [ { diff --git a/test/plugins/test_lastgenre.py b/test/plugins/test_lastgenre.py index 49d219de9..d34860774 100644 --- a/test/plugins/test_lastgenre.py +++ b/test/plugins/test_lastgenre.py @@ -14,17 +14,17 @@ """Tests for the 'lastgenre' plugin.""" +import unittest from unittest.mock import Mock import pytest from beets import config from beets.test import _common -from beets.test.helper import BeetsTestCase from beetsplug import lastgenre -class LastGenrePluginTest(BeetsTestCase): +class LastGenrePluginTest(unittest.TestCase): def setUp(self): super().setUp() self.plugin = lastgenre.LastGenrePlugin() diff --git a/test/plugins/test_musicbrainz.py b/test/plugins/test_musicbrainz.py index d9a06d00a..100cfc498 100644 --- a/test/plugins/test_musicbrainz.py +++ b/test/plugins/test_musicbrainz.py @@ -14,6 +14,7 @@ """Tests for MusicBrainz API wrapper.""" +import unittest from unittest import mock import pytest @@ -665,7 +666,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase): assert t[1].trackdisambig == "SECOND TRACK" -class ArtistFlatteningTest(BeetsTestCase): +class ArtistFlatteningTest(unittest.TestCase): def _credit_dict(self, suffix=""): return { "artist": { diff --git a/test/plugins/test_subsonicupdate.py b/test/plugins/test_subsonicupdate.py index 891f75cb7..183c2bd67 100644 --- a/test/plugins/test_subsonicupdate.py +++ b/test/plugins/test_subsonicupdate.py @@ -1,11 +1,11 @@ """Tests for the 'subsonic' plugin.""" +import unittest from urllib.parse import parse_qs, urlparse import responses from beets import config -from beets.test.helper import BeetsTestCase from beetsplug import subsonicupdate @@ -24,7 +24,7 @@ def _params(url): return parse_qs(urlparse(url).query) -class SubsonicPluginTest(BeetsTestCase): +class SubsonicPluginTest(unittest.TestCase): """Test class for subsonicupdate.""" @responses.activate diff --git a/test/plugins/test_the.py b/test/plugins/test_the.py index bf073301b..c8f919de2 100644 --- a/test/plugins/test_the.py +++ b/test/plugins/test_the.py @@ -1,11 +1,12 @@ """Tests for the 'the' plugin""" +import unittest + from beets import config -from beets.test.helper import BeetsTestCase from beetsplug.the import FORMAT, PATTERN_A, PATTERN_THE, ThePlugin -class ThePluginTest(BeetsTestCase): +class ThePluginTest(unittest.TestCase): def test_unthe_with_default_patterns(self): assert ThePlugin().unthe("", PATTERN_THE) == "" assert ( diff --git a/test/test_files.py b/test/test_files.py index 72b1610c0..8be94f328 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -200,7 +200,7 @@ class MoveTest(BeetsTestCase): assert self.i.path == util.normpath(self.dest) -class HelperTest(BeetsTestCase): +class HelperTest(unittest.TestCase): def test_ancestry_works_on_file(self): p = "/a/b/c" a = ["/", "/a", "/a/b"] diff --git a/test/test_importer.py b/test/test_importer.py index 5070a058d..9bb0e8a63 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -924,7 +924,7 @@ class ChooseCandidateTest(AutotagImportTestCase): assert self.lib.albums().get().album == "Applied Album MM" -class InferAlbumDataTest(BeetsTestCase): +class InferAlbumDataTest(unittest.TestCase): def setUp(self): super().setUp() @@ -1220,7 +1220,7 @@ class ImportDuplicateSingletonTest(ImportTestCase): return item -class TagLogTest(BeetsTestCase): +class TagLogTest(unittest.TestCase): def test_tag_log_line(self): sio = StringIO() handler = logging.StreamHandler(sio) diff --git a/test/test_logging.py b/test/test_logging.py index d95a54387..1859ea2dd 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -3,21 +3,17 @@ import logging as log import sys import threading +import unittest from io import StringIO import beets.logging as blog import beetsplug from beets import plugins, ui from beets.test import _common, helper -from beets.test.helper import ( - AsIsImporterMixin, - BeetsTestCase, - ImportTestCase, - PluginMixin, -) +from beets.test.helper import AsIsImporterMixin, ImportTestCase, PluginMixin -class LoggingTest(BeetsTestCase): +class LoggingTest(unittest.TestCase): def test_logging_management(self): l1 = log.getLogger("foo123") l2 = blog.getLogger("foo123") diff --git a/test/test_query.py b/test/test_query.py index f85e5c637..22c2710de 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -373,7 +373,7 @@ class GetTest(DummyDataTestCase): dbcore.query.RegexpQuery("year", "199(") -class MatchTest(BeetsTestCase): +class MatchTest(unittest.TestCase): def setUp(self): super().setUp() self.item = _common.item() @@ -811,7 +811,7 @@ class NoneQueryTest(BeetsTestCase, AssertsMixin): self.assertInResult(item, matched) -class NotQueryMatchTest(BeetsTestCase): +class NotQueryMatchTest(unittest.TestCase): """Test `query.NotQuery` matching against a single item, using the same cases and assertions as on `MatchTest`, plus assertion on the negated queries (ie. assert q -> assert not NotQuery(q)). diff --git a/test/test_sort.py b/test/test_sort.py index d6aa5c518..25d993e30 100644 --- a/test/test_sort.py +++ b/test/test_sort.py @@ -378,7 +378,7 @@ class ConfigSortTest(DummyDataTestCase): assert results[0].albumartist > results[1].albumartist -class CaseSensitivityTest(DummyDataTestCase, BeetsTestCase): +class CaseSensitivityTest(DummyDataTestCase): """If case_insensitive is false, lower-case values should be placed after all upper-case values. E.g., `Foo Qux bar` """ diff --git a/test/test_ui.py b/test/test_ui.py index afa16e171..8bb0218d5 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -1337,7 +1337,7 @@ class ShowChangeTest(BeetsTestCase): @patch("beets.library.Item.try_filesize", Mock(return_value=987)) -class SummarizeItemsTest(BeetsTestCase): +class SummarizeItemsTest(unittest.TestCase): def setUp(self): super().setUp() item = library.Item() @@ -1374,7 +1374,7 @@ class SummarizeItemsTest(BeetsTestCase): assert summary == "3 items, G 2, F 1, 4kbps, 32:42, 2.9 KiB" -class PathFormatTest(BeetsTestCase): +class PathFormatTest(unittest.TestCase): def test_custom_paths_prepend(self): default_formats = ui.get_path_formats() @@ -1521,7 +1521,7 @@ class CommonOptionsParserCliTest(BeetsTestCase): # assert 'plugins: ' in output -class CommonOptionsParserTest(BeetsTestCase): +class CommonOptionsParserTest(unittest.TestCase): def test_album_option(self): parser = ui.CommonOptionsParser() assert not parser._album_flags @@ -1614,7 +1614,7 @@ class CommonOptionsParserTest(BeetsTestCase): ) -class EncodingTest(BeetsTestCase): +class EncodingTest(unittest.TestCase): """Tests for the `terminal_encoding` config option and our `_in_encoding` and `_out_encoding` utility functions. """ diff --git a/test/test_util.py b/test/test_util.py index 6b795b957..d08868619 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -25,7 +25,6 @@ import pytest from beets import util from beets.test import _common -from beets.test.helper import BeetsTestCase class UtilTest(unittest.TestCase): @@ -132,7 +131,7 @@ class UtilTest(unittest.TestCase): pass -class PathConversionTest(BeetsTestCase): +class PathConversionTest(unittest.TestCase): def test_syspath_windows_format(self): with _common.platform_windows(): path = os.path.join("a", "b", "c")