mirror of
https://github.com/beetbox/beets.git
synced 2026-07-16 17:48:54 -04:00
Replace ImporterMixin.import_dir attribute with ImporterMixin.import_path
- Update importer fixtures and tests to use pathlib paths directly. - Encode import paths only at the ImportSession boundary.
This commit is contained in:
@@ -583,10 +583,6 @@ class ImporterMixin(PathsMixin, ConfigMixin):
|
||||
import_path.mkdir(exist_ok=True)
|
||||
return import_path
|
||||
|
||||
@cached_property
|
||||
def import_dir(self) -> bytes:
|
||||
return bytestring_path(self.import_path)
|
||||
|
||||
def prepare_track_for_import(
|
||||
self, track_id: int, album_path: Path, album_id: int | None = None
|
||||
) -> Path:
|
||||
@@ -641,16 +637,19 @@ 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: bytes) -> ImportSession:
|
||||
def _get_import_session(self, import_dir: util.PathLike) -> ImportSession:
|
||||
return ImportSessionFixture(
|
||||
self.lib, loghandler=None, query=None, paths=[import_dir]
|
||||
self.lib,
|
||||
loghandler=None,
|
||||
query=None,
|
||||
paths=[os.fsencode(import_dir)],
|
||||
)
|
||||
|
||||
def setup_importer(
|
||||
self, import_dir: bytes | 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_dir)
|
||||
self.importer = self._get_import_session(import_dir or self.import_path)
|
||||
return self.importer
|
||||
|
||||
def setup_singleton_importer(self, **kwargs: Any) -> ImportSession:
|
||||
@@ -782,13 +781,15 @@ class TerminalImportSessionFixture(TerminalImportSession):
|
||||
class TerminalImportMixin(IOMixin, ImportHelper):
|
||||
"""Provides_a terminal importer for the import session."""
|
||||
|
||||
def _get_import_session(self, import_dir: bytes) -> importer.ImportSession:
|
||||
def _get_import_session(
|
||||
self, import_dir: util.PathLike
|
||||
) -> importer.ImportSession:
|
||||
return TerminalImportSessionFixture(
|
||||
self.lib,
|
||||
loghandler=None,
|
||||
query=None,
|
||||
io=self.request.getfixturevalue("io"),
|
||||
paths=[import_dir],
|
||||
paths=[os.fsencode(import_dir)],
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ class TestPermissionsPlugin(AsIsImporterMixin, PluginMixin, ImportHelper):
|
||||
if platform.system() == "Windows":
|
||||
pytest.skip("permissions not available on Windows")
|
||||
|
||||
track_file = os.path.join(self.import_dir, b"album", b"track_1.mp3")
|
||||
assert os.stat(track_file).st_mode & 0o777 != 511
|
||||
track_file = self.import_path / "album" / "track_1.mp3"
|
||||
assert track_file.stat().st_mode & 0o777 != 511
|
||||
|
||||
self.run_asis_importer()
|
||||
item = self.lib.items().get()
|
||||
|
||||
@@ -316,12 +316,12 @@ class ImportSingletonTest(AutotagImportTestCase):
|
||||
|
||||
def test_import_single_files(self):
|
||||
resource_path = os.path.join(_common.RSRC, b"empty.mp3")
|
||||
single_path = os.path.join(self.import_dir, b"track_2.mp3")
|
||||
single_path = self.import_path / "track_2.mp3"
|
||||
|
||||
util.copy(resource_path, single_path)
|
||||
import_files = [os.path.join(self.import_dir, b"album"), single_path]
|
||||
import_files = [self.import_path / "album", single_path]
|
||||
self.setup_importer()
|
||||
self.importer.paths = import_files
|
||||
self.importer.paths = list(map(os.fsencode, import_files))
|
||||
|
||||
self.importer.add_choice(importer.Action.ASIS)
|
||||
self.importer.add_choice(importer.Action.ASIS)
|
||||
@@ -379,7 +379,7 @@ class TestImportFormat(ImportHelper):
|
||||
|
||||
def test_recognize_format(self):
|
||||
resource_src = os.path.join(_common.RSRC, b"no_ext")
|
||||
resource_path = os.path.join(self.import_dir, b"no_ext")
|
||||
resource_path = self.import_path / "no_ext"
|
||||
util.copy(resource_src, resource_path)
|
||||
self.setup_importer(autotag=False)
|
||||
self.importer.paths = [resource_path]
|
||||
@@ -509,7 +509,7 @@ class TestImport(PathsMixin, AutotagImportHelper):
|
||||
@NEEDS_FFPROBE
|
||||
def test_skip_non_album_dirs(self):
|
||||
assert (self.import_path / "album").exists()
|
||||
self.touch(b"cruft", dir_=self.import_dir)
|
||||
(self.import_path / "cruft").touch()
|
||||
self.importer.add_choice(importer.Action.APPLY)
|
||||
self.importer.run()
|
||||
|
||||
@@ -1868,7 +1868,9 @@ class TestImportId(ImportHelper):
|
||||
def test_candidates_album(self):
|
||||
"""Test directly ImportTask.lookup_candidates()."""
|
||||
task = importer.ImportTask(
|
||||
paths=self.import_dir, toppath="top path", items=[_common.item()]
|
||||
paths=os.fsencode(self.import_path),
|
||||
toppath="top path",
|
||||
items=[_common.item()],
|
||||
)
|
||||
|
||||
task.lookup_candidates([self.ID_RELEASE_0, self.ID_RELEASE_1])
|
||||
@@ -1909,8 +1911,8 @@ class TestMpeglayerWavImport(AsIsImporterMixin, ImportHelper):
|
||||
"""When remux_mp3_in_wav is disabled, WAV file should not be remuxed."""
|
||||
self.config["import"]["remux_mp3_in_wav"] = False
|
||||
src = os.path.join(_common.RSRC, b"mpeglayer3.wav")
|
||||
dest = os.path.join(self.import_dir, b"mpeglayer3.wav")
|
||||
dest = self.import_path / "mpeglayer3.wav"
|
||||
shutil.copy(syspath(src), syspath(dest))
|
||||
|
||||
self.run_asis_importer()
|
||||
assert os.path.exists(dest)
|
||||
assert dest.exists()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import importlib
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
from typing import ClassVar
|
||||
@@ -101,7 +100,7 @@ class TestEvents(PluginImportHelper):
|
||||
if not msg.startswith("Sending event:")
|
||||
]
|
||||
assert logs == [
|
||||
f"Album: {displayable_path(os.path.join(self.import_dir, b'album'))}",
|
||||
f"Album: {self.import_path / 'album'}",
|
||||
f" {displayable_path(self.import_media[0].path)}",
|
||||
f" {displayable_path(self.import_media[1].path)}",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user