Use unittest.TestCase for tests that don't require the dir setup

This commit is contained in:
Šarūnas Nejus 2025-05-26 12:40:38 +01:00
parent e439c04d89
commit c9f98fca55
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
13 changed files with 28 additions and 29 deletions

View file

@ -18,6 +18,7 @@ from __future__ import annotations
import os import os
import shutil import shutil
import unittest
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from unittest.mock import patch from unittest.mock import patch
@ -1012,7 +1013,7 @@ class ArtForAlbumTest(UseThePlugin):
self._assert_image_operated(self.IMG_348x348, self.RESIZE_OP, True) 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, """While refactoring the plugin, the remote_priority option was deprecated,
and a new codepath should translate its effect. Check that it actually does and a new codepath should translate its effect. Check that it actually does
so. so.
@ -1030,7 +1031,7 @@ class DeprecatedConfigTest(BeetsTestCase):
assert isinstance(self.plugin.sources[-1], fetchart.FileSystem) assert isinstance(self.plugin.sources[-1], fetchart.FileSystem)
class EnforceRatioConfigTest(BeetsTestCase): class EnforceRatioConfigTest(unittest.TestCase):
"""Throw some data at the regexes.""" """Throw some data at the regexes."""
def _load_with_config(self, values, should_raise): def _load_with_config(self, values, should_raise):

View file

@ -14,6 +14,7 @@
"""Tests for the 'beatport' plugin.""" """Tests for the 'beatport' plugin."""
import unittest
from datetime import timedelta from datetime import timedelta
from beets.test import _common from beets.test import _common
@ -585,7 +586,7 @@ class BeatportTest(BeetsTestCase):
assert track.genre == test_track.genre assert track.genre == test_track.genre
class BeatportResponseEmptyTest(BeetsTestCase): class BeatportResponseEmptyTest(unittest.TestCase):
def _make_tracks_response(self): def _make_tracks_response(self):
results = [ results = [
{ {

View file

@ -14,17 +14,17 @@
"""Tests for the 'lastgenre' plugin.""" """Tests for the 'lastgenre' plugin."""
import unittest
from unittest.mock import Mock from unittest.mock import Mock
import pytest import pytest
from beets import config from beets import config
from beets.test import _common from beets.test import _common
from beets.test.helper import BeetsTestCase
from beetsplug import lastgenre from beetsplug import lastgenre
class LastGenrePluginTest(BeetsTestCase): class LastGenrePluginTest(unittest.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.plugin = lastgenre.LastGenrePlugin() self.plugin = lastgenre.LastGenrePlugin()

View file

@ -14,6 +14,7 @@
"""Tests for MusicBrainz API wrapper.""" """Tests for MusicBrainz API wrapper."""
import unittest
from unittest import mock from unittest import mock
import pytest import pytest
@ -665,7 +666,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert t[1].trackdisambig == "SECOND TRACK" assert t[1].trackdisambig == "SECOND TRACK"
class ArtistFlatteningTest(BeetsTestCase): class ArtistFlatteningTest(unittest.TestCase):
def _credit_dict(self, suffix=""): def _credit_dict(self, suffix=""):
return { return {
"artist": { "artist": {

View file

@ -1,11 +1,11 @@
"""Tests for the 'subsonic' plugin.""" """Tests for the 'subsonic' plugin."""
import unittest
from urllib.parse import parse_qs, urlparse from urllib.parse import parse_qs, urlparse
import responses import responses
from beets import config from beets import config
from beets.test.helper import BeetsTestCase
from beetsplug import subsonicupdate from beetsplug import subsonicupdate
@ -24,7 +24,7 @@ def _params(url):
return parse_qs(urlparse(url).query) return parse_qs(urlparse(url).query)
class SubsonicPluginTest(BeetsTestCase): class SubsonicPluginTest(unittest.TestCase):
"""Test class for subsonicupdate.""" """Test class for subsonicupdate."""
@responses.activate @responses.activate

View file

@ -1,11 +1,12 @@
"""Tests for the 'the' plugin""" """Tests for the 'the' plugin"""
import unittest
from beets import config from beets import config
from beets.test.helper import BeetsTestCase
from beetsplug.the import FORMAT, PATTERN_A, PATTERN_THE, ThePlugin from beetsplug.the import FORMAT, PATTERN_A, PATTERN_THE, ThePlugin
class ThePluginTest(BeetsTestCase): class ThePluginTest(unittest.TestCase):
def test_unthe_with_default_patterns(self): def test_unthe_with_default_patterns(self):
assert ThePlugin().unthe("", PATTERN_THE) == "" assert ThePlugin().unthe("", PATTERN_THE) == ""
assert ( assert (

View file

@ -200,7 +200,7 @@ class MoveTest(BeetsTestCase):
assert self.i.path == util.normpath(self.dest) assert self.i.path == util.normpath(self.dest)
class HelperTest(BeetsTestCase): class HelperTest(unittest.TestCase):
def test_ancestry_works_on_file(self): def test_ancestry_works_on_file(self):
p = "/a/b/c" p = "/a/b/c"
a = ["/", "/a", "/a/b"] a = ["/", "/a", "/a/b"]

View file

@ -924,7 +924,7 @@ class ChooseCandidateTest(AutotagImportTestCase):
assert self.lib.albums().get().album == "Applied Album MM" assert self.lib.albums().get().album == "Applied Album MM"
class InferAlbumDataTest(BeetsTestCase): class InferAlbumDataTest(unittest.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@ -1220,7 +1220,7 @@ class ImportDuplicateSingletonTest(ImportTestCase):
return item return item
class TagLogTest(BeetsTestCase): class TagLogTest(unittest.TestCase):
def test_tag_log_line(self): def test_tag_log_line(self):
sio = StringIO() sio = StringIO()
handler = logging.StreamHandler(sio) handler = logging.StreamHandler(sio)

View file

@ -3,21 +3,17 @@
import logging as log import logging as log
import sys import sys
import threading import threading
import unittest
from io import StringIO from io import StringIO
import beets.logging as blog import beets.logging as blog
import beetsplug import beetsplug
from beets import plugins, ui from beets import plugins, ui
from beets.test import _common, helper from beets.test import _common, helper
from beets.test.helper import ( from beets.test.helper import AsIsImporterMixin, ImportTestCase, PluginMixin
AsIsImporterMixin,
BeetsTestCase,
ImportTestCase,
PluginMixin,
)
class LoggingTest(BeetsTestCase): class LoggingTest(unittest.TestCase):
def test_logging_management(self): def test_logging_management(self):
l1 = log.getLogger("foo123") l1 = log.getLogger("foo123")
l2 = blog.getLogger("foo123") l2 = blog.getLogger("foo123")

View file

@ -373,7 +373,7 @@ class GetTest(DummyDataTestCase):
dbcore.query.RegexpQuery("year", "199(") dbcore.query.RegexpQuery("year", "199(")
class MatchTest(BeetsTestCase): class MatchTest(unittest.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.item = _common.item() self.item = _common.item()
@ -811,7 +811,7 @@ class NoneQueryTest(BeetsTestCase, AssertsMixin):
self.assertInResult(item, matched) self.assertInResult(item, matched)
class NotQueryMatchTest(BeetsTestCase): class NotQueryMatchTest(unittest.TestCase):
"""Test `query.NotQuery` matching against a single item, using the same """Test `query.NotQuery` matching against a single item, using the same
cases and assertions as on `MatchTest`, plus assertion on the negated cases and assertions as on `MatchTest`, plus assertion on the negated
queries (ie. assert q -> assert not NotQuery(q)). queries (ie. assert q -> assert not NotQuery(q)).

View file

@ -378,7 +378,7 @@ class ConfigSortTest(DummyDataTestCase):
assert results[0].albumartist > results[1].albumartist 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 """If case_insensitive is false, lower-case values should be placed
after all upper-case values. E.g., `Foo Qux bar` after all upper-case values. E.g., `Foo Qux bar`
""" """

