From 50e384d48a23f45fdeaa2c7fbdfe2aecaa030406 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Sat, 1 Feb 2014 21:44:10 +0100 Subject: [PATCH] Test choosing candidates during import --- test/_common.py | 2 +- test/test_importer.py | 58 +++++++++++++++++++++++++++++++++++++++- test/test_ui_importer.py | 6 +++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/test/_common.py b/test/_common.py index ac07a17bc..00640f5bc 100644 --- a/test/_common.py +++ b/test/_common.py @@ -180,7 +180,7 @@ class InputException(Exception): def __str__(self): msg = "Attempt to read with no input provided." if self.output is not None: - msg += " Output: %s" % repr(self.output) + msg += " Output: %s" % self.output return msg class DummyOut(object): encoding = 'utf8' diff --git a/test/test_importer.py b/test/test_importer.py index 3e36f3b10..9107ab447 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -27,7 +27,6 @@ from beets import autotag from beets.autotag import AlbumInfo, TrackInfo, AlbumMatch, TrackMatch from beets import config -TEST_TITLES = ('The Opener', 'The Second Track', 'The Last Track') class ImportHelper(object): """Provides tools to setup a library, a directory containing files that are to be imported and an import session. The class also provides stubs for the @@ -177,6 +176,8 @@ class TestImportSession(importer.ImportSession): if choice == importer.action.APPLY: return task.candidates[0] + elif isinstance(choice, int): + return task.candidates[choice-1] else: return choice @@ -811,6 +812,61 @@ class InferAlbumDataTest(_common.TestCase): self.assertFalse(self.items[1].comp) self.assertEqual(self.items[1].albumartist, self.items[2].artist) +class ChooseCandidateTest(_common.TestCase, ImportHelper): + def setUp(self): + super(ChooseCandidateTest, self).setUp() + self._setup_library() + self._create_import_dir(1) + self._setup_import_session() + + autotag.mb.match_album = self._match_album + autotag.mb.match_track = self._match_track + + def _match_album(self, albumartist, album, tracks): + """Stub for ``mb.match_album``. + """ + for i in range(1,4): + yield self._generate_album_match(albumartist, album, tracks, i) + + def _generate_track_match(self, artist, album, number): + return TrackInfo( + title = u'Title %d' % number, + track_id = u'trackid %d' % number, + artist = artist, + length = 1) + + def _generate_album_match(self, artist, album, tracks, distance): + if distance: + id = ' ' + 'M' * distance + 'atch' + else: + id = '' + artist = artist + id + album = album + id + + trackInfos = [] + for i in range(tracks): + trackInfos.append(self._generate_track_match(artist, album, i+1)) + + return AlbumInfo( + artist = artist, + album = album, + tracks = trackInfos, + va = False, + album_id = u'albumid' + id, + artist_id = u'artistid' + id, + albumtype = u'soundtrack') + + def test_choose_first_candidate(self): + self.importer.add_choice(1) + self.importer.run() + self.assertEqual(self.lib.albums().get().album, 'Tag Album Match') + + def test_choose_second_candidate(self): + self.importer.add_choice(2) + self.importer.run() + self.assertEqual(self.lib.albums().get().album, 'Tag Album MMatch') + + class DuplicateCheckTest(_common.TestCase): def setUp(self): super(DuplicateCheckTest, self).setUp() diff --git a/test/test_ui_importer.py b/test/test_ui_importer.py index 0e5f64d1b..c951ea2f5 100644 --- a/test/test_ui_importer.py +++ b/test/test_ui_importer.py @@ -61,6 +61,10 @@ class TestTerminalImportSession(TerminalImportSession): self.io.addinput('T') elif choice == importer.action.SKIP: self.io.addinput('S') + elif isinstance(choice, int): + self.io.addinput('M') + self.io.addinput(str(choice)) + self._add_choice_input() else: raise Exception('Unknown choice %s' % choice) @@ -100,6 +104,8 @@ class ImportCompilationTest(TerminalImportSessionSetup, test_importer.ImportCompilationTest): pass class ImportExistingTest(TerminalImportSessionSetup, test_importer.ImportExistingTest): pass +class ChooseCandidateTest(TerminalImportSessionSetup, + test_importer.ChooseCandidateTest): pass class GroupAlbumsImportTest(TerminalImportSessionSetup, test_importer.GroupAlbumsImportTest): pass class GlobalGroupAlbumsImportTest(TerminalImportSessionSetup,