local/core: Add and fix more random related tests.

- Adds tests for eot_track vs next_track as we were only testing the one code
  path.
- Makes test_random_until_end_of_playlist_and_play_from_start actually test
  random and not repeat.
- Adds test_play_track_then_enable_random which is the underlying bug covered
  by the regression test for issue #17.
This commit is contained in:
Thomas Adamcik 2013-10-20 18:35:03 +02:00
parent 025bafc114
commit 66ae1b8eee

View File

@ -957,10 +957,7 @@ class LocalPlaybackProviderTest(unittest.TestCase):
self.assertEqual(self.tracklist.consume, False)
@populate_tracklist
@mock.patch('random.shuffle')
def test_random_until_end_of_playlist(self, shuffle_mock):
shuffle_mock.side_effect = lambda tracks: tracks.reverse()
def test_random_until_end_of_playlist(self):
self.tracklist.random = True
self.playback.play()
for _ in self.tracks[1:]:
@ -968,9 +965,19 @@ class LocalPlaybackProviderTest(unittest.TestCase):
tl_track = self.playback.current_tl_track
self.assertEqual(self.tracklist.next_track(tl_track), None)
@populate_tracklist
def test_random_with_eot_until_end_of_playlist(self):
self.tracklist.random = True
self.playback.play()
for _ in self.tracks[1:]:
self.playback.on_end_of_track()
tl_track = self.playback.current_tl_track
self.assertEqual(self.tracklist.eot_track(tl_track), None)
@populate_tracklist
def test_random_until_end_of_playlist_and_play_from_start(self):
self.tracklist.repeat = True
self.tracklist.random = True
self.playback.play()
for _ in self.tracks:
self.playback.next()
tl_track = self.playback.current_tl_track
@ -979,12 +986,24 @@ class LocalPlaybackProviderTest(unittest.TestCase):
self.playback.play()
self.assertEqual(self.playback.state, PlaybackState.PLAYING)
@populate_tracklist
def test_random_with_eot_until_end_of_playlist_and_play_from_start(self):
self.tracklist.random = True
self.playback.play()
for _ in self.tracks:
self.playback.on_end_of_track()
tl_track = self.playback.current_tl_track
self.assertNotEqual(self.tracklist.eot_track(tl_track), None)
self.assertEqual(self.playback.state, PlaybackState.STOPPED)
self.playback.play()
self.assertEqual(self.playback.state, PlaybackState.PLAYING)
@populate_tracklist
def test_random_until_end_of_playlist_with_repeat(self):
self.tracklist.repeat = True
self.tracklist.random = True
self.playback.play()
for _ in self.tracks:
for _ in self.tracks[1:]:
self.playback.next()
tl_track = self.playback.current_tl_track
self.assertNotEqual(self.tracklist.next_track(tl_track), None)
@ -999,6 +1018,23 @@ class LocalPlaybackProviderTest(unittest.TestCase):
played.append(self.playback.current_track)
self.playback.next()
@populate_tracklist
@mock.patch('random.shuffle')
def test_play_track_then_enable_random(self, shuffle_mock):
# Covers underlying issue IssueGH17RegressionTest tests for.
shuffle_mock.side_effect = lambda tracks: tracks.reverse()
expected = self.tl_tracks[1::-1]
actual = []
self.playback.play()
self.tracklist.random = True
for _ in self.tracks[1:]:
self.playback.next()
actual.append(self.playback.current_tl_track)
self.assertEqual(actual, expected)
@populate_tracklist
def test_playing_track_that_isnt_in_playlist(self):
test = lambda: self.playback.play((17, Track()))