trackdb: Give TagStacks state related functions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0a8462e5c5
commit
5870e7e9a1
|
@ -12,6 +12,13 @@ class TagStack:
|
|||
track.add_to_playlist("Previous")
|
||||
return track
|
||||
|
||||
def __getstate__(self):
|
||||
return { "tags" : self.tags }
|
||||
|
||||
def __setstate__(self, state):
|
||||
self.__dict__.update(state)
|
||||
self.PushPop = publisher.Publisher()
|
||||
|
||||
def current(self):
|
||||
if len(self.tags) == 0:
|
||||
return tags.User.store["Collection"]
|
||||
|
@ -50,3 +57,7 @@ class TagStack:
|
|||
def queue(self, track):
|
||||
track.add_to_playlist("Up Next")
|
||||
self.push(tags.User["Up Next"])
|
||||
|
||||
def reset(self):
|
||||
self.tags.clear()
|
||||
self.PushPop.reset()
|
||||
|
|
|
@ -109,3 +109,21 @@ class TestTagStack(unittest.TestCase):
|
|||
self.assertEqual(s.tags, [ tags.User["Up Next"] ])
|
||||
self.assertEqual(s.next().n, 1)
|
||||
self.assertEqual(tags.User["Up Next"].tracks, [ ])
|
||||
|
||||
def test_tag_stack_state(self):
|
||||
s = stack.TagStack()
|
||||
t = tag.Tag("Test")
|
||||
s.push(t)
|
||||
|
||||
state = s.__getstate__()
|
||||
self.assertEqual(state, { "tags" : [ t ] })
|
||||
|
||||
s.__dict__.clear()
|
||||
s.__setstate__(state)
|
||||
self.assertEqual(s.tags, [ t ])
|
||||
self.assertIsInstance(s.PushPop, publisher.Publisher)
|
||||
|
||||
s.PushPop.register(self.on_push_pop)
|
||||
s.reset()
|
||||
self.assertEqual(s.tags, [ ])
|
||||
self.assertEqual(len(s.PushPop.subscribers), 0)
|
||||
|
|
Loading…
Reference in New Issue