tests and a bug fix for #229

This commit is contained in:
Adrian Sampson 2011-09-15 21:26:19 -07:00
parent af98a2fb01
commit 80ddff263f
2 changed files with 54 additions and 1 deletions

View file

@ -104,6 +104,10 @@ def prune_dirs(path, root, clutter=('.DS_Store', 'Thumbs.db')):
ancestors.reverse()
for directory in ancestors:
directory = syspath(directory)
if not os.path.exists(directory):
# Directory gone already.
continue
if all(fn in clutter for fn in os.listdir(directory)):
# Directory contains only clutter (or nothing).
try:

View file

@ -192,7 +192,7 @@ class AlbumFileTest(unittest.TestCase):
def test_albuminfo_move_to_custom_dir(self):
self.ai.move(basedir=self.otherdir)
self.lib.load(self.i)
self.assert_('testotherdir' in self.i.path)
self.assertTrue('testotherdir' in self.i.path)
class ArtFileTest(unittest.TestCase, _common.ExtraAsserts):
def setUp(self):
@ -320,6 +320,35 @@ class ArtFileTest(unittest.TestCase, _common.ExtraAsserts):
os.chmod(newart, 0777)
os.chmod(ai.artpath, 0777)
def test_move_last_file_moves_albumart(self):
oldartpath = self.lib.albums()[0].artpath
self.assertExists(oldartpath)
self.ai.album = 'different_album'
self.lib.move(self.i)
artpath = self.lib.albums()[0].artpath
self.assertTrue('different_album' in artpath)
self.assertExists(artpath)
self.assertNotExists(oldartpath)
def test_move_not_last_file_does_not_move_albumart(self):
i2 = item()
i2.albumid = self.ai.id
self.lib.add(i2)
oldartpath = self.lib.albums()[0].artpath
self.assertExists(oldartpath)
self.i.album = 'different_album'
self.i.album_id = None # detach from album
self.lib.move(self.i)
artpath = self.lib.albums()[0].artpath
self.assertFalse('different_album' in artpath)
self.assertEqual(artpath, oldartpath)
self.assertExists(oldartpath)
class RemoveTest(unittest.TestCase, _common.ExtraAsserts):
def setUp(self):
# Make library and item.
@ -444,6 +473,26 @@ class SafeMoveCopyTest(unittest.TestCase, _common.ExtraAsserts):
util.copy(self.path, self.path)
self.assertExists(self.path)
class PruneTest(unittest.TestCase, _common.ExtraAsserts):
def setUp(self):
self.base = os.path.join(_common.RSRC, 'testdir')
os.mkdir(self.base)
self.sub = os.path.join(self.base, 'subdir')
os.mkdir(self.sub)
def tearDown(self):
if os.path.exists(self.base):
shutil.rmtree(self.base)
def test_prune_existent_directory(self):
util.prune_dirs(self.sub, self.base)
self.assertExists(self.base)
self.assertNotExists(self.sub)
def test_prune_nonexistent_directory(self):
util.prune_dirs(os.path.join(self.sub, 'another'), self.base)
self.assertExists(self.base)
self.assertNotExists(self.sub)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)