def test_apply_match_uses_album_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. _call_apply(coro, [self.i], self.info) self.assertExists( os.path.join(self.libdir, self.lib.path_formats['default'] + '.mp3'))
def test_apply_as_tracks_uses_singleton_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. self._call_apply_choice(coro, [self.i], importer.action.TRACKS) self.assertExists( os.path.join(self.libdir, self.lib.path_formats['singleton'] + '.mp3'))
def _apply_result(self): """Run the "apply" coroutine and get the resulting Album.""" coro = importer.apply_choices(self.config) coro.next() _call_apply_choice(coro, self.items, importer.action.ASIS) return self.lib.albums()[0]
def test_reimport_inside_file_moves_and_does_not_add_to_old_paths(self): """Reimporting a file *inside* the library directory should *move* the file. """ # Add the item to the library while inside the library directory. internal_srcpath = os.path.join(self.libdir, 'source.mp3') shutil.move(self.srcpath, internal_srcpath) temp_item = library.Item.from_path(internal_srcpath) self.lib.add(temp_item) self.lib.conn.commit() self.i = library.Item.from_path(internal_srcpath) self.i.comp = False # Then, re-import the same file. coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() task = _call_apply(coro, [self.i], self.info) # Old file should be gone. self.assertNotExists(internal_srcpath) # New file should be present. self.assertExists(os.path.join(self.libdir, 'one.mp3')) # Also, the old file should not be in old_paths because it does # not exist. self.assertEqual(task.old_paths, [])
def test_apply_match_uses_album_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. _call_apply(coro, [self.i], self.info) self.assertExists( os.path.join(self.libdir, self.lib.path_formats['default']+'.mp3') )
def test_finalize_with_delete(self): config = _common.iconfig(self.lib, delete=True) applyc = importer.apply_choices(config) applyc.next() finalize = importer.finalize(config) finalize.next() _call_apply([applyc, finalize], [self.i], self.info) self.assertNotExists(self.srcpath)
def test_finalize_with_delete_prunes_directory_empty(self): config = _common.iconfig(self.lib, delete=True) applyc = importer.apply_choices(config) applyc.next() finalize = importer.finalize(config) finalize.next() _call_apply([applyc, finalize], [self.i], self.info, self.srcdir) self.assertNotExists(os.path.dirname(self.srcpath))
def test_apply_with_move_prunes_empty_directory(self): config = _common.iconfig(self.lib, move=True) applyc = importer.apply_choices(config) applyc.next() finalize = importer.finalize(config) finalize.next() _call_apply([applyc], [self.i], self.info, self.srcdir) self.assertNotExists(os.path.dirname(self.srcpath))
def test_apply_tracks_uses_singleton_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. task = importer.ImportTask.item_task(self.i) task.set_choice(self.info.tracks[0]) coro.send(task) self.assertExists(os.path.join(self.libdir, 'three.mp3'))
def test_apply_tracks_uses_singleton_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. task = importer.ImportTask.item_task(self.i) task.set_choice(self.info.tracks[0]) coro.send(task) self.assertExists(os.path.join(self.libdir, "three.mp3"))
def test_apply_with_move(self): config = _common.iconfig(self.lib, move=True) applyc = importer.apply_choices(config) applyc.next() finalize = importer.finalize(config) finalize.next() _call_apply([applyc], [self.i], self.info) self.assertExists(list(self.lib.items())[0].path) self.assertNotExists(self.srcpath)
def test_apply_tracks_uses_singleton_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. task = importer.ImportTask.item_task(self.i) task.set_choice(self.info['tracks'][0]) coro.send(task) self.assertExists( os.path.join(self.libdir, self.lib.path_formats['singleton']+'.mp3') )
def test_apply_tracks_uses_singleton_path(self): apply_coro = importer.apply_choices(self.session) apply_coro.next() manip_coro = importer.manipulate_files(self.session) manip_coro.next() task = importer.ImportTask.item_task(self.i) task.set_choice(TrackMatch(0, self.info.tracks[0])) apply_coro.send(task) manip_coro.send(task) self.assertExists(os.path.join(self.libdir, 'three.mp3'))
def test_apply_tracks_uses_singleton_path(self): config = _common.iconfig(self.lib) apply_coro = importer.apply_choices(config) apply_coro.next() manip_coro = importer.manipulate_files(config) manip_coro.next() task = importer.ImportTask.item_task(self.i) task.set_choice(TrackMatch(0, self.info.tracks[0])) apply_coro.send(task) manip_coro.send(task) self.assertExists(os.path.join(self.libdir, "three.mp3"))
def test_reimport_moves_file_and_does_not_add_to_old_paths(self): # First, add the item to the library. temp_item = library.Item.from_path(self.srcpath) self.lib.add(temp_item) self.lib.save() # Then, re-import the same file. coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() task = _call_apply(coro, [self.i], self.info) # Old file should be gone. self.assertNotExists(self.srcpath) # New file should be present. self.assertExists(os.path.join(self.libdir, 'one.mp3')) # Also, the old file should not be in old_paths because it does # not exist. self.assertEqual(task.old_paths, [])
def test_reimport_outside_file_copies(self): """Reimporting a file *outside* the library directory should *copy* the file (when copying is enabled). """ # First, add the item to the library. temp_item = library.Item.from_path(self.srcpath) self.lib.add(temp_item) self.lib.conn.commit() # Then, re-import the same file. coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() task = _call_apply(coro, [self.i], self.info) # Old file should still exist. self.assertExists(self.srcpath) # New file should also be present. self.assertExists(os.path.join(self.libdir, 'one.mp3')) # The old (copy-source) file should be marked for possible # deletion. self.assertEqual(task.old_paths, [self.srcpath])
def _apply_asis(self, items, album=True): """Run the "apply" coroutine.""" coro = importer.apply_choices(self.config) coro.next() _call_apply_choice(coro, items, importer.action.ASIS, album)
def test_apply_sentinel(self): coro = importer.apply_choices(self.session) coro.next() coro.send(importer.ImportTask.done_sentinel('toppath'))
def test_apply_as_tracks_uses_singleton_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. self._call_apply_choice(coro, [self.i], importer.action.TRACKS) self.assertExists(os.path.join(self.libdir, self.lib.path_formats["singleton"] + ".mp3"))
def test_apply_with_delete(self): coro = importer.apply_choices(_common.iconfig(self.lib, delete=True)) coro.next() # Prime coroutine. self._call_apply(coro, [self.i], self.info) self.assertNotExists(self.srcpath)
def test_apply_asis_uses_album_path(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() # Prime coroutine. _call_apply_choice(coro, [self.i], importer.action.ASIS) self.assertExists(os.path.join(self.libdir, 'one.mp3'))
def test_apply_populates_old_paths(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() task = _call_apply(coro, [self.i], self.info) self.assertEqual(task.old_paths, [self.srcpath])
def test_apply_sentinel(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() coro.send(importer.ImportTask.done_sentinel('toppath'))
def test_apply_sentinel(self): coro = importer.apply_choices(_common.iconfig(self.lib)) coro.next() coro.send(importer.ImportTask.done_sentinel("toppath"))