curds: Don't loop len(1) playlists

We need to check if looping is true, even if length is one, before
setting the current index.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-03-23 10:12:14 -04:00
parent 61d6221e30
commit f765536c86
2 changed files with 6 additions and 0 deletions

View File

@ -45,6 +45,8 @@ class Playlist():
if max == -1:
return None
elif max == 0:
if self.loop == False and self.current == 0:
return None
self.current = 0
elif self.random == True:
self.current = (self.current + random.randint(1, max)) % max

View File

@ -174,8 +174,12 @@ class TestPlaylist(unittest.TestCase):
track = tags.Track.lookup(os.path.join(path, "01 - Test Track 01.ogg"))
plist.add(track)
self.assertEqual(plist.current, -1)
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)
self.assertEqual(plist.next(), None)
self.assertEqual(plist.current, 0)
plist.set_loop(True)
self.assertEqual(plist.next(), track)
self.assertEqual(plist.current, 0)