trackdb: Give stacks an easy way to queue up tracks

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-07-07 13:56:11 -04:00
parent db5bfdb550
commit 925664f7aa
2 changed files with 16 additions and 0 deletions

View File

@ -34,3 +34,7 @@ class TagStack:
self.tags.remove(tag)
self.tags.insert(0, tag)
tag.stacked()
def queue(self, track):
track.add_to_playlist("Up Next")
self.push(tags.User["Up Next"])

View File

@ -7,10 +7,14 @@ import unittest
class FakeTrack:
def __init__(self, n):
self.n = n
self.length = n
def add_to_playlist(self, name):
tags.User.add(name, self)
def remove_from_playlist(self, name):
tags.User[name].remove_track(self)
class TestTagStack(unittest.TestCase):
def tearDown(self):
tags.reset()
@ -77,3 +81,11 @@ class TestTagStack(unittest.TestCase):
self.assertEqual(s.tags, [ t1, t2 ])
s.push(tags.User["Collection"])
self.assertEqual(s.tags, [ ])
def test_tag_stack_queue(self):
s = stack.TagStack()
s.queue(FakeTrack(1))
self.assertEqual(s.tags, [ tags.User["Up Next"] ])
self.assertEqual(s.next().n, 1)
self.assertEqual(tags.User["Up Next"].tracks, [ ])