示例#1
0
def test_when_playlist_fm_mode_exited(app_mock, song, mocker):
    mock_fetch = mocker.MagicMock()
    app_mock.playlist = Playlist(app_mock)
    fm = FM(app_mock)
    fm.activate(mock_fetch)
    app_mock.playlist.mode = PlaylistMode.normal
    assert fm._activated is False  # noqa
示例#2
0
async def test_fetch_song_cancelled(event_loop, app_mock, song, mocker):
    mock_fetch = mocker.MagicMock()
    app_mock.playlist = Playlist(app_mock)
    app_mock.task_mgr = TaskManager(app_mock, event_loop)
    fm = FM(app_mock)
    fm.activate(mock_fetch)
    task_spec = app_mock.task_mgr.get_or_create(fm._fetch_songs_task_name)
    task_spec._task.cancel()
    await asyncio.sleep(0.1)  # schedule cancel callback
    assert fm._is_fetching_songs is False
示例#3
0
async def test_fetch_song_failed(event_loop, app_mock, song, mocker):
    mock_fetch = mocker.MagicMock(side_effect=ProviderIOError)
    mock_fm_add = mocker.patch.object(Playlist, 'fm_add')
    app_mock.playlist = Playlist(app_mock)
    app_mock.task_mgr = TaskManager(app_mock, event_loop)
    fm = FM(app_mock)
    fm.activate(mock_fetch)
    assert fm._is_fetching_songs is True
    await asyncio.sleep(0.1)  # schedule mock_fetch callback
    assert fm._is_fetching_songs is False
    assert not mock_fm_add.called
示例#4
0
async def test_multiple_eof_reached_signal(event_loop, app_mock, song, mocker):
    mock_fetch = mocker.MagicMock(return_value=[song] * 3)
    mock_fm_add = mocker.patch.object(Playlist, 'fm_add')
    app_mock.playlist = Playlist(app_mock)
    app_mock.task_mgr = TaskManager(app_mock, event_loop)
    fm = FM(app_mock)
    fm.activate(mock_fetch)
    app_mock.playlist.next()
    app_mock.playlist.next()
    task_spec = app_mock.task_mgr.get_or_create(fm._fetch_songs_task_name)
    await task_spec._task  # this is a little bit tricky
    # called exactly once
    mock_fetch.assert_called_once_with(3)
    assert mock_fm_add.called
示例#5
0
    def __init__(self, args, config):

        self.mode = config.MODE  # DEPRECATED: use app.config.MODE instead
        self.config = config
        self.args = args
        self.initialized = Signal()
        self.about_to_shutdown = Signal()

        self.plugin_mgr = PluginsManager(self)
        self.request = Request()  # TODO: rename request to http
        self.version_mgr = VersionManager(self)
        self.task_mgr = TaskManager(self)

        # Library.
        self.library = Library(config.PROVIDERS_STANDBY)
        # TODO: initialization should be moved into initialize
        Resolver.library = self.library

        # Player.
        self.player = Player(
            audio_device=bytes(config.MPV_AUDIO_DEVICE, 'utf-8'))
        self.playlist = Playlist(
            self, audio_select_policy=config.AUDIO_SELECT_POLICY)
        self.live_lyric = LiveLyric(self)
        self.fm = FM(self)

        # TODO: initialization should be moved into initialize
        self.player.set_playlist(self.playlist)

        self.about_to_shutdown.connect(lambda _: self.dump_state(), weak=False)
示例#6
0
async def test_reactivate_fm_mode_after_playing_other_songs(
        event_loop, app_mock, song, song1, mocker):
    def f(*args, **kwargs):
        return [song1]

    def is_active(fm):
        return fm.is_active

    playlist = Playlist(app_mock)
    app_mock.playlist = playlist
    app_mock.task_mgr = TaskManager(app_mock, event_loop)
    fm = FM(app_mock)
    fm.activate(f)
    assert playlist.mode is PlaylistMode.fm
    await asyncio.sleep(0.1)  # wait for fm-fetch-song task finished

    # user trigger play next
    app_mock.playlist.current_song = song
    assert playlist.mode is PlaylistMode.normal
    assert is_active(fm) is False

    await asyncio.sleep(0.1)  # wait for validate-song task finished
    assert playlist.list() == [song]

    fm.activate(f)
    assert is_active(fm) is True
    assert playlist.mode is PlaylistMode.fm
示例#7
0
def test_fm_activate_and_deactivate(app_mock, song, mocker):
    mock_fetch = mocker.MagicMock(return_value=[song])
    app_mock.playlist = Playlist(app_mock)
    fm = FM(app_mock)
    fm.activate(mock_fetch)
    assert app_mock.playlist.mode is PlaylistMode.fm
    assert app_mock.task_mgr.get_or_create.called

    fm.deactivate()
    assert app_mock.playlist.mode is PlaylistMode.normal