Merge pull request #1091 from multikatt/1067

Run cleanup if extracted
This commit is contained in:
Adrian Sampson 2014-11-16 19:50:10 -08:00
commit 8fb4d9ebc9
2 changed files with 39 additions and 10 deletions

View file

@ -504,6 +504,9 @@ class ImportTask(object):
move=session.config['move'])
self._emit_imported(session.lib)
if isinstance(self, ArchiveImportTask):
self.cleanup()
def cleanup(self, copy=False, delete=False, move=False):
"""Remove and prune imported paths.
"""

View file

@ -335,6 +335,41 @@ class NonAutotaggedImportTest(_common.TestCase, ImportHelper):
self.assertEqual(os.readlink(filename), mediafile.path)
def create_archive(session):
(handle, path) = mkstemp(dir=session.temp_dir)
os.close(handle)
archive = ZipFile(path, mode='w')
archive.write(os.path.join(_common.RSRC, 'full.mp3'),
'full.mp3')
archive.close()
return path
class RmTempTest(unittest.TestCase, ImportHelper):
"""Tests that temporarily extracted archives are properly removed
after usage.
"""
def setUp(self):
self.setup_beets()
self.want_resume = False
self.config['incremental'] = False
self._old_home = None
def tearDown(self):
self.teardown_beets()
def test_rm(self):
zip_path = create_archive(self)
archive_task = importer.ArchiveImportTask(zip_path)
archive_task.extract()
tmp_path = archive_task.toppath
self._setup_import_session(autotag=False, import_dir=tmp_path)
self.assertTrue(os.path.exists(tmp_path))
archive_task.finalize(self)
self.assertFalse(os.path.exists(tmp_path))
class ImportZipTest(unittest.TestCase, ImportHelper):
def setUp(self):
@ -344,7 +379,7 @@ class ImportZipTest(unittest.TestCase, ImportHelper):
self.teardown_beets()
def test_import_zip(self):
zip_path = self.create_archive()
zip_path = create_archive(self)
self.assertEqual(len(self.lib.items()), 0)
self.assertEqual(len(self.lib.albums()), 0)
@ -353,15 +388,6 @@ class ImportZipTest(unittest.TestCase, ImportHelper):
self.assertEqual(len(self.lib.items()), 1)
self.assertEqual(len(self.lib.albums()), 1)
def create_archive(self):
(handle, path) = mkstemp(dir=self.temp_dir)
os.close(handle)
archive = ZipFile(path, mode='w')
archive.write(os.path.join(_common.RSRC, 'full.mp3'),
'full.mp3')
archive.close()
return path
class ImportTarTest(ImportZipTest):