Esempio n. 1
0
class TestPlayer(TestCase):

    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0
        self.player.initialize()

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

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

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_duration(self):
        # This may failed?
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.assertIsNotNone(self.player.duration)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_seek(self):
        self.player.play(MP3_URL)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    def test_replay(self):
        song = FakeValidSongModel()
        self.player.play_song(song)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100
        self.player.replay()
        time.sleep(MPV_SLEEP_SECOND)
        self.assertTrue(self.player.position < 10)

    @skipIf(os.environ.get('TEST_ENV') == 'travis', '')
    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(os.environ.get('TEST_ENV') == 'travis', '')
    def test_set_volume(self):
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)
Esempio n. 2
0
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('fuocore.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()
Esempio n. 3
0
class TestPlayer(TestCase):

    def setUp(self):
        self.player = MpvPlayer()
        self.player.volume = 0
        self.player.initialize()

    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_replay(self):
        song = FakeValidSongModel()
        self.player.play_song(song)
        time.sleep(MPV_SLEEP_SECOND)
        self.player.position = 100
        self.player.replay()
        time.sleep(MPV_SLEEP_SECOND)
        self.assertTrue(self.player.position < 10)

    @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):
        self.player.volume = 30
        self.assertEqual(self.player.volume, 30)

    @mock.patch('fuocore.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()