diff --git a/beets/test/helper.py b/beets/test/helper.py index 359ce0485..4f62055e7 100644 --- a/beets/test/helper.py +++ b/beets/test/helper.py @@ -470,11 +470,11 @@ class TestHelper(_common.Assertions): # Safe file operations - def create_temp_dir(self): + def create_temp_dir(self, **kwargs): """Create a temporary directory and assign it into `self.temp_dir`. Call `remove_temp_dir` later to delete it. """ - temp_dir = mkdtemp() + temp_dir = mkdtemp(**kwargs) self.temp_dir = util.bytestring_path(temp_dir) def remove_temp_dir(self): @@ -980,4 +980,3 @@ 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_art.py b/test/plugins/test_art.py index 4d631aa38..3e9f016da 100644 --- a/test/plugins/test_art.py +++ b/test/plugins/test_art.py @@ -23,7 +23,7 @@ from unittest.mock import patch import confuse import responses -from beets import config, importer, library, logging, util +from beets import config, importer, logging, util from beets.autotag import AlbumInfo, AlbumMatch from beets.test import _common from beets.test.helper import ( @@ -736,16 +736,12 @@ class ArtImporterTest(UseThePlugin): self.plugin.art_for_album = art_for_album # Test library. - self.libpath = os.path.join(self.temp_dir, b"tmplib.blb") - self.libdir = os.path.join(self.temp_dir, b"tmplib") - os.mkdir(syspath(self.libdir)) os.mkdir(syspath(os.path.join(self.libdir, b"album"))) itempath = os.path.join(self.libdir, b"album", b"test.mp3") shutil.copyfile( syspath(os.path.join(_common.RSRC, b"full.mp3")), syspath(itempath), ) - self.lib = library.Library(self.libpath) self.i = _common.item() self.i.path = itempath self.album = self.lib.add_album([self.i]) @@ -768,7 +764,6 @@ class ArtImporterTest(UseThePlugin): self.task.set_choice(AlbumMatch(0, info, {}, set(), set())) def tearDown(self): - self.lib._connection().close() super().tearDown() self.plugin.art_for_album = self.old_afa diff --git a/test/plugins/test_beatport.py b/test/plugins/test_beatport.py index 98807e9c8..6a4cc5216 100644 --- a/test/plugins/test_beatport.py +++ b/test/plugins/test_beatport.py @@ -18,7 +18,6 @@ import unittest from datetime import timedelta -from beets import library from beets.test import _common from beets.test.helper import BeetsTestCase from beetsplug import beatport @@ -452,7 +451,6 @@ class BeatportTest(BeetsTestCase): def setUp(self): super().setUp() self.load_plugins("beatport") - self.lib = library.Library(":memory:") # Set up 'album'. response_release = self._make_release_response() @@ -630,7 +628,6 @@ class BeatportResponseEmptyTest(BeetsTestCase): def setUp(self): super().setUp() self.load_plugins("beatport") - self.lib = library.Library(":memory:") # Set up 'tracks'. self.response_tracks = self._make_tracks_response() diff --git a/test/plugins/test_importfeeds.py b/test/plugins/test_importfeeds.py index 7d95a150b..a8985d0bf 100644 --- a/test/plugins/test_importfeeds.py +++ b/test/plugins/test_importfeeds.py @@ -1,27 +1,21 @@ import datetime import os import os.path -import shutil -import tempfile import unittest from beets import config -from beets.library import Album, Item, Library +from beets.library import Album, Item +from beets.test.helper import BeetsTestCase from beetsplug.importfeeds import ImportFeedsPlugin -class ImportfeedsTestTest(unittest.TestCase): +class ImportfeedsTestTest(BeetsTestCase): def setUp(self): - config.clear() - config.read(user=False) + super().setUp() self.importfeeds = ImportFeedsPlugin() - self.lib = Library(":memory:") - self.feeds_dir = tempfile.mkdtemp() + self.feeds_dir = os.path.join(os.fsdecode(self.temp_dir), "importfeeds") config["importfeeds"]["dir"] = self.feeds_dir - def tearDown(self): - shutil.rmtree(self.feeds_dir) - def test_multi_format_album_playlist(self): config["importfeeds"]["formats"] = "m3u_multi" album = Album(album="album/name", id=1) diff --git a/test/plugins/test_ipfs.py b/test/plugins/test_ipfs.py index cd23b65ad..928b193f3 100644 --- a/test/plugins/test_ipfs.py +++ b/test/plugins/test_ipfs.py @@ -16,7 +16,6 @@ import os import unittest from unittest.mock import Mock, patch -from beets import library from beets.test import _common from beets.test.helper import BeetsTestCase from beets.util import _fsencoding, bytestring_path @@ -28,7 +27,6 @@ class IPFSPluginTest(BeetsTestCase): def setUp(self): super().setUp() self.load_plugins("ipfs") - self.lib = library.Library(":memory:") def tearDown(self): self.unload_plugins() diff --git a/test/plugins/test_playlist.py b/test/plugins/test_playlist.py index c7a2caa96..74befd71f 100644 --- a/test/plugins/test_playlist.py +++ b/test/plugins/test_playlist.py @@ -25,7 +25,6 @@ from beets.test.helper import BeetsTestCase class PlaylistTestCase(BeetsTestCase): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.music_dir = os.path.expanduser(os.path.join("~", "Music")) diff --git a/test/test_files.py b/test/test_files.py index 68971cd85..acece24d0 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -41,14 +41,10 @@ class MoveTest(BeetsTestCase): ) # add it to a temporary library - self.lib = beets.library.Library(":memory:") self.i = beets.library.Item.from_path(self.path) self.lib.add(self.i) # set up the destination - self.libdir = join(self.temp_dir, b"testlibdir") - os.mkdir(syspath(self.libdir)) - self.lib.directory = self.libdir self.lib.path_formats = [ ("default", join("$artist", "$album", "$title")) ] @@ -250,12 +246,9 @@ class AlbumFileTest(BeetsTestCase): super().setUp() # Make library and item. - self.lib = beets.library.Library(":memory:") self.lib.path_formats = [ ("default", join("$albumartist", "$album", "$title")) ] - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - self.lib.directory = self.libdir self.i = item(self.lib) # Make a file for the item. self.i.path = self.i.destination() @@ -317,9 +310,6 @@ class ArtFileTest(BeetsTestCase): super().setUp() # Make library and item. - self.lib = beets.library.Library(":memory:") - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - self.lib.directory = self.libdir self.i = item(self.lib) self.i.path = self.i.destination() # Make a music file. @@ -491,9 +481,6 @@ class RemoveTest(BeetsTestCase): super().setUp() # Make library and item. - self.lib = beets.library.Library(":memory:") - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - self.lib.directory = self.libdir self.i = item(self.lib) self.i.path = self.i.destination() # Make a music file. diff --git a/test/test_library.py b/test/test_library.py index bce4dbb66..e0ded46ba 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -97,7 +97,6 @@ class StoreTest(ItemInDBTestCase): class AddTest(BeetsTestCase): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.i = item() def test_item_add_inserts_row(self): @@ -155,9 +154,8 @@ class GetSetTest(BeetsTestCase): def test_album_fallback(self): # integration test of item-album fallback - lib = beets.library.Library(":memory:") - i = item(lib) - album = lib.add_album([i]) + i = item(self.lib) + album = self.lib.add_album([i]) album["flex"] = "foo" album.store() @@ -170,18 +168,16 @@ class GetSetTest(BeetsTestCase): class DestinationTest(BeetsTestCase): + """Confirm tests handle temporary directory path containing '.'""" + + def create_temp_dir(self, **kwargs): + kwargs["prefix"] = "." + super().create_temp_dir(**kwargs) + def setUp(self): super().setUp() - # default directory is ~/Music and the only reason why it was switched - # to ~/.Music is to confirm that tests works well when path to - # temporary directory contains . - self.lib = beets.library.Library(":memory:", "~/.Music") self.i = item(self.lib) - def tearDown(self): - super().tearDown() - self.lib._connection().close() - def test_directory_works_with_trailing_slash(self): self.lib.directory = b"one/" self.lib.path_formats = [("default", "two")] @@ -623,15 +619,10 @@ class PathFormattingMixin: class DestinationFunctionTest(BeetsTestCase, PathFormattingMixin): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.lib.directory = b"/base" self.lib.path_formats = [("default", "path")] self.i = item(self.lib) - def tearDown(self): - super().tearDown() - self.lib._connection().close() - def test_upper_case_literal(self): self._setf("%upper{foo}") self._assert_dest(b"/base/FOO") @@ -732,7 +723,6 @@ class DestinationFunctionTest(BeetsTestCase, PathFormattingMixin): class DisambiguationTest(BeetsTestCase, PathFormattingMixin): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.lib.directory = b"/base" self.lib.path_formats = [("default", "path")] @@ -746,10 +736,6 @@ class DisambiguationTest(BeetsTestCase, PathFormattingMixin): self._setf("foo%aunique{albumartist album,year}/$title") - def tearDown(self): - super().tearDown() - self.lib._connection().close() - def test_unique_expands_to_disambiguating_year(self): self._assert_dest(b"/base/foo [2001]/the title", self.i1) @@ -821,7 +807,6 @@ class DisambiguationTest(BeetsTestCase, PathFormattingMixin): class SingletonDisambiguationTest(BeetsTestCase, PathFormattingMixin): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.lib.directory = b"/base" self.lib.path_formats = [("default", "path")] @@ -835,10 +820,6 @@ class SingletonDisambiguationTest(BeetsTestCase, PathFormattingMixin): self._setf("foo/$title%sunique{artist title,year}") - def tearDown(self): - super().tearDown() - self.lib._connection().close() - def test_sunique_expands_to_disambiguating_year(self): self._assert_dest(b"/base/foo/the title [2001]", self.i1) @@ -919,7 +900,6 @@ class PluginDestinationTest(BeetsTestCase): self.old_field_getters = plugins.item_field_getters plugins.item_field_getters = field_getters - self.lib = beets.library.Library(":memory:") self.lib.directory = b"/base" self.lib.path_formats = [("default", "$artist $foo")] self.i = item(self.lib) @@ -958,7 +938,6 @@ class PluginDestinationTest(BeetsTestCase): class AlbumInfoTest(BeetsTestCase): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.i = item() self.lib.add_album((self.i,)) @@ -1065,9 +1044,7 @@ class ArtDestinationTest(BeetsTestCase): super().setUp() config["art_filename"] = "artimage" config["replace"] = {"X": "Y"} - self.lib = beets.library.Library( - ":memory:", replacements=[(re.compile("X"), "Y")] - ) + self.lib.replacements = [(re.compile("X"), "Y")] self.i = item(self.lib) self.i.path = self.i.destination() self.ai = self.lib.add_album((self.i,)) @@ -1091,7 +1068,6 @@ class ArtDestinationTest(BeetsTestCase): class PathStringTest(BeetsTestCase): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") self.i = item(self.lib) def test_item_path_is_bytestring(self): @@ -1183,7 +1159,6 @@ class MtimeTest(BeetsTestCase): syspath(self.ipath), ) self.i = beets.library.Item.from_path(self.ipath) - self.lib = beets.library.Library(":memory:") self.lib.add(self.i) def tearDown(self): @@ -1213,10 +1188,6 @@ class MtimeTest(BeetsTestCase): class ImportTimeTest(BeetsTestCase): - def setUp(self): - super().setUp() - self.lib = beets.library.Library(":memory:") - def added(self): self.track = item() self.album = self.lib.add_album((self.track,)) diff --git a/test/test_query.py b/test/test_query.py index 565719501..02cdc1673 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -29,7 +29,7 @@ from beets.dbcore.query import ( NoneQuery, ParsingError, ) -from beets.library import Item, Library +from beets.library import Item from beets.test import _common from beets.test.helper import BeetsTestCase, ItemInDBTestCase from beets.util import syspath @@ -94,7 +94,6 @@ class AnyFieldQueryTest(ItemInDBTestCase): class DummyDataTestCase(BeetsTestCase, AssertsMixin): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") items = [_common.item() for _ in range(3)] items[0].title = "foo bar" items[0].artist = "one" @@ -725,9 +724,6 @@ class PathQueryTest(ItemInDBTestCase, AssertsMixin): class IntQueryTest(BeetsTestCase): - def setUp(self): - self.lib = Library(":memory:") - def tearDown(self): super().tearDown() Item._types = {} @@ -766,7 +762,6 @@ class IntQueryTest(BeetsTestCase): class BoolQueryTest(BeetsTestCase, AssertsMixin): def setUp(self): super().setUp() - self.lib = Library(":memory:") Item._types = {"flexbool": types.Boolean()} def tearDown(self): @@ -836,10 +831,6 @@ class DefaultSearchFieldsTest(DummyDataTestCase): class NoneQueryTest(BeetsTestCase, AssertsMixin): - def setUp(self): - super().setUp() - self.lib = Library(":memory:") - def test_match_singletons(self): singleton = self.add_item() album_item = self.add_album().items().get() @@ -1137,7 +1128,6 @@ class RelatedQueriesTest(BeetsTestCase, AssertsMixin): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") albums = [] for album_idx in range(1, 3): diff --git a/test/test_sort.py b/test/test_sort.py index b222c93f9..3d092e551 100644 --- a/test/test_sort.py +++ b/test/test_sort.py @@ -28,7 +28,6 @@ from beets.test.helper import BeetsTestCase class DummyDataTestCase(BeetsTestCase): def setUp(self): super().setUp() - self.lib = beets.library.Library(":memory:") albums = [_common.album() for _ in range(3)] albums[0].album = "Album A" diff --git a/test/test_ui.py b/test/test_ui.py index 890a033f8..d35a900f9 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -40,9 +40,9 @@ from beets.ui import commands from beets.util import MoveOperation, syspath -class ListTest(unittest.TestCase): +class ListTest(BeetsTestCase): def setUp(self): - self.lib = library.Library(":memory:") + super().setUp() self.item = _common.item() self.item.path = "xxx/yyy" self.lib.add(self.item) @@ -114,11 +114,7 @@ class RemoveTest(BeetsTestCase): self.io.install() - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - os.mkdir(syspath(self.libdir)) - # Copy a file into the library. - self.lib = library.Library(":memory:", self.libdir) self.item_path = os.path.join(_common.RSRC, b"full.mp3") self.i = library.Item.from_path(self.item_path) self.lib.add(self.i) @@ -451,9 +447,6 @@ class MoveTest(BeetsTestCase): self.io.install() - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - os.mkdir(syspath(self.libdir)) - self.itempath = os.path.join(self.libdir, b"srcfile") shutil.copy( syspath(os.path.join(_common.RSRC, b"full.mp3")), @@ -461,7 +454,6 @@ class MoveTest(BeetsTestCase): ) # Add a file to the library but don't copy it in yet. - self.lib = library.Library(":memory:", self.libdir) self.i = library.Item.from_path(self.itempath) self.lib.add(self.i) self.album = self.lib.add_album([self.i]) @@ -485,28 +477,28 @@ class MoveTest(BeetsTestCase): def test_move_item(self): self._move() self.i.load() - self.assertIn(b"testlibdir", self.i.path) + self.assertIn(b"libdir", self.i.path) self.assertExists(self.i.path) self.assertNotExists(self.itempath) def test_copy_item(self): self._move(copy=True) self.i.load() - self.assertIn(b"testlibdir", self.i.path) + self.assertIn(b"libdir", self.i.path) self.assertExists(self.i.path) self.assertExists(self.itempath) def test_move_album(self): self._move(album=True) self.i.load() - self.assertIn(b"testlibdir", self.i.path) + self.assertIn(b"libdir", self.i.path) self.assertExists(self.i.path) self.assertNotExists(self.itempath) def test_copy_album(self): self._move(copy=True, album=True) self.i.load() - self.assertIn(b"testlibdir", self.i.path) + self.assertIn(b"libdir", self.i.path) self.assertExists(self.i.path) self.assertExists(self.itempath) @@ -559,10 +551,7 @@ class UpdateTest(BeetsTestCase): self.io.install() - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - # Copy a file into the library. - self.lib = library.Library(":memory:", self.libdir) item_path = os.path.join(_common.RSRC, b"full.mp3") item_path_two = os.path.join(_common.RSRC, b"full.flac") self.i = library.Item.from_path(item_path) diff --git a/test/test_ui_commands.py b/test/test_ui_commands.py index a064fcf71..735d0c393 100644 --- a/test/test_ui_commands.py +++ b/test/test_ui_commands.py @@ -28,18 +28,6 @@ from beets.util import syspath class QueryTest(BeetsTestCase): - def setUp(self): - super().setUp() - - self.libdir = os.path.join(self.temp_dir, b"testlibdir") - os.mkdir(syspath(self.libdir)) - - # Add a file to the library but don't copy it in yet. - self.lib = library.Library(":memory:", self.libdir) - - # Alternate destination directory. - # self.otherdir = os.path.join(self.temp_dir, b"testotherdir") - def add_item(self, filename=b"srcfile", templatefile=b"full.mp3"): itempath = os.path.join(self.libdir, filename) shutil.copy( diff --git a/test/test_vfs.py b/test/test_vfs.py index 939d44f73..34a5f5d30 100644 --- a/test/test_vfs.py +++ b/test/test_vfs.py @@ -16,7 +16,7 @@ import unittest -from beets import library, vfs +from beets import vfs from beets.test import _common from beets.test.helper import BeetsTestCase @@ -24,13 +24,10 @@ from beets.test.helper import BeetsTestCase class VFSTest(BeetsTestCase): def setUp(self): super().setUp() - self.lib = library.Library( - ":memory:", - path_formats=[ - ("default", "albums/$album/$title"), - ("singleton:true", "tracks/$artist/$title"), - ], - ) + self.lib.path_formats = [ + ("default", "albums/$album/$title"), + ("singleton:true", "tracks/$artist/$title"), + ] self.lib.add(_common.item()) self.lib.add_album([_common.item()]) self.tree = vfs.libtree(self.lib)