curds: Add extra playlist next() tests

We want to make sure we get the expected results when calling next() on
empty playlists and with playlists that only have one track.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-03-12 11:09:00 -04:00
parent 63d6168229
commit dca914860b
2 changed files with 32 additions and 1 deletions

View File

@ -16,7 +16,11 @@ class Playlist(list):
def next(self):
max = len(self) - 1
if self.random == True:
if max == -1:
return None
elif max == 0:
self.current = 0
elif self.random == True:
self.current = (self.current + random.randint(1, max)) % max
elif self.current < max:
self.current += 1

View File

@ -145,3 +145,30 @@ class TestPlaylist(unittest.TestCase):
track = plist.next()
self.assertEqual(plist.current, i)
self.assertEqual(track, tracks[i])
def test_playlist_next_empty(self):
plist = playlist.Playlist("Test Playlist")
self.assertIsNone(plist.next())
self.assertEqual(plist.current, -1)
plist.set_loop(True)
self.assertIsNone(plist.next())
self.assertEqual(plist.current, -1)
plist.set_random(True)
self.assertIsNone(plist.next())
self.assertEqual(plist.current, -1)
def test_playlist_next_one(self):
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
plist = playlist.Playlist("Test Playlist")
track = tags.Track.lookup(os.path.join(path, "01 - Test Track 01.ogg"))
plist.add(track)
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)
plist.set_loop(True)
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)
plist.set_random(True)
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)