Remove redundant library setUp instructions

This commit is contained in:
Šarūnas Nejus 2024-07-05 11:22:26 +01:00
parent 2d5fd907c3
commit 7d7f16395c
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
13 changed files with 29 additions and 126 deletions

View file

@ -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:")

View file

@ -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

View file

@ -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()

View file

@ -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)

View file

@ -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()

View file

@ -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"))

View file

@ -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.

View file

@ -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,))

View file

@ -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):

View file

@ -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"

View file

@ -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)

View file

@ -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(

View file

@ -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)