コード例 #1
0
ファイル: test_player.py プロジェクト: zeroWin/FeelUOwn
class TestPlayerAndPlaylist(TestCase):
    def setUp(self):
        self.player = MpvPlayer()

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    @mock.patch.object(MpvPlayer, 'play')
    def test_change_song(self, _):
        s1 = FakeValidSongModel()
        s2 = FakeValidSongModel()

        playlist = self.player.playlist
        playlist.add(s1)
        playlist.add(s2)

        self.player.play_song(s1)
        playlist.next()
        self.assertTrue(playlist.current_song, s2)

        playlist.previous()
        self.assertTrue(playlist.current_song, s1)

    @skipIf(cannot_play_audio, '')
    @mock.patch.object(MpvPlayer, 'play')
    def test_remove_current_song_2(self, mock_play):
        """当播放列表只有一首歌时,移除它"""
        s1 = FakeValidSongModel()
        self.player.playlist.current_song = s1
        time.sleep(MPV_SLEEP_SECOND)  # 让 Mpv 真正的开始播放
        self.player.playlist.remove(s1)
        self.assertEqual(len(self.player.playlist), 0)
        self.assertEqual(self.player.state, State.stopped)
コード例 #2
0
def test_serialize_app(mocker):
    app = mocker.Mock(spec=App)
    app.live_lyric = mocker.Mock()
    app.live_lyric.current_sentence = ''
    player = MpvPlayer()
    app.player = player
    app.playlist = player.playlist
    for format in ('plain', 'json'):
        serialize(format, app, brief=False)
        serialize(format, app, fetch=True)
    player.shutdown()
コード例 #3
0
ファイル: test_player.py プロジェクト: zeroWin/FeelUOwn
class TestPlayer(TestCase):
    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(cannot_play_audio, '')
    def test_play(self):
        self.player.play(MP3_URL)
        self.player.stop()

    @skipIf(cannot_play_audio, '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.assertIsNotNone(self.player.duration)

    @skipIf(cannot_play_audio, '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100

    @skipIf(cannot_play_audio, '')
    def test_play_pause_toggle_resume_stop(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.toggle()
        self.assertEqual(self.player.state, State.paused)
        self.player.resume()
        self.assertEqual(self.player.state, State.playing)
        self.player.pause()
        self.assertEqual(self.player.state, State.paused)
        self.player.stop()
        self.assertEqual(self.player.state, State.stopped)

    @skipIf(cannot_play_audio, '')
    def test_set_volume(self):
        cb = mock.Mock()
        self.player.volume_changed.connect(cb)
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)
        cb.assert_called_once_with(30)

    @mock.patch('feeluown.player.mpvplayer._mpv_set_option_string')
    def test_play_media_with_http_headers(self, mock_set_option_string):
        media = Media('http://xxx', http_headers={'referer': 'http://xxx'})
        self.player.play(media)
        assert mock_set_option_string.called
        self.player.stop()
コード例 #4
0
class TestPlayerAndPlaylist(TestCase):
    def setUp(self):
        self.player = MpvPlayer(Playlist(app_mock))

    def tearDown(self):
        self.player.stop()
        self.player.shutdown()

    @skipIf(cannot_play_audio, '')
    @mock.patch.object(MpvPlayer, 'play')
    def test_remove_current_song_2(self, mock_play):
        """当播放列表只有一首歌时,移除它"""
        s1 = FakeValidSongModel()
        self.player.playlist.current_song = s1
        time.sleep(MPV_SLEEP_SECOND)  # 让 Mpv 真正的开始播放
        self.player.playlist.remove(s1)
        self.assertEqual(len(self.player.playlist), 0)
        self.assertEqual(self.player.state, State.stopped)