diff --git a/beets/test/helper.py b/beets/test/helper.py index 1499bd125..359ce0485 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -520,20 +520,15 @@ class BeetsTestCase(unittest.TestCase, TestHelper): self.teardown_beets() -class LibTestCase(BeetsTestCase): +class ItemInDBTestCase(BeetsTestCase): """A test case that includes an in-memory library object (`lib`) and an item added to the library (`i`). """ def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.i = _common.item(self.lib) - def tearDown(self): - self.lib._connection().close() - super().tearDown() - class ImportHelper: """Provides tools to setup a library, a directory containing files that are @@ -985,3 +980,4 @@ class CleanupModulesMixin: """Remove files created by the plugin.""" for module in cls.modules: clean_module_tempdir(module) + self.lib = beets.library.Library(":memory:") diff --git a/test/plugins/test_web.py b/test/plugins/test_web.py index c34de05d2..d2eb3f190 100644 --- a/test/plugins/test_web.py +++ b/test/plugins/test_web.py @@ -9,11 +9,11 @@ import unittest from beets import logging from beets.library import Album, Item from beets.test import _common -from beets.test.helper import LibTestCase +from beets.test.helper import ItemInDBTestCase from beetsplug import web -class WebPluginTest(LibTestCase): +class WebPluginTest(ItemInDBTestCase): def setUp(self): super().setUp() self.log = logging.getLogger("beets.web") diff --git a/test/test_datequery.py b/test/test_datequery.py index 56c85e05d..48740420c 100644 --- a/test/test_datequery.py +++ b/test/test_datequery.py @@ -25,7 +25,7 @@ from beets.dbcore.query import ( InvalidQueryArgumentValueError, _parse_periods, ) -from beets.test.helper import LibTestCase +from beets.test.helper import ItemInDBTestCase def _date(string): @@ -152,7 +152,7 @@ def _parsetime(s): return time.mktime(datetime.strptime(s, "%Y-%m-%d %H:%M").timetuple()) -class DateQueryTest(LibTestCase): +class DateQueryTest(ItemInDBTestCase): def setUp(self): super().setUp() self.i.added = _parsetime("2013-03-30 22:21") @@ -187,7 +187,7 @@ class DateQueryTest(LibTestCase): self.assertEqual(len(matched), 0) -class DateQueryTestRelative(LibTestCase): +class DateQueryTestRelative(ItemInDBTestCase): def setUp(self): super().setUp() @@ -233,7 +233,7 @@ class DateQueryTestRelative(LibTestCase): self.assertEqual(len(matched), 0) -class DateQueryTestRelativeMore(LibTestCase): +class DateQueryTestRelativeMore(ItemInDBTestCase): def setUp(self): super().setUp() self.i.added = _parsetime(datetime.now().strftime("%Y-%m-%d %H:%M")) diff --git a/test/test_library.py b/test/test_library.py index 7d27604d6..d224f055c 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -32,14 +32,14 @@ import beets.library from beets import config, plugins, util from beets.test import _common from beets.test._common import item -from beets.test.helper import BeetsTestCase, LibTestCase +from beets.test.helper import BeetsTestCase, ItemInDBTestCase from beets.util import bytestring_path, syspath # Shortcut to path normalization. np = util.normpath -class LoadTest(LibTestCase): +class LoadTest(ItemInDBTestCase): def test_load_restores_data_from_db(self): original_title = self.i.title self.i.title = "something" @@ -53,7 +53,7 @@ class LoadTest(LibTestCase): self.assertNotIn("artist", self.i._dirty) -class StoreTest(LibTestCase): +class StoreTest(ItemInDBTestCase): def test_store_changes_database_value(self): self.i.year = 1987 self.i.store() @@ -126,7 +126,7 @@ class AddTest(BeetsTestCase): self.assertEqual(new_grouping, self.i.grouping) -class RemoveTest(LibTestCase): +class RemoveTest(ItemInDBTestCase): def test_remove_deletes_from_db(self): self.i.remove() c = self.lib._connection().execute("select * from items") @@ -547,7 +547,7 @@ class DestinationTest(BeetsTestCase): self.assertEqual(self.i.destination(), np("one/foo/two")) -class ItemFormattedMappingTest(LibTestCase): +class ItemFormattedMappingTest(ItemInDBTestCase): def test_formatted_item_value(self): formatted = self.i.formatted() self.assertEqual(formatted["artist"], "the artist") @@ -1228,7 +1228,7 @@ class ImportTimeTest(BeetsTestCase): self.assertGreater(self.singleton.added, 0) -class TemplateTest(LibTestCase): +class TemplateTest(ItemInDBTestCase): def test_year_formatted_in_template(self): self.i.year = 123 self.i.store() @@ -1258,7 +1258,7 @@ class TemplateTest(LibTestCase): self.assertEqual(f"{item:$tagada}", "togodo") -class UnicodePathTest(LibTestCase): +class UnicodePathTest(ItemInDBTestCase): def test_unicode_path(self): self.i.path = os.path.join(_common.RSRC, "unicode\u2019d.mp3".encode()) # If there are any problems with unicode paths, we will raise diff --git a/test/test_query.py b/test/test_query.py index a5a2091bf..565719501 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -31,7 +31,7 @@ from beets.dbcore.query import ( ) from beets.library import Item, Library from beets.test import _common -from beets.test.helper import BeetsTestCase, LibTestCase +from beets.test.helper import BeetsTestCase, ItemInDBTestCase from beets.util import syspath # Because the absolute path begins with something like C:, we @@ -55,7 +55,7 @@ class AssertsMixin: self.assertNotIn(item.id, result_ids) -class AnyFieldQueryTest(LibTestCase): +class AnyFieldQueryTest(ItemInDBTestCase): def test_no_restriction(self): q = dbcore.query.AnyFieldQuery( "title", @@ -486,7 +486,7 @@ class MatchTest(BeetsTestCase): self.assertNotEqual(q3, q4) -class PathQueryTest(LibTestCase, AssertsMixin): +class PathQueryTest(ItemInDBTestCase, AssertsMixin): def setUp(self): super().setUp() diff --git a/test/test_ui_commands.py b/test/test_ui_commands.py index dfd8ffad0..a064fcf71 100644 --- a/test/test_ui_commands.py +++ b/test/test_ui_commands.py @@ -22,7 +22,7 @@ import unittest from beets import library, ui from beets.test import _common -from beets.test.helper import BeetsTestCase, LibTestCase +from beets.test.helper import BeetsTestCase, ItemInDBTestCase from beets.ui import commands from beets.util import syspath @@ -88,7 +88,7 @@ class QueryTest(BeetsTestCase): self.check_do_query(0, 2, album=True, also_items=False) -class FieldsTest(LibTestCase): +class FieldsTest(ItemInDBTestCase): def setUp(self): super().setUp() diff --git a/test/test_ui_init.py b/test/test_ui_init.py index df1f36b97..9febd397c 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -23,7 +23,7 @@ from random import random from beets import config, ui from beets.test import _common -from beets.test.helper import BeetsTestCase, LibTestCase, control_stdin +from beets.test.helper import BeetsTestCase, ItemInDBTestCase, control_stdin class InputMethodsTest(BeetsTestCase): @@ -90,7 +90,7 @@ class InputMethodsTest(BeetsTestCase): self.assertEqual(items, ["1", "3"]) -class InitTest(LibTestCase): +class InitTest(ItemInDBTestCase): def setUp(self): super().setUp()