Skip to content

Commit

Permalink
add tests for playerctld shift error conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsalomon committed Jun 4, 2020
1 parent 8ece9ef commit afd253d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion playerctl/playerctl-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ int playercmd_shift(GDBusConnection *connection) {
G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &error);
g_object_unref(connection);
if (error != NULL) {
g_printerr("%s", error->message);
g_printerr("Cannot shift: %s\n", error->message);
return 1;
}
return 0;
Expand Down
31 changes: 28 additions & 3 deletions test/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def playerctld_shift(bus_address):
env=env,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT)
await shift.wait()
return await shift.wait()

@pytest.mark.asyncio
async def test_daemon_shift_simple(bus_address):
Expand All @@ -179,11 +179,13 @@ async def test_daemon_shift_simple(bus_address):
line = await proc.queue.get()
assert line == 'playerctld: artist2 - title2', proc.queue

await playerctld_shift(bus_address)
code = await playerctld_shift(bus_address)
assert code == 0
line = await proc.queue.get()
assert line == 'playerctld: artist1 - title1', proc.queue

await playerctld_shift(bus_address)
code = await playerctld_shift(bus_address)
assert code == 0
line = await proc.queue.get()
assert line == 'playerctld: artist2 - title2', proc.queue

Expand All @@ -194,3 +196,26 @@ async def test_daemon_shift_simple(bus_address):
proc.proc.terminate()
await proc.proc.wait()
await playerctld_proc.wait()

@pytest.mark.asyncio
async def test_daemon_shift_no_player(bus_address):
playerctld_proc = await start_playerctld(bus_address)

playerctl = PlayerctlCli(bus_address)
pctl_cmd = '--player playerctld metadata --format "{{playerInstance}}: {{artist}} - {{title}}" --follow'
proc = await playerctl.start(pctl_cmd)

code = await playerctld_shift(bus_address)
assert code == 1

[mpris1] = await setup_mpris('player1',
bus_address=bus_address)
code = await playerctld_shift(bus_address)
assert code == 0

mpris1.disconnect()
code = await playerctld_shift(bus_address)
assert code == 1

playerctld_proc.terminate()
await playerctld_proc.wait()

0 comments on commit afd253d

Please sign in to comment.