curds: Replace the Library.add() function with a lookup

This makes the user's intentions a little more explicit, and saves us a
couple of lines of code.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-02 11:24:34 -04:00
parent 084567e3b8
commit 2cf0ad8df9
5 changed files with 13 additions and 15 deletions

View File

@ -66,9 +66,6 @@ class LibraryManager(PlaylistManagerBase):
def normalize(self, path):
return os.path.abspath(path)
def add(self, path):
return self.lookup(path, allocate=True)
class PlaylistManager(PlaylistManagerBase):
def __init__(self):

View File

@ -65,7 +65,7 @@ class TestPlaylistManager(unittest.TestCase):
self.assertEqual(self.playman.index(self.playman[3]), 3)
def test_manager_library(self):
plist = self.playman.lookup("Library").add(test_library + "/")
plist = self.playman.lookup("Library").lookup(test_library + "/", allocate=True)
self.assertEqual(self.cb_plist, plist)
self.assertEqual(str(self.playman.lookup("Library")), "<big>Library</big>")
self.assertEqual(self.playman.lookup("Library").name, "Library")
@ -74,10 +74,11 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIsInstance(plist, library.LibraryPlaylist)
self.cb_plist = None
self.assertEqual(self.playman.lookup("Library").add(test_library), plist)
self.assertEqual(self.playman.lookup("Library").lookup(test_library), plist)
self.assertIsNone(self.cb_plist)
alist = self.playman.lookup("Library").add(test_album)
self.assertIsNone(self.playman.lookup("Library").lookup(test_album))
alist = self.playman.lookup("Library").lookup(test_album, allocate=True)
self.assertEqual(self.cb_plist, alist)
self.assertIsInstance(alist, library.LibraryPlaylist)
self.assertNotEqual(id(plist), id(alist))
@ -104,7 +105,7 @@ class TestPlaylistManager(unittest.TestCase):
self.assertEqual(genreman.name, "Genre")
self.assertEqual(genreman.icon, "audio-x-generic-symbolic")
self.playman.lookup("Library").add(test_library)
self.playman.lookup("Library").lookup(test_library, allocate=True)
library.join()
plist = genreman.lookup("Test Genre 1")
@ -126,11 +127,11 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIn((genreman.add_track, False), notify.registered["new-track"])
def test_manager_on_scan(self):
plist = self.playman.lookup("Library").add(test_library)
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
self.assertEqual(self.playman.lookup("Library").index(plist), 0)
self.assertEqual(self.playman.lookup("Library")[0], plist)
alist = self.playman.lookup("Library").add(test_album)
alist = self.playman.lookup("Library").lookup(test_album, allocate=True)
self.assertEqual(self.playman.lookup("Library").index(alist), 0)
self.assertEqual(self.playman.lookup("Library").index(plist), 1)
self.assertEqual(self.playman.lookup("Library")[0], alist)
@ -150,7 +151,7 @@ class TestPlaylistManager(unittest.TestCase):
clist = self.playman.lookup("Collection")
prev = self.playman.lookup("Previous")
plist = self.playman.lookup("Library").add(test_library)
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
library.join()
track1 = self.playman.next()

View File

@ -142,7 +142,7 @@ def library_cancel_clicked(self, *args):
def library_ok_clicked(self, *args):
path = LibraryChooser.get_filename()
LibraryPopover.popdown()
curds.PlaylistManager.lookup("Library").add(path)
curds.PlaylistManager.lookup("Library").lookup(path, allocate=True)
LibraryAdd = gtk.Builder.get_object("library_add")

View File

@ -121,7 +121,7 @@ class TestGst(unittest.TestCase):
gst.PrevButton.clicked()
self.assertIsNone(curds.PlaylistManager.track)
curds.PlaylistManager.lookup("Library").add(test_album)
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.playlist.library.join()
self.assertEqual(curds.PlaylistManager.lookup("Collection").current, -1)

View File

@ -94,8 +94,8 @@ class TestManager(unittest.TestCase):
self.assertFalse(model.iter_has_child(iter))
self.assertFalse(model.iter_n_children(iter), 0)
plist_mgr.lookup("Library").add(test_album1)
plist_mgr.lookup("Library").add(test_album2)
plist_mgr.lookup("Library").lookup(test_album1, allocate=True)
plist_mgr.lookup("Library").lookup(test_album2, allocate=True)
curds.playlist.library.join()
self.assertTrue(model.iter_has_child(iter))
self.assertEqual(model.iter_n_children(iter), len(pl_top))
@ -135,7 +135,7 @@ class TestManager(unittest.TestCase):
iter = model.find_playlist(plist_mgr.lookup("Collection"))
path = model.get_path(iter)
plist = plist_mgr.lookup("Library").add(test_album1)
plist = plist_mgr.lookup("Library").lookup(test_album1, allocate=True)
curds.playlist.library.join()
while curds.notify.run_queued():
continue