local: Fix handling of single in eot_track (fixes #496)

- Adds test cases for code paths that caused bug
- Short circuits EOT next track handling when in single mode.
This commit is contained in:
Thomas Adamcik 2013-10-20 21:43:19 +02:00
parent d968244712
commit f1f223bba8
2 changed files with 36 additions and 4 deletions

View File

@ -161,6 +161,11 @@ class TracklistController(object):
if not self.tl_tracks:
return None
if self.single and self.repeat:
return tl_track
elif self.single:
return None
if self.random and not self._shuffled:
if self.repeat or self._first_shuffle:
logger.debug('Shuffling tracks')
@ -176,10 +181,7 @@ class TracklistController(object):
position = self.index(tl_track)
if self.repeat and self.single:
return self.tl_tracks[position]
if self.repeat and not self.single:
if self.repeat:
return self.tl_tracks[(position + 1) % len(self.tl_tracks)]
try:

View File

@ -339,6 +339,7 @@ class LocalPlaybackProviderTest(unittest.TestCase):
self.tracklist.single = True
self.tracklist.repeat = True
self.playback.play()
self.assertEqual(self.playback.current_track, self.tracks[0])
self.playback.next()
self.assertEqual(self.playback.current_track, self.tracks[1])
@ -899,9 +900,38 @@ class LocalPlaybackProviderTest(unittest.TestCase):
self.tracklist.single = True
self.tracklist.repeat = True
self.playback.play()
self.assertEqual(self.playback.current_track, self.tracks[0])
self.playback.on_end_of_track()
self.assertEqual(self.playback.current_track, self.tracks[0])
@populate_tracklist
def test_end_of_song_with_single_random_and_repeat_starts_same(self):
self.tracklist.single = True
self.tracklist.repeat = True
self.tracklist.random = True
self.playback.play()
current_track = self.playback.current_track
self.playback.on_end_of_track()
self.assertEqual(self.playback.current_track, current_track)
@populate_tracklist
def test_end_of_song_with_single_stops(self):
self.tracklist.single = True
self.playback.play()
self.assertEqual(self.playback.current_track, self.tracks[0])
self.playback.on_end_of_track()
self.assertEqual(self.playback.current_track, None)
self.assertEqual(self.playback.state, PlaybackState.STOPPED)
@populate_tracklist
def test_end_of_song_with_single_and_random_stops(self):
self.tracklist.single = True
self.tracklist.random = True
self.playback.play()
self.playback.on_end_of_track()
self.assertEqual(self.playback.current_track, None)
self.assertEqual(self.playback.state, PlaybackState.STOPPED)
@populate_tracklist
def test_end_of_playlist_stops(self):
self.playback.play(self.tracklist.tl_tracks[-1])