class TestPlaylist(TestCase): def setUp(self): self.s1 = FakeSongModel() self.s2 = FakeSongModel() self.playlist = Playlist() self.playlist.add(self.s1) self.playlist.add(self.s2) def tearDown(self): self.playlist.clear() def test_add(self): self.playlist.add(self.s1) self.assertEqual(len(self.playlist), 2) @mock.patch.object(MpvPlayer, 'play') def test_remove_current_song(self, mock_play): s3 = FakeSongModel() self.playlist.add(s3) self.playlist.current_song = self.s2 self.playlist.remove(self.s2) self.assertEqual(self.playlist.current_song, s3) self.assertEqual(len(self.playlist), 2) def test_remove(self): self.playlist.remove(self.s1) self.assertEqual(len(self.playlist), 1) @mock.patch.object(MpvPlayer, 'play') def test_remove_2(self, mock_play): """播放器正在播放,移除一首歌""" self.playlist.current_song = self.s2 self.playlist.remove(self.s1) self.assertEqual(self.playlist.current_song, self.s2) self.assertEqual(len(self.playlist), 1) def test_remove_3(self): """移除一首不存在的歌""" self.playlist.remove(FakeSongModel()) self.assertEqual(len(self.playlist), 2) def test_remove_4(self): """移除一首被标记为无效的歌曲""" self.playlist.mark_as_bad(self.s2) self.assertEqual(len(self.playlist._bad_songs), 1) self.playlist.remove(self.s2) self.assertEqual(len(self.playlist), 1) self.assertEqual(len(self.playlist._bad_songs), 0) def test_getitem(self): self.assertEqual(self.playlist[1], self.s2) def test_mark_as_bad(self): self.assertEqual(self.playlist.next_song, self.s1) self.playlist.mark_as_bad(self.s1) self.assertEqual(self.playlist.next_song, self.s2) def test_list(self): self.assertIn(self.s1, self.playlist.list()) def test_set_current_song(self): """将一首不存在于播放列表的歌曲设置为当前播放歌曲""" s3 = FakeSongModel() self.playlist.current_song = s3 self.assertIn(s3, self.playlist) def test_next_song(self): self.playlist.playback_mode = PlaybackMode.sequential self.playlist.current_song = self.s2 self.assertIsNone(self.playlist.next_song) self.playlist.playback_mode = PlaybackMode.random self.playlist.next_song # assert no exception def test_previous_song(self): self.assertEqual(self.playlist.previous_song, self.s2) self.playlist.current_song = self.s2 self.assertEqual(self.playlist.previous_song, self.s1)
def setUp(self): self.s1 = FakeSongModel() self.s2 = FakeSongModel() self.playlist = Playlist() self.playlist.add(self.s1) self.playlist.add(self.s2)
class TestPlaylist(TestCase): def setUp(self): self.s1 = FakeSongModel() self.s2 = FakeSongModel() self.playlist = Playlist() self.playlist.add(self.s1) self.playlist.add(self.s2) def tearDown(self): self.playlist.clear() def test_add(self): self.playlist.add(self.s1) self.assertEqual(len(self.playlist), 2) def test_remove_current_song(self): s3 = FakeSongModel() self.playlist.add(s3) self.playlist.current_song = self.s2 self.playlist.remove(self.s2) self.assertEqual(self.playlist.current_song, s3) self.assertEqual(len(self.playlist), 2) def test_remove(self): self.playlist.remove(self.s1) self.assertEqual(len(self.playlist), 1)