Add previous tests and implementation

This commit is contained in:
Thomas Adamcik 2010-02-14 16:08:38 +01:00
parent 4c80a585eb
commit f9312b372f
3 changed files with 29 additions and 1 deletions

View File

@ -114,6 +114,9 @@ class BasePlaybackController(object):
def next(self):
raise NotImplementedError
def previous(self):
raise NotImplementedError
def pause(self):
raise NotImplementedError

View File

@ -96,6 +96,20 @@ class GStreamerPlaybackController(BasePlaybackController):
next_track = playlist.tracks[self.playlist_position+1]
self.play(next_track)
def previous(self):
playlist = self.backend.current_playlist.playlist
if not self.current_track:
self.play()
elif not playlist.tracks:
self.stop()
elif self.playlist_position - 1 > 0:
first_track = playlist.tracks[0]
self.play(first_track)
else:
previous_track = playlist.tracks[self.playlist_position-1]
self.play(previous_track)
@property
def volume(self):
return int(self.bin.get_property('volume') * 100)

View File

@ -290,15 +290,26 @@ class BasePlaybackControllerTest(object):
self.assertEqual(playback.current_track, tracks[-1])
self.assertEqual(playback.playlist_position, len(tracks) - 1)
def test_previous(self):
def test_next_for_empty_playlist(self):
raise NotImplementedError
@populate_playlist
def test_previous(self):
tracks = self.backend.current_playlist.playlist.tracks
self.playback.play()
self.playback.next()
self.playback.previous()
self.assertEqual(self.playback.current_track, tracks[0])
def test_previous_triggers_playback(self):
raise NotImplementedError
def test_previous_at_start_of_playlist(self):
raise NotImplementedError
def test_previous_for_empty_playlist(self):
raise NotImplementedError
@populate_playlist
def test_next_track_before_play(self):
tracks = self.backend.current_playlist.playlist.tracks