def test_playing_playlist_ops(request, client, active_playlist_with_item, new_playlist_with_items): request.addfinalizer(lambda: client.stop()) request.addfinalizer(lambda: client.set_active_playlist(0)) client.start(1, False) time.sleep(0.5) active_playlist = client.get_active_playlist() assert active_playlist == 0 client.set_active_playlist(1) client.set_playing_playlist(1) client.stop() active_playlist = client.get_active_playlist() assert active_playlist == 1 client.play_or_pause() time.sleep(0.5) _, handle = client.get_now_playing() formatted = dict(handle) assert formatted[b'path'] == new_playlist_with_items.files[0].path.encode() client.set_active_playlist(0) client.reset_playing_playlist() assert client.get_playing_playlist() == 0
def test_activeplaylist_sort_by_format(request, client, test_files_with_varying_length): test_files = test_files_with_varying_length random.shuffle(test_files) paths = [test_file.path for test_file in test_files] request.addfinalizer(lambda: client.activeplaylist_remove_items( list(range(len(test_files))))) request.addfinalizer(lambda: client.stop()) client.activeplaylist_add_items(paths) # This is a trick for making foobar2000 recognise the lengths of each track. # Without it, the sorting has no effect. for index in range(len(test_files)): client.next() time.sleep(0.1) client.activeplaylist_sort_by_format(b"%length_seconds%", False) items = [dict(item) for item in client.activeplaylist_get_all_items()] items_paths = [os.path.basename(item[b'path'].decode()) for item in items] expected_paths = [ os.path.basename(test_file.path) for test_file in sorted(test_files, key=lambda test_file: test_file.length) ] # Now the items should be sorted by length assert expected_paths == items_paths
def test_is_playing(request, client, active_playlist_with_item): assert not client.is_playing() client.start(1, False) request.addfinalizer(lambda: client.stop()) # Foobar needs time for getting the file and starting the actual playback. time.sleep(0.5) assert client.is_playing()
def test_playback_get_length(request, client, active_playlist_with_item): request.addfinalizer(lambda: client.stop()) client.start(1, False) time.sleep(0.5) length = client.playback_get_length() length_ex = client.playback_get_length_ex() assert length == length_ex == active_playlist_with_item.files[0].length
def test_get_playing_item_location(request, client, active_playlist_with_item): client.start(1, False) request.addfinalizer(lambda: client.stop()) time.sleep(0.5) success, playlist, item = client.get_playing_item_location( active_playlist_with_item.index, 0) assert playlist == active_playlist_with_item.index assert item == 0
def test_previous_when_at_first(request, client, active_playlist_with_items): client.start(1, False) request.addfinalizer(lambda: client.stop()) time.sleep(0.5) client.previous() time.sleep(0.5) playing, current_playing = client.get_now_playing() assert not playing assert not current_playing
def test_toggle_pause(request, client, active_playlist_with_item): client.start(1, False) request.addfinalizer(lambda: client.toggle_pause() if client.is_paused() else None) request.addfinalizer(lambda: client.stop()) time.sleep(0.5) assert not client.is_paused() client.toggle_pause() assert client.is_paused() client.toggle_pause() assert not client.is_paused()
def test_play_or_pause(request, client, active_playlist_with_item): client.start(1, False) request.addfinalizer(lambda: client.stop()) time.sleep(0.5) # Now it should be started. assert client.is_playing() client.play_or_pause() assert client.is_paused() client.play_or_pause() assert not client.is_paused() assert client.is_playing()
def test_is_paused(request, client, active_playlist_with_item): # Initially it is not paused assert not client.is_paused() client.start(1, False) request.addfinalizer(lambda: client.stop()) # Foobar needs time for getting the file and starting the actual playback. time.sleep(0.5) client.pause(True) assert client.is_paused() client.pause(False) assert not client.is_paused()
def test_playback_seek_ops(request, client, active_playlist_with_item): request.addfinalizer(lambda: client.stop()) client.start(1, False) time.sleep(0.5) assert client.playback_can_seek() client.playback_seek(2) position = client.playback_get_position() assert position >= 2 client.playback_seek_delta(5) position = client.playback_get_position() assert position >= 7 client.playback_seek_delta(-4) position = client.playback_get_position() assert 3 <= position < 7
def test_get_now_playing(request, client, active_playlist_with_item): client.start(1, False) request.addfinalizer(lambda: client.stop()) # Foobar needs time for getting the file and starting the actual playback. time.sleep(0.5) is_playing, now_playing = client.get_now_playing() assert is_playing now_playing_formatted = dict(now_playing) assert b'index' in now_playing_formatted assert b'path' in now_playing_formatted assert b'selected' in now_playing_formatted assert now_playing_formatted[b'index'] == 0 assert now_playing_formatted[b'path'] == active_playlist_with_item.files[ 0].path.encode() assert now_playing_formatted[b'selected']
def test_previous_next(request, client, active_playlist_with_items): client.start(1, False) request.addfinalizer(lambda: client.stop()) time.sleep(0.5) now_playing = dict(client.get_now_playing()[1]) first = active_playlist_with_items.files[0] second = active_playlist_with_items.files[1] assert now_playing[b'path'] == first.path.encode() client.next() time.sleep(0.5) now_playing = dict(client.get_now_playing()[1]) assert now_playing[b'path'] == second.path.encode() client.previous() time.sleep(0.5) now_playing = dict(client.get_now_playing()[1]) assert now_playing[b'path'] == first.path.encode()