curds: Add a Previous playlist
This playlist is designed to hold all the tracks that have been selected for playback, and iterate through them backwards if needed. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a5535a5daa
commit
c794faf95c
|
@ -0,0 +1,19 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import playlist
|
||||
from .. import notify
|
||||
|
||||
class PreviousPlaylist(playlist.Playlist):
|
||||
def __init__(self):
|
||||
playlist.Playlist.__init__(self, "Previous", "edit-undo")
|
||||
|
||||
def add(self, track):
|
||||
if track is not None and track not in self:
|
||||
self.list.insert(0, track)
|
||||
self.current = 0
|
||||
notify.Notify.notify("add-track", self, track)
|
||||
|
||||
def set_loop(self, loop):
|
||||
return playlist.Playlist.set_loop(self, False)
|
||||
|
||||
def set_random(self, random):
|
||||
return playlist.Playlist.set_random(self, False)
|
|
@ -0,0 +1,67 @@
|
|||
# Copyright 2019 (c) Anna Schumaker.
|
||||
from . import playlist
|
||||
from . import previous
|
||||
from .. import notify
|
||||
from .. import tags
|
||||
import os
|
||||
import unittest
|
||||
|
||||
test_album = os.path.abspath("./trier/Test Library/Test Artist 01/Test Album 1")
|
||||
|
||||
class TestPreviousPlaylist(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.cb_plist = None
|
||||
self.cb_track = None
|
||||
|
||||
def tearDown(self):
|
||||
notify.Notify.notifications.clear()
|
||||
|
||||
def on_add_track(self, plist, track):
|
||||
if isinstance(plist, previous.PreviousPlaylist):
|
||||
self.cb_plist = plist
|
||||
self.cb_track = track
|
||||
|
||||
def test_previous_playlist(self):
|
||||
plist = previous.PreviousPlaylist()
|
||||
notify.Notify.notify_me("add-track", self.on_add_track)
|
||||
|
||||
self.assertIsInstance(plist, previous.PreviousPlaylist)
|
||||
self.assertIsInstance(plist, playlist.Playlist)
|
||||
self.assertEqual(plist.name, "Previous")
|
||||
self.assertEqual(plist.icon, "edit-undo")
|
||||
|
||||
self.assertFalse(plist.loop)
|
||||
self.assertFalse(plist.set_loop(True))
|
||||
self.assertFalse(plist.loop)
|
||||
|
||||
self.assertFalse(plist.random)
|
||||
self.assertFalse(plist.set_random(True))
|
||||
self.assertFalse(plist.random)
|
||||
|
||||
track1 = tags.Track.lookup(os.path.join(test_album, "01 - Test Track 01.ogg"))
|
||||
track2 = tags.Track.lookup(os.path.join(test_album, "02 - Test Track 02.ogg"))
|
||||
track3 = tags.Track.lookup(os.path.join(test_album, "03 - Test Track 03.ogg"))
|
||||
|
||||
self.assertEqual(plist.current, -1)
|
||||
self.assertEqual(plist.next(), None)
|
||||
|
||||
plist.add(track1)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track1)
|
||||
self.assertEqual(plist.current, 0)
|
||||
self.assertEqual(plist.next(), None)
|
||||
|
||||
plist.add(track2)
|
||||
self.assertEqual(self.cb_plist, plist)
|
||||
self.assertEqual(self.cb_track, track2)
|
||||
self.assertEqual(plist.current, 0)
|
||||
|
||||
self.assertEqual(len(plist), 2)
|
||||
self.assertEqual(plist[0], track2)
|
||||
self.assertEqual(plist[1], track1)
|
||||
|
||||
self.assertEqual(plist.next(), track1)
|
||||
self.assertEqual(plist.current, 1)
|
||||
|
||||
plist.add(track3)
|
||||
self.assertEqual(plist.current, 0)
|
Loading…
Reference in New Issue