mirror of
https://github.com/beetbox/beets.git
synced 2026-07-22 03:17:26 -04:00
Replace TestHelper.libdir attribute with TestHelper.lib_path
This commit is contained in:
@@ -231,10 +231,6 @@ class TestHelper(RunMixin, PathsMixin, ConfigMixin):
|
||||
lib_path.mkdir(exist_ok=True)
|
||||
return lib_path
|
||||
|
||||
@cached_property
|
||||
def libdir(self) -> bytes:
|
||||
return bytestring_path(self.lib_path)
|
||||
|
||||
# TODO automate teardown through hook registration
|
||||
|
||||
def setup_beets(self) -> None:
|
||||
@@ -249,7 +245,7 @@ class TestHelper(RunMixin, PathsMixin, ConfigMixin):
|
||||
- ``temp_dir`` Path to a temporary directory containing all
|
||||
files specific to beets
|
||||
|
||||
- ``libdir`` Path to a subfolder of ``temp_dir``, containing the
|
||||
- ``lib_path`` Path to a subfolder of ``temp_dir``, containing the
|
||||
library's media files. Same as ``config['directory']``.
|
||||
|
||||
- ``lib`` Library instance created with the settings from
|
||||
@@ -637,7 +633,7 @@ class ImporterMixin(PathsMixin, ConfigMixin):
|
||||
for album_id in range(base_idx, count + base_idx):
|
||||
self.prepare_album_for_import(1, album_id=album_id)
|
||||
|
||||
def _get_import_session(self, import_dir: util.PathLike) -> ImportSession:
|
||||
def _get_import_session(self, import_dir: Path) -> ImportSession:
|
||||
return ImportSessionFixture(
|
||||
self.lib,
|
||||
loghandler=None,
|
||||
@@ -646,7 +642,7 @@ class ImporterMixin(PathsMixin, ConfigMixin):
|
||||
)
|
||||
|
||||
def setup_importer(
|
||||
self, import_dir: bytes | None = None, **kwargs: Any
|
||||
self, import_dir: Path | None = None, **kwargs: Any
|
||||
) -> ImportSession:
|
||||
self.config["import"].set_args({**self.default_import_config, **kwargs})
|
||||
self.importer = self._get_import_session(import_dir or self.import_path)
|
||||
@@ -781,9 +777,7 @@ class TerminalImportSessionFixture(TerminalImportSession):
|
||||
class TerminalImportMixin(IOMixin, ImportHelper):
|
||||
"""Provides_a terminal importer for the import session."""
|
||||
|
||||
def _get_import_session(
|
||||
self, import_dir: util.PathLike
|
||||
) -> importer.ImportSession:
|
||||
def _get_import_session(self, import_dir: Path) -> importer.ImportSession:
|
||||
return TerminalImportSessionFixture(
|
||||
self.lib,
|
||||
loghandler=None,
|
||||
|
||||
@@ -866,8 +866,8 @@ class TestArtImporter(UseThePlugin):
|
||||
self.plugin.art_for_album = art_for_album
|
||||
|
||||
# Test library.
|
||||
os.mkdir(syspath(os.path.join(self.libdir, b"album")))
|
||||
itempath = os.path.join(self.libdir, b"album", b"test.mp3")
|
||||
(self.lib_path / "album").mkdir()
|
||||
itempath = self.lib_path / "album" / "test.mp3"
|
||||
shutil.copyfile(
|
||||
syspath(os.path.join(_common.RSRC, b"full.mp3")), syspath(itempath)
|
||||
)
|
||||
|
||||
@@ -288,7 +288,7 @@ class BPDTestHelper(PluginTestCase):
|
||||
"--library",
|
||||
self.config["library"].as_filename(),
|
||||
"--directory",
|
||||
os.fsdecode(self.libdir),
|
||||
str(self.lib_path),
|
||||
"--config",
|
||||
os.fsdecode(config_file.name),
|
||||
"bpd",
|
||||
|
||||
@@ -81,7 +81,7 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
|
||||
# Newer Item path mtimes as if Beets had modified them
|
||||
modify_mtimes(items_added_before.keys(), offset=10000)
|
||||
# Reimport
|
||||
self.setup_importer(import_dir=self.libdir)
|
||||
self.setup_importer(import_dir=self.lib_path)
|
||||
self.importer.run()
|
||||
# Verify the reimported items
|
||||
album = self.lib.albums().get()
|
||||
@@ -123,7 +123,7 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
|
||||
# Newer Item path mtimes as if Beets had modified them
|
||||
modify_mtimes(items_added_before.keys(), offset=10000)
|
||||
# Reimport
|
||||
self.setup_importer(import_dir=self.libdir, singletons=True)
|
||||
self.setup_importer(import_dir=self.lib_path, singletons=True)
|
||||
self.importer.run()
|
||||
# Verify the reimported items
|
||||
items_added_after = {item.path: item.added for item in self.lib.items()}
|
||||
|
||||
@@ -91,7 +91,7 @@ class ImportSourceTest(IOMixin, PluginMixin, AutotagImportTestCase):
|
||||
mb_albumid = album.mb_albumid
|
||||
|
||||
# Reimport from library
|
||||
reimporter = self.setup_importer(import_dir=self.libdir)
|
||||
reimporter = self.setup_importer(import_dir=self.lib_path)
|
||||
reimporter.add_choice(importer.Action.APPLY)
|
||||
reimporter.run()
|
||||
|
||||
|
||||
@@ -315,8 +315,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
def test_setart_copies_image(self):
|
||||
util.remove(self.art)
|
||||
|
||||
newart = os.path.join(self.libdir, b"newart.jpg")
|
||||
touch(newart)
|
||||
newart = self.lib_path / "newart.jpg"
|
||||
newart.touch()
|
||||
i2 = item()
|
||||
i2.path = self.i.path
|
||||
i2.artist = "someArtist"
|
||||
@@ -331,8 +331,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
util.remove(self.art)
|
||||
|
||||
# Original art.
|
||||
newart = os.path.join(self.libdir, b"newart.jpg")
|
||||
touch(newart)
|
||||
newart = self.lib_path / "newart.jpg"
|
||||
newart.touch()
|
||||
i2 = item()
|
||||
i2.path = self.i.path
|
||||
i2.artist = "someArtist"
|
||||
@@ -345,8 +345,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
assert ai.art_filepath.exists()
|
||||
|
||||
def test_setart_to_existing_but_unset_art_works(self):
|
||||
newart = os.path.join(self.libdir, b"newart.jpg")
|
||||
touch(newart)
|
||||
newart = self.lib_path / "newart.jpg"
|
||||
newart.touch()
|
||||
i2 = item()
|
||||
i2.path = self.i.path
|
||||
i2.artist = "someArtist"
|
||||
@@ -362,8 +362,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
assert ai.art_filepath.exists()
|
||||
|
||||
def test_setart_to_conflicting_file_replaces_it(self):
|
||||
newart = os.path.join(self.libdir, b"newart.jpg")
|
||||
touch(newart)
|
||||
newart = self.lib_path / "newart.jpg"
|
||||
newart.touch()
|
||||
i2 = item()
|
||||
i2.path = self.i.path
|
||||
i2.artist = "someArtist"
|
||||
@@ -380,8 +380,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
assert artdest == ai.artpath
|
||||
|
||||
def test_setart_replaces_old_art_at_different_path(self):
|
||||
newart = os.path.join(self.libdir, b"newart.png")
|
||||
touch(newart)
|
||||
newart = self.lib_path / "newart.png"
|
||||
newart.touch()
|
||||
i2 = item()
|
||||
i2.path = self.i.path
|
||||
i2.artist = "someArtist"
|
||||
@@ -394,8 +394,8 @@ class ArtFileTest(BeetsTestCase):
|
||||
assert os.path.exists(syspath(old_artpath))
|
||||
|
||||
# Set new art with a different extension.
|
||||
another_art = os.path.join(self.libdir, b"another.jpg")
|
||||
touch(another_art)
|
||||
another_art = self.lib_path / "another.jpg"
|
||||
another_art.touch()
|
||||
ai.set_art(another_art)
|
||||
|
||||
# Old art should be removed.
|
||||
@@ -405,9 +405,9 @@ class ArtFileTest(BeetsTestCase):
|
||||
def test_setart_sets_permissions(self):
|
||||
util.remove(self.art)
|
||||
|
||||
newart = os.path.join(self.libdir, b"newart.jpg")
|
||||
touch(newart)
|
||||
os.chmod(syspath(newart), 0o400) # read-only
|
||||
newart = self.lib_path / "newart.jpg"
|
||||
newart.touch()
|
||||
newart.chmod(0o400) # read-only
|
||||
|
||||
try:
|
||||
i2 = item()
|
||||
|
||||
@@ -745,7 +745,7 @@ class ImportExistingTest(PathsMixin, AutotagImportTestCase):
|
||||
super().setUp()
|
||||
self.prepare_album_for_import(1)
|
||||
|
||||
self.reimporter = self.setup_importer(import_dir=self.libdir)
|
||||
self.reimporter = self.setup_importer(import_dir=self.lib_path)
|
||||
self.importer = self.setup_importer()
|
||||
|
||||
def tearDown(self):
|
||||
@@ -1630,7 +1630,7 @@ class ReimportTest(AutotagImportTestCase):
|
||||
item.store()
|
||||
|
||||
def _setup_session(self, singletons=False):
|
||||
self.setup_importer(import_dir=self.libdir, singletons=singletons)
|
||||
self.setup_importer(import_dir=self.lib_path, singletons=singletons)
|
||||
self.importer.add_choice(importer.Action.APPLY)
|
||||
|
||||
def _album(self):
|
||||
|
||||
@@ -8,6 +8,7 @@ import re
|
||||
import shutil
|
||||
import stat
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -20,13 +21,7 @@ from beets.library import Album
|
||||
from beets.test import _common
|
||||
from beets.test._common import item
|
||||
from beets.test.helper import TestHelper
|
||||
from beets.util import (
|
||||
as_string,
|
||||
bytestring_path,
|
||||
normpath,
|
||||
path_as_posix,
|
||||
syspath,
|
||||
)
|
||||
from beets.util import as_string, bytestring_path, normpath, syspath
|
||||
|
||||
# Shortcut to path normalization.
|
||||
np = util.normpath
|
||||
@@ -1076,18 +1071,18 @@ class TestPathString(PytestItemHelper):
|
||||
assert isinstance(self.get_first_item().path, bytes)
|
||||
|
||||
def test_special_chars_preserved_in_database(self, item_in_db):
|
||||
path = "b\xe1r".encode()
|
||||
path = Path("b\xe1r")
|
||||
item_in_db.path = path
|
||||
item_in_db.store()
|
||||
assert self.get_first_item().path == os.path.join(self.libdir, path)
|
||||
assert self.get_first_item().filepath == self.lib_path / path
|
||||
|
||||
def test_special_char_path_added_to_database(self, item, item_in_db):
|
||||
item_in_db.remove()
|
||||
path = "b\xe1r".encode()
|
||||
path = Path("b\xe1r")
|
||||
item = _common.item()
|
||||
item.path = path
|
||||
self.lib.add(item)
|
||||
assert self.get_first_item().path == os.path.join(self.libdir, path)
|
||||
assert self.get_first_item().filepath == self.lib_path / path
|
||||
|
||||
def test_destination_returns_bytestring(self, item_in_db):
|
||||
item_in_db.artist = "b\xe1r"
|
||||
@@ -1101,7 +1096,7 @@ class TestPathString(PytestItemHelper):
|
||||
assert isinstance(dest, bytes)
|
||||
|
||||
def test_artpath_stores_special_chars(self, item_in_db):
|
||||
path = bytestring_path("b\xe1r")
|
||||
path = Path("b\xe1r")
|
||||
alb = self.lib.add_album([item_in_db])
|
||||
alb.artpath = path
|
||||
alb.store()
|
||||
@@ -1111,8 +1106,8 @@ class TestPathString(PytestItemHelper):
|
||||
.fetchone()[0]
|
||||
)
|
||||
alb = self.lib.get_album(item_in_db)
|
||||
assert stored_path == path
|
||||
assert alb.artpath == os.path.join(self.libdir, path)
|
||||
assert stored_path == os.fsencode(path)
|
||||
assert alb.art_filepath == self.lib_path / path
|
||||
|
||||
def test_sanitize_path_with_special_chars(self):
|
||||
path = "b\xe1r?"
|
||||
@@ -1138,8 +1133,8 @@ class TestPathString(PytestItemHelper):
|
||||
assert isinstance(alb.artpath, bytes)
|
||||
|
||||
def test_relative_path_is_stored(self, item_in_db):
|
||||
relative_path = os.path.join(b"abc", b"foo.mp3")
|
||||
absolute_path = os.path.join(self.libdir, relative_path)
|
||||
relative_path = Path("abc") / "foo.mp3"
|
||||
absolute_path = self.lib_path / relative_path
|
||||
item_in_db.path = absolute_path
|
||||
item_in_db.store()
|
||||
stored_path = (
|
||||
@@ -1149,9 +1144,9 @@ class TestPathString(PytestItemHelper):
|
||||
)
|
||||
album = self.lib.add_album([item_in_db])
|
||||
|
||||
assert item_in_db.path == absolute_path
|
||||
assert stored_path == path_as_posix(relative_path)
|
||||
assert album.path == os.path.dirname(absolute_path)
|
||||
assert item_in_db.filepath == absolute_path
|
||||
assert stored_path == util.path_as_posix(os.fsencode(relative_path))
|
||||
assert album.filepath == absolute_path.parent
|
||||
|
||||
|
||||
class TestMtime(TestHelper):
|
||||
|
||||
@@ -127,7 +127,7 @@ class MoveTest(BeetsTestCase):
|
||||
self.i.load()
|
||||
i2.load()
|
||||
assert self.i.path == old_i_path
|
||||
assert i2.path.startswith(self.libdir)
|
||||
assert i2.filepath.is_relative_to(self.lib_path)
|
||||
assert i2.filepath.exists()
|
||||
|
||||
def test_move_item_skips_missing_file(self):
|
||||
|
||||
@@ -12,10 +12,10 @@ from beets.util import syspath
|
||||
|
||||
|
||||
class QueryTest(BeetsTestCase):
|
||||
def add_item(self, filename=b"srcfile", templatefile=b"full.mp3"):
|
||||
itempath = os.path.join(self.libdir, filename)
|
||||
def add_item(self):
|
||||
itempath = self.lib_path / "srcfile"
|
||||
shutil.copy(
|
||||
syspath(os.path.join(_common.RSRC, templatefile)), syspath(itempath)
|
||||
syspath(os.path.join(_common.RSRC, b"full.mp3")), syspath(itempath)
|
||||
)
|
||||
item = library.Item.from_path(itempath)
|
||||
self.lib.add(item)
|
||||
|
||||
Reference in New Issue
Block a user