View file

@ -1337,7 +1337,7 @@ class ShowChangeTest(BeetsTestCase):
@patch("beets.library.Item.try_filesize", Mock(return_value=987)) @patch("beets.library.Item.try_filesize", Mock(return_value=987))
class SummarizeItemsTest(BeetsTestCase): class SummarizeItemsTest(unittest.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
item = library.Item() item = library.Item()
@ -1374,7 +1374,7 @@ class SummarizeItemsTest(BeetsTestCase):
assert summary == "3 items, G 2, F 1, 4kbps, 32:42, 2.9 KiB" 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): def test_custom_paths_prepend(self):
default_formats = ui.get_path_formats() default_formats = ui.get_path_formats()
@ -1521,7 +1521,7 @@ class CommonOptionsParserCliTest(BeetsTestCase):
# assert 'plugins: ' in output # assert 'plugins: ' in output
class CommonOptionsParserTest(BeetsTestCase): class CommonOptionsParserTest(unittest.TestCase):
def test_album_option(self): def test_album_option(self):
parser = ui.CommonOptionsParser() parser = ui.CommonOptionsParser()
assert not parser._album_flags 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 """Tests for the `terminal_encoding` config option and our
`_in_encoding` and `_out_encoding` utility functions. `_in_encoding` and `_out_encoding` utility functions.
""" """

View file

@ -25,7 +25,6 @@ import pytest
from beets import util from beets import util
from beets.test import _common from beets.test import _common
from beets.test.helper import BeetsTestCase
class UtilTest(unittest.TestCase): class UtilTest(unittest.TestCase):
@ -132,7 +131,7 @@ class UtilTest(unittest.TestCase):
pass pass
class PathConversionTest(BeetsTestCase): class PathConversionTest(unittest.TestCase):
def test_syspath_windows_format(self): def test_syspath_windows_format(self):
with _common.platform_windows(): with _common.platform_windows():
path = os.path.join("a", "b", "c") path = os.path.join("a", "b", "c")