mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Centralise 'import_dir' creation
This commit is contained in:
parent
1f8466f04a
commit
41bbb77a0b
2 changed files with 9 additions and 14 deletions
|
|
@ -39,6 +39,7 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from functools import cached_property
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from tempfile import mkdtemp, mkstemp
|
from tempfile import mkdtemp, mkstemp
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
|
|
@ -504,6 +505,12 @@ class ImportHelper:
|
||||||
|
|
||||||
importer: importer.ImportSession
|
importer: importer.ImportSession
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def import_dir(self):
|
||||||
|
import_dir = os.path.join(self.temp_dir, b"import")
|
||||||
|
os.makedirs(syspath(import_dir), exist_ok=True)
|
||||||
|
return import_dir
|
||||||
|
|
||||||
def setup_beets(self):
|
def setup_beets(self):
|
||||||
super().setup_beets()
|
super().setup_beets()
|
||||||
self.lib.path_formats = [
|
self.lib.path_formats = [
|
||||||
|
|
@ -526,10 +533,6 @@ class ImportHelper:
|
||||||
|
|
||||||
:param count: Number of files to create
|
:param count: Number of files to create
|
||||||
"""
|
"""
|
||||||
self.import_dir = os.path.join(self.temp_dir, b"testsrcdir")
|
|
||||||
if os.path.isdir(syspath(self.import_dir)):
|
|
||||||
shutil.rmtree(syspath(self.import_dir))
|
|
||||||
|
|
||||||
album_path = os.path.join(self.import_dir, b"the_album")
|
album_path = os.path.join(self.import_dir, b"the_album")
|
||||||
os.makedirs(syspath(album_path))
|
os.makedirs(syspath(album_path))
|
||||||
|
|
||||||
|
|
@ -595,14 +598,10 @@ class ImportHelper:
|
||||||
Copies the specified number of files to a subdirectory of
|
Copies the specified number of files to a subdirectory of
|
||||||
`self.temp_dir` and creates a `ImportSessionFixture` for this path.
|
`self.temp_dir` and creates a `ImportSessionFixture` for this path.
|
||||||
"""
|
"""
|
||||||
import_dir = os.path.join(self.temp_dir, b"import")
|
|
||||||
if not os.path.isdir(syspath(import_dir)):
|
|
||||||
os.mkdir(syspath(import_dir))
|
|
||||||
|
|
||||||
album_no = 0
|
album_no = 0
|
||||||
while album_count:
|
while album_count:
|
||||||
album = util.bytestring_path(f"album {album_no}")
|
album = util.bytestring_path(f"album {album_no}")
|
||||||
album_dir = os.path.join(import_dir, album)
|
album_dir = os.path.join(self.import_dir, album)
|
||||||
if os.path.exists(syspath(album_dir)):
|
if os.path.exists(syspath(album_dir)):
|
||||||
album_no += 1
|
album_no += 1
|
||||||
continue
|
continue
|
||||||
|
|
@ -639,7 +638,7 @@ class ImportHelper:
|
||||||
config["import"]["resume"] = False
|
config["import"]["resume"] = False
|
||||||
|
|
||||||
return ImportSessionFixture(
|
return ImportSessionFixture(
|
||||||
self.lib, loghandler=None, query=None, paths=[import_dir]
|
self.lib, loghandler=None, query=None, paths=[self.import_dir]
|
||||||
)
|
)
|
||||||
|
|
||||||
def assert_file_in_lib(self, *segments):
|
def assert_file_in_lib(self, *segments):
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,6 @@ class FileFilterPluginTest(ImportTestCase):
|
||||||
medium.save()
|
medium.save()
|
||||||
|
|
||||||
def __create_import_dir(self, count):
|
def __create_import_dir(self, count):
|
||||||
self.import_dir = os.path.join(self.temp_dir, b"testsrcdir")
|
|
||||||
if os.path.isdir(syspath(self.import_dir)):
|
|
||||||
shutil.rmtree(syspath(self.import_dir))
|
|
||||||
|
|
||||||
self.artist_path = os.path.join(self.import_dir, b"artist")
|
self.artist_path = os.path.join(self.import_dir, b"artist")
|
||||||
self.album_path = os.path.join(self.artist_path, b"album")
|
self.album_path = os.path.join(self.artist_path, b"album")
|
||||||
self.misc_path = os.path.join(self.import_dir, b"misc")
|
self.misc_path = os.path.join(self.import_dir, b"misc")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue