mirror of
https://github.com/beetbox/beets.git
synced 2025-12-20 15:43:58 +01:00
Synchronise ImportHelper._create_import_dir and TestHelper.create_importer implementations
This commit is contained in:
parent
41bbb77a0b
commit
c2fdf9873d
8 changed files with 109 additions and 119 deletions
|
|
@ -41,6 +41,7 @@ from contextlib import contextmanager
|
|||
from enum import Enum
|
||||
from functools import cached_property
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
from typing import ClassVar
|
||||
from unittest.mock import patch
|
||||
|
|
@ -534,35 +535,35 @@ class ImportHelper:
|
|||
:param count: Number of files to create
|
||||
"""
|
||||
album_path = os.path.join(self.import_dir, b"the_album")
|
||||
os.makedirs(syspath(album_path))
|
||||
os.makedirs(syspath(album_path), exist_ok=True)
|
||||
|
||||
resource_path = os.path.join(_common.RSRC, b"full.mp3")
|
||||
|
||||
metadata = {
|
||||
"artist": "Tag Artist",
|
||||
"album": "Tag Album",
|
||||
"albumartist": None,
|
||||
"mb_trackid": None,
|
||||
"mb_albumid": None,
|
||||
"comp": None,
|
||||
}
|
||||
self.media_files = []
|
||||
for i in range(count):
|
||||
# Copy files
|
||||
album = bytestring_path("album")
|
||||
album_path = os.path.join(self.import_dir, album)
|
||||
os.makedirs(syspath(album_path), exist_ok=True)
|
||||
|
||||
self.import_media = []
|
||||
for track_id in range(1, count + 1):
|
||||
medium_path = os.path.join(
|
||||
album_path, bytestring_path("track_%d.mp3" % (i + 1))
|
||||
album_path, bytestring_path(f"track_{track_id}.mp3")
|
||||
)
|
||||
shutil.copy(syspath(resource_path), syspath(medium_path))
|
||||
medium = MediaFile(medium_path)
|
||||
|
||||
# Set metadata
|
||||
metadata["track"] = i + 1
|
||||
metadata["title"] = "Tag Title %d" % (i + 1)
|
||||
for attr in metadata:
|
||||
setattr(medium, attr, metadata[attr])
|
||||
medium.update(
|
||||
{
|
||||
"album": "Tag Album",
|
||||
"albumartist": None,
|
||||
"mb_albumid": None,
|
||||
"comp": None,
|
||||
"artist": "Tag Artist",
|
||||
"title": f"Tag Track {track_id}",
|
||||
"track": track_id,
|
||||
"mb_trackid": None,
|
||||
}
|
||||
)
|
||||
medium.save()
|
||||
self.media_files.append(medium)
|
||||
self.import_media = self.media_files
|
||||
self.import_media.append(medium)
|
||||
|
||||
def _get_import_session(self, import_dir: str) -> None:
|
||||
self.importer = ImportSessionFixture(
|
||||
|
|
@ -598,40 +599,35 @@ class ImportHelper:
|
|||
Copies the specified number of files to a subdirectory of
|
||||
`self.temp_dir` and creates a `ImportSessionFixture` for this path.
|
||||
"""
|
||||
album_no = 0
|
||||
while album_count:
|
||||
album = util.bytestring_path(f"album {album_no}")
|
||||
album_dir = os.path.join(self.import_dir, album)
|
||||
if os.path.exists(syspath(album_dir)):
|
||||
album_no += 1
|
||||
continue
|
||||
os.mkdir(syspath(album_dir))
|
||||
album_count -= 1
|
||||
resource_path = os.path.join(_common.RSRC, b"full.mp3")
|
||||
|
||||
track_no = 0
|
||||
album_item_count = item_count
|
||||
while album_item_count:
|
||||
title = f"track {track_no}"
|
||||
src = os.path.join(_common.RSRC, b"full.mp3")
|
||||
title_file = util.bytestring_path(f"{title}.mp3")
|
||||
dest = os.path.join(album_dir, title_file)
|
||||
if os.path.exists(syspath(dest)):
|
||||
track_no += 1
|
||||
continue
|
||||
album_item_count -= 1
|
||||
shutil.copy(syspath(src), syspath(dest))
|
||||
mediafile = MediaFile(dest)
|
||||
mediafile.update(
|
||||
album_dirs = Path(os.fsdecode(self.import_dir)).glob("album_*")
|
||||
base_idx = int(str(max(album_dirs, default="0")).split("_")[-1]) + 1
|
||||
|
||||
for album_id in range(base_idx, album_count + base_idx):
|
||||
album = bytestring_path(f"album_{album_id}")
|
||||
album_path = os.path.join(self.import_dir, album)
|
||||
os.makedirs(syspath(album_path), exist_ok=True)
|
||||
|
||||
for track_id in range(1, item_count + 1):
|
||||
medium_path = os.path.join(
|
||||
album_path, bytestring_path(f"track_{track_id}.mp3")
|
||||
)
|
||||
shutil.copy(syspath(resource_path), syspath(medium_path))
|
||||
medium = MediaFile(medium_path)
|
||||
medium.update(
|
||||
{
|
||||
"artist": "artist",
|
||||
"albumartist": "album artist",
|
||||
"title": title,
|
||||
"album": album,
|
||||
"album": f"Tag Album {album_id}",
|
||||
"albumartist": None,
|
||||
"mb_albumid": None,
|
||||
"comp": None,
|
||||
"artist": "Tag Artist",
|
||||
"title": f"Tag Track {track_id}",
|
||||
"track": track_id,
|
||||
"mb_trackid": None,
|
||||
}
|
||||
)
|
||||
mediafile.save()
|
||||
medium.save()
|
||||
|
||||
config["import"]["quiet"] = True
|
||||
config["import"]["autotag"] = False
|
||||
|
|
@ -930,7 +926,7 @@ class AutotagStub:
|
|||
|
||||
def _make_track_match(self, artist, album, number):
|
||||
return TrackInfo(
|
||||
title="Applied Title %d" % number,
|
||||
title="Applied Track %d" % number,
|
||||
track_id="match %d" % number,
|
||||
artist=artist,
|
||||
length=1,
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ class EditDuringImporterTestCase(
|
|||
super().setUp()
|
||||
# Create some mediafiles, and store them for comparison.
|
||||
self._create_import_dir(3)
|
||||
self.items_orig = [Item.from_path(f.path) for f in self.media_files]
|
||||
self.items_orig = [Item.from_path(f.path) for f in self.import_media]
|
||||
self.matcher = AutotagStub().install()
|
||||
self.matcher.matching = AutotagStub.GOOD
|
||||
self.config["import"]["timid"] = True
|
||||
|
|
@ -349,7 +349,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session()
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Tag Title": "Edited Title"}},
|
||||
{"replacements": {"Tag Track": "Edited Track"}},
|
||||
# eDit, Apply changes.
|
||||
["d", "a"],
|
||||
)
|
||||
|
|
@ -367,7 +367,7 @@ class EditDuringImporterTestCase(
|
|||
],
|
||||
)
|
||||
self.assertTrue(
|
||||
all("Edited Title" in i.title for i in self.lib.items())
|
||||
all("Edited Track" in i.title for i in self.lib.items())
|
||||
)
|
||||
|
||||
# Ensure album is *not* fetched from a candidate.
|
||||
|
|
@ -380,7 +380,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session()
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Tag Title": "Edited Title"}},
|
||||
{"replacements": {"Tag Track": "Edited Track"}},
|
||||
# eDit, Cancel, Use as-is.
|
||||
["d", "c", "u"],
|
||||
)
|
||||
|
|
@ -392,7 +392,7 @@ class EditDuringImporterTestCase(
|
|||
[],
|
||||
self.IGNORED + ["albumartist", "mb_albumartistid"],
|
||||
)
|
||||
self.assertTrue(all("Tag Title" in i.title for i in self.lib.items()))
|
||||
self.assertTrue(all("Tag Track" in i.title for i in self.lib.items()))
|
||||
|
||||
# Ensure album is *not* fetched from a candidate.
|
||||
self.assertEqual(self.lib.albums()[0].mb_albumid, "")
|
||||
|
|
@ -404,7 +404,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session()
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Applied Title": "Edited Title"}},
|
||||
{"replacements": {"Applied Track": "Edited Track"}},
|
||||
# edit Candidates, 1, Apply changes.
|
||||
["c", "1", "a"],
|
||||
)
|
||||
|
|
@ -412,7 +412,7 @@ class EditDuringImporterTestCase(
|
|||
# Check that 'title' field is modified, and other fields come from
|
||||
# the candidate.
|
||||
self.assertTrue(
|
||||
all("Edited Title " in i.title for i in self.lib.items())
|
||||
all("Edited Track " in i.title for i in self.lib.items())
|
||||
)
|
||||
self.assertTrue(all("match " in i.mb_trackid for i in self.lib.items()))
|
||||
|
||||
|
|
@ -435,7 +435,7 @@ class EditDuringImporterTestCase(
|
|||
self.importer.paths = []
|
||||
self.importer.query = TrueQuery()
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Applied Title": "Edited Title"}},
|
||||
{"replacements": {"Applied Track": "Edited Track"}},
|
||||
# eDit, Apply changes.
|
||||
["d", "a"],
|
||||
)
|
||||
|
|
@ -443,7 +443,7 @@ class EditDuringImporterTestCase(
|
|||
# Check that 'title' field is modified, and other fields come from
|
||||
# the candidate.
|
||||
self.assertTrue(
|
||||
all("Edited Title " in i.title for i in self.lib.items())
|
||||
all("Edited Track " in i.title for i in self.lib.items())
|
||||
)
|
||||
self.assertTrue(all("match " in i.mb_trackid for i in self.lib.items()))
|
||||
|
||||
|
|
@ -457,7 +457,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session()
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Applied Title": "Edited Title"}},
|
||||
{"replacements": {"Applied Track": "Edited Track"}},
|
||||
# edit Candidates, 1, Apply changes.
|
||||
["c", "1", "a"],
|
||||
)
|
||||
|
|
@ -465,7 +465,7 @@ class EditDuringImporterTestCase(
|
|||
# Check that 'title' field is modified, and other fields come from
|
||||
# the candidate.
|
||||
self.assertTrue(
|
||||
all("Edited Title " in i.title for i in self.lib.items())
|
||||
all("Edited Track " in i.title for i in self.lib.items())
|
||||
)
|
||||
self.assertTrue(all("match " in i.mb_trackid for i in self.lib.items()))
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session(singletons=True)
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Tag Title": "Edited Title"}},
|
||||
{"replacements": {"Tag Track": "Edited Track"}},
|
||||
# eDit, Apply changes, aBort.
|
||||
["d", "a", "b"],
|
||||
)
|
||||
|
|
@ -492,7 +492,7 @@ class EditDuringImporterTestCase(
|
|||
self.IGNORED + ["albumartist", "mb_albumartistid"],
|
||||
)
|
||||
self.assertTrue(
|
||||
all("Edited Title" in i.title for i in self.lib.items())
|
||||
all("Edited Track" in i.title for i in self.lib.items())
|
||||
)
|
||||
|
||||
def test_edit_apply_candidate_singleton(self):
|
||||
|
|
@ -502,7 +502,7 @@ class EditDuringImporterTestCase(
|
|||
self._setup_import_session()
|
||||
# Edit track titles.
|
||||
self.run_mocked_interpreter(
|
||||
{"replacements": {"Applied Title": "Edited Title"}},
|
||||
{"replacements": {"Applied Track": "Edited Track"}},
|
||||
# edit Candidates, 1, Apply changes, aBort.
|
||||
["c", "1", "a", "b"],
|
||||
)
|
||||
|
|
@ -510,6 +510,6 @@ class EditDuringImporterTestCase(
|
|||
# Check that 'title' field is modified, and other fields come from
|
||||
# the candidate.
|
||||
self.assertTrue(
|
||||
all("Edited Title " in i.title for i in self.lib.items())
|
||||
all("Edited Track " in i.title for i in self.lib.items())
|
||||
)
|
||||
self.assertTrue(all("match " in i.mb_trackid for i in self.lib.items()))
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class FileFilterPluginTest(ImportTestCase):
|
|||
self.album_paths = []
|
||||
for i in range(count):
|
||||
metadata["track"] = i + 1
|
||||
metadata["title"] = "Tag Title Album %d" % (i + 1)
|
||||
metadata["title"] = "Tag Track Album %d" % (i + 1)
|
||||
track_file = bytestring_path("%02d - track.mp3" % (i + 1))
|
||||
dest_path = os.path.join(self.album_path, track_file)
|
||||
self.__copy_file(dest_path, metadata)
|
||||
|
|
@ -73,7 +73,7 @@ class FileFilterPluginTest(ImportTestCase):
|
|||
metadata["album"] = None
|
||||
for i in range(count):
|
||||
metadata["track"] = i + 10
|
||||
metadata["title"] = "Tag Title Artist %d" % (i + 1)
|
||||
metadata["title"] = "Tag Track Artist %d" % (i + 1)
|
||||
track_file = bytestring_path("track_%d.mp3" % (i + 1))
|
||||
dest_path = os.path.join(self.artist_path, track_file)
|
||||
self.__copy_file(dest_path, metadata)
|
||||
|
|
@ -83,7 +83,7 @@ class FileFilterPluginTest(ImportTestCase):
|
|||
for i in range(count):
|
||||
metadata["artist"] = "Artist %d" % (i + 42)
|
||||
metadata["track"] = i + 5
|
||||
metadata["title"] = "Tag Title Misc %d" % (i + 1)
|
||||
metadata["title"] = "Tag Track Misc %d" % (i + 1)
|
||||
track_file = bytestring_path("track_%d.mp3" % (i + 1))
|
||||
dest_path = os.path.join(self.misc_path, track_file)
|
||||
self.__copy_file(dest_path, metadata)
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ class ImportAddedTest(PluginMixin, ImportTestCase):
|
|||
self._create_import_dir(2)
|
||||
# Different mtimes on the files to be imported in order to test the
|
||||
# plugin
|
||||
modify_mtimes(mfile.path for mfile in self.media_files)
|
||||
modify_mtimes(mfile.path for mfile in self.import_media)
|
||||
self.min_mtime = min(
|
||||
os.path.getmtime(mfile.path) for mfile in self.media_files
|
||||
os.path.getmtime(mfile.path) for mfile in self.import_media
|
||||
)
|
||||
self.matcher = AutotagStub().install()
|
||||
self.matcher.macthin = AutotagStub.GOOD
|
||||
|
|
@ -65,7 +65,7 @@ class ImportAddedTest(PluginMixin, ImportTestCase):
|
|||
|
||||
def find_media_file(self, item):
|
||||
"""Find the pre-import MediaFile for an Item"""
|
||||
for m in self.media_files:
|
||||
for m in self.import_media:
|
||||
if m.title.replace("Tag", "Applied") == item.title:
|
||||
return m
|
||||
raise AssertionError(
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ class MBSubmitPluginTest(PluginMixin, TerminalImportMixin, ImportTestCase):
|
|||
# Manually build the string for comparing the output.
|
||||
tracklist = (
|
||||
"Open files with Picard? "
|
||||
"01. Tag Title 1 - Tag Artist (0:01)\n"
|
||||
"02. Tag Title 2 - Tag Artist (0:01)"
|
||||
"01. Tag Track 1 - Tag Artist (0:01)\n"
|
||||
"02. Tag Track 2 - Tag Artist (0:01)"
|
||||
)
|
||||
self.assertIn(tracklist, output.getvalue())
|
||||
|
||||
|
|
@ -64,6 +64,6 @@ class MBSubmitPluginTest(PluginMixin, TerminalImportMixin, ImportTestCase):
|
|||
|
||||
# Manually build the string for comparing the output.
|
||||
tracklist = (
|
||||
"Open files with Picard? " "02. Tag Title 2 - Tag Artist (0:01)"
|
||||
"Open files with Picard? " "02. Tag Track 2 - Tag Artist (0:01)"
|
||||
)
|
||||
self.assertIn(tracklist, output.getvalue())
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class PermissionsPluginTest(PluginMixin, ImportTestCase):
|
|||
self.importer = self.create_importer()
|
||||
typs = ["file", "dir"]
|
||||
|
||||
track_file = (b"album 0", b"track 0.mp3")
|
||||
track_file = (b"album_1", b"track_1.mp3")
|
||||
self.exp_perms = {
|
||||
True: {
|
||||
k: convert_perm(self.config["permissions"][k].get())
|
||||
|
|
|
|||
|
|
@ -144,18 +144,18 @@ class NonAutotaggedImportTest(ImportTestCase):
|
|||
def test_import_with_move_prunes_directory_empty(self):
|
||||
config["import"]["move"] = True
|
||||
|
||||
self.assertExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertExists(os.path.join(self.import_dir, b"album"))
|
||||
self.importer.run()
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"album"))
|
||||
|
||||
def test_import_with_move_prunes_with_extra_clutter(self):
|
||||
self.touch(os.path.join(self.import_dir, b"the_album", b"alog.log"))
|
||||
self.touch(os.path.join(self.import_dir, b"album", b"alog.log"))
|
||||
config["clutter"] = ["*.log"]
|
||||
config["import"]["move"] = True
|
||||
|
||||
self.assertExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertExists(os.path.join(self.import_dir, b"album"))
|
||||
self.importer.run()
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"album"))
|
||||
|
||||
def test_threaded_import_move_arrives(self):
|
||||
config["import"]["move"] = True
|
||||
|
|
@ -192,9 +192,9 @@ class NonAutotaggedImportTest(ImportTestCase):
|
|||
|
||||
def test_import_with_delete_prunes_directory_empty(self):
|
||||
config["import"]["delete"] = True
|
||||
self.assertExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertExists(os.path.join(self.import_dir, b"album"))
|
||||
self.importer.run()
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertNotExists(os.path.join(self.import_dir, b"album"))
|
||||
|
||||
@unittest.skipUnless(_common.HAVE_SYMLINK, "need symlinks")
|
||||
def test_import_link_arrives(self):
|
||||
|
|
@ -354,7 +354,7 @@ class ImportSingletonTest(ImportTestCase):
|
|||
|
||||
self.importer.add_choice(importer.action.ASIS)
|
||||
self.importer.run()
|
||||
self.assertEqual(self.lib.items().get().title, "Tag Title 1")
|
||||
self.assertEqual(self.lib.items().get().title, "Tag Track 1")
|
||||
|
||||
def test_apply_asis_does_not_add_album(self):
|
||||
self.assertIsNone(self.lib.albums().get())
|
||||
|
|
@ -368,14 +368,14 @@ class ImportSingletonTest(ImportTestCase):
|
|||
|
||||
self.importer.add_choice(importer.action.ASIS)
|
||||
self.importer.run()
|
||||
self.assert_file_in_lib(b"singletons", b"Tag Title 1.mp3")
|
||||
self.assert_file_in_lib(b"singletons", b"Tag Track 1.mp3")
|
||||
|
||||
def test_apply_candidate_adds_track(self):
|
||||
self.assertIsNone(self.lib.items().get())
|
||||
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Title 1")
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Track 1")
|
||||
|
||||
def test_apply_candidate_does_not_add_album(self):
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
|
|
@ -387,7 +387,7 @@ class ImportSingletonTest(ImportTestCase):
|
|||
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assert_file_in_lib(b"singletons", b"Applied Title 1.mp3")
|
||||
self.assert_file_in_lib(b"singletons", b"Applied Track 1.mp3")
|
||||
|
||||
def test_skip_does_not_add_first_track(self):
|
||||
self.importer.add_choice(importer.action.SKIP)
|
||||
|
|
@ -407,7 +407,7 @@ class ImportSingletonTest(ImportTestCase):
|
|||
|
||||
util.copy(resource_path, single_path)
|
||||
import_files = [
|
||||
os.path.join(self.import_dir, b"the_album"),
|
||||
os.path.join(self.import_dir, b"album"),
|
||||
single_path,
|
||||
]
|
||||
self._setup_import_session(singletons=False)
|
||||
|
|
@ -439,7 +439,7 @@ class ImportSingletonTest(ImportTestCase):
|
|||
item.load() # TODO: Not sure this is necessary.
|
||||
self.assertEqual(item.genre, genre)
|
||||
self.assertEqual(item.collection, collection)
|
||||
self.assertEqual(item.title, "Tag Title 1 - formatted")
|
||||
self.assertEqual(item.title, "Tag Track 1 - formatted")
|
||||
# Remove item from library to test again with APPLY choice.
|
||||
item.remove()
|
||||
|
||||
|
|
@ -453,7 +453,7 @@ class ImportSingletonTest(ImportTestCase):
|
|||
item.load()
|
||||
self.assertEqual(item.genre, genre)
|
||||
self.assertEqual(item.collection, collection)
|
||||
self.assertEqual(item.title, "Applied Title 1 - formatted")
|
||||
self.assertEqual(item.title, "Applied Track 1 - formatted")
|
||||
|
||||
|
||||
class ImportTest(ImportTestCase):
|
||||
|
|
@ -481,14 +481,14 @@ class ImportTest(ImportTestCase):
|
|||
self.assertIsNone(self.lib.items().get())
|
||||
self.importer.add_choice(importer.action.ASIS)
|
||||
self.importer.run()
|
||||
self.assertEqual(self.lib.items().get().title, "Tag Title 1")
|
||||
self.assertEqual(self.lib.items().get().title, "Tag Track 1")
|
||||
|
||||
def test_apply_asis_adds_album_path(self):
|
||||
self.assert_lib_dir_empty()
|
||||
|
||||
self.importer.add_choice(importer.action.ASIS)
|
||||
self.importer.run()
|
||||
self.assert_file_in_lib(b"Tag Artist", b"Tag Album", b"Tag Title 1.mp3")
|
||||
self.assert_file_in_lib(b"Tag Artist", b"Tag Album", b"Tag Track 1.mp3")
|
||||
|
||||
def test_apply_candidate_adds_album(self):
|
||||
self.assertIsNone(self.lib.albums().get())
|
||||
|
|
@ -502,7 +502,7 @@ class ImportTest(ImportTestCase):
|
|||
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Title 1")
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Track 1")
|
||||
|
||||
def test_apply_candidate_adds_album_path(self):
|
||||
self.assert_lib_dir_empty()
|
||||
|
|
@ -510,7 +510,7 @@ class ImportTest(ImportTestCase):
|
|||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assert_file_in_lib(
|
||||
b"Applied Artist", b"Applied Album", b"Applied Title 1.mp3"
|
||||
b"Applied Artist", b"Applied Album", b"Applied Track 1.mp3"
|
||||
)
|
||||
|
||||
def test_apply_from_scratch_removes_other_metadata(self):
|
||||
|
|
@ -542,9 +542,7 @@ class ImportTest(ImportTestCase):
|
|||
def test_apply_with_move_deletes_import(self):
|
||||
config["import"]["move"] = True
|
||||
|
||||
import_file = os.path.join(
|
||||
self.import_dir, b"the_album", b"track_1.mp3"
|
||||
)
|
||||
import_file = os.path.join(self.import_dir, b"album", b"track_1.mp3")
|
||||
self.assertExists(import_file)
|
||||
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
|
|
@ -554,9 +552,7 @@ class ImportTest(ImportTestCase):
|
|||
def test_apply_with_delete_deletes_import(self):
|
||||
config["import"]["delete"] = True
|
||||
|
||||
import_file = os.path.join(
|
||||
self.import_dir, b"the_album", b"track_1.mp3"
|
||||
)
|
||||
import_file = os.path.join(self.import_dir, b"album", b"track_1.mp3")
|
||||
self.assertExists(import_file)
|
||||
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
|
|
@ -569,7 +565,7 @@ class ImportTest(ImportTestCase):
|
|||
self.assertIsNone(self.lib.items().get())
|
||||
|
||||
def test_skip_non_album_dirs(self):
|
||||
self.assertIsDir(os.path.join(self.import_dir, b"the_album"))
|
||||
self.assertIsDir(os.path.join(self.import_dir, b"album"))
|
||||
self.touch(b"cruft", dir=self.import_dir)
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
|
|
@ -691,7 +687,7 @@ class ImportTracksTest(ImportTestCase):
|
|||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Title 1")
|
||||
self.assertEqual(self.lib.items().get().title, "Applied Track 1")
|
||||
self.assertIsNone(self.lib.albums().get())
|
||||
|
||||
def test_apply_tracks_adds_singleton_path(self):
|
||||
|
|
@ -701,7 +697,7 @@ class ImportTracksTest(ImportTestCase):
|
|||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
self.assert_file_in_lib(b"singletons", b"Applied Title 1.mp3")
|
||||
self.assert_file_in_lib(b"singletons", b"Applied Track 1.mp3")
|
||||
|
||||
|
||||
class ImportCompilationTest(ImportTestCase):
|
||||
|
|
@ -885,7 +881,7 @@ class ImportExistingTest(ImportTestCase):
|
|||
medium.save()
|
||||
|
||||
old_path = os.path.join(
|
||||
b"Applied Artist", b"Applied Album", b"Applied Title 1.mp3"
|
||||
b"Applied Artist", b"Applied Album", b"Applied Track 1.mp3"
|
||||
)
|
||||
self.assert_file_in_lib(old_path)
|
||||
|
||||
|
|
@ -903,7 +899,7 @@ class ImportExistingTest(ImportTestCase):
|
|||
medium.save()
|
||||
|
||||
old_path = os.path.join(
|
||||
b"Applied Artist", b"Applied Album", b"Applied Title 1.mp3"
|
||||
b"Applied Artist", b"Applied Album", b"Applied Track 1.mp3"
|
||||
)
|
||||
self.assert_file_in_lib(old_path)
|
||||
|
||||
|
|
@ -927,7 +923,7 @@ class ImportExistingTest(ImportTestCase):
|
|||
self.importer.add_choice(importer.action.APPLY)
|
||||
self.importer.run()
|
||||
new_path = os.path.join(
|
||||
b"Applied Artist", b"Applied Album", b"Applied Title 1.mp3"
|
||||
b"Applied Artist", b"Applied Album", b"Applied Track 1.mp3"
|
||||
)
|
||||
|
||||
self.assert_file_in_lib(new_path)
|
||||
|
|
@ -1194,7 +1190,7 @@ class ImportDuplicateAlbumTest(ImportTestCase):
|
|||
# Imported item has the same artist and album as the one in the
|
||||
# library.
|
||||
import_file = os.path.join(
|
||||
self.importer.paths[0], b"album 0", b"track 0.mp3"
|
||||
self.importer.paths[0], b"album_1", b"track_1.mp3"
|
||||
)
|
||||
import_file = MediaFile(import_file)
|
||||
import_file.artist = item["artist"]
|
||||
|
|
@ -1242,7 +1238,7 @@ class ImportDuplicateAlbumTest(ImportTestCase):
|
|||
|
||||
item = self.lib.items().get()
|
||||
import_file = MediaFile(
|
||||
os.path.join(self.importer.paths[0], b"album 0", b"track 0.mp3")
|
||||
os.path.join(self.importer.paths[0], b"album_1", b"track_1.mp3")
|
||||
)
|
||||
import_file.artist = item["artist"]
|
||||
import_file.albumartist = item["artist"]
|
||||
|
|
@ -1380,11 +1376,11 @@ class ResumeImportTest(ImportTestCase):
|
|||
|
||||
self.importer.run()
|
||||
self.assertEqual(len(self.lib.albums()), 1)
|
||||
self.assertIsNotNone(self.lib.albums("album:album 0").get())
|
||||
self.assertIsNotNone(self.lib.albums("album:'Album 1'").get())
|
||||
|
||||
self.importer.run()
|
||||
self.assertEqual(len(self.lib.albums()), 2)
|
||||
self.assertIsNotNone(self.lib.albums("album:album 1").get())
|
||||
self.assertIsNotNone(self.lib.albums("album:'Album 2'").get())
|
||||
|
||||
@patch("beets.plugins.send")
|
||||
def test_resume_singleton(self, plugins_send):
|
||||
|
|
@ -1402,11 +1398,11 @@ class ResumeImportTest(ImportTestCase):
|
|||
|
||||
self.importer.run()
|
||||
self.assertEqual(len(self.lib.items()), 1)
|
||||
self.assertIsNotNone(self.lib.items("title:track 0").get())
|
||||
self.assertIsNotNone(self.lib.items("title:'Track 1'").get())
|
||||
|
||||
self.importer.run()
|
||||
self.assertEqual(len(self.lib.items()), 2)
|
||||
self.assertIsNotNone(self.lib.items("title:track 1").get())
|
||||
self.assertIsNotNone(self.lib.items("title:'Track 1'").get())
|
||||
|
||||
|
||||
class IncrementalImportTest(ImportTestCase):
|
||||
|
|
@ -1751,7 +1747,7 @@ class ImportPretendTest(ImportTestCase):
|
|||
single_path = os.path.join(self.import_dir, b"track_2.mp3")
|
||||
shutil.copy(syspath(resource_path), syspath(single_path))
|
||||
self.import_paths = [
|
||||
os.path.join(self.import_dir, b"the_album"),
|
||||
os.path.join(self.import_dir, b"album"),
|
||||
single_path,
|
||||
]
|
||||
self.import_files = [
|
||||
|
|
|
|||
|
|
@ -179,12 +179,10 @@ class EventsTest(PluginImportTestCase):
|
|||
logs,
|
||||
[
|
||||
"Album: {}".format(
|
||||
displayable_path(
|
||||
os.path.join(self.import_dir, b"the_album")
|
||||
)
|
||||
displayable_path(os.path.join(self.import_dir, b"album"))
|
||||
),
|
||||
" {}".format(displayable_path(self.media_files[0].path)),
|
||||
" {}".format(displayable_path(self.media_files[1].path)),
|
||||
" {}".format(displayable_path(self.import_media[0].path)),
|
||||
" {}".format(displayable_path(self.import_media[1].path)),
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -230,10 +228,10 @@ class EventsTest(PluginImportTestCase):
|
|||
logs,
|
||||
[
|
||||
"Singleton: {}".format(
|
||||
displayable_path(self.media_files[0].path)
|
||||
displayable_path(self.import_media[0].path)
|
||||
),
|
||||
"Singleton: {}".format(
|
||||
displayable_path(self.media_files[1].path)
|
||||
displayable_path(self.import_media[1].path)
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue