curds: Add a way to cancel notifications
I expect this will mostly get used by testing code as we create and delete a bunch of different objects. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a2037d6c59
commit
a751bb4f61
|
@ -11,6 +11,11 @@ class Playlist(list):
|
|||
self.append(track)
|
||||
self.notify("on-add", track)
|
||||
|
||||
def never_mind(name, func):
|
||||
cb = Playlist.notifications.get(name, [])
|
||||
if func in cb:
|
||||
cb.remove(func)
|
||||
|
||||
def notify_me(name, func):
|
||||
Playlist.notifications.setdefault(name, []).append(func)
|
||||
|
||||
|
|
|
@ -80,3 +80,13 @@ class TestPlaylist(unittest.TestCase):
|
|||
plist.add(None)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track)
|
||||
|
||||
self.cb_plist = None
|
||||
self.cb_track = None
|
||||
track = tags.Track.add(os.path.join(path, "02 - Test Track 02.ogg"))
|
||||
playlist.Playlist.never_mind("on-add", self.on_add1)
|
||||
self.assertEqual(len(playlist.Playlist.notifications["on-add"]), 1)
|
||||
playlist.Playlist.never_mind("on-add", self.on_add1)
|
||||
plist.add(track)
|
||||
self.assertIsNone(self.cb_plist)
|
||||
self.assertEqual(self.cb_track, track)
|
||||
|
|
Loading…
Reference in New Issue