File: test_commands.py

package info (click to toggle)
playerctl 2.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704 kB
  • sloc: ansic: 5,157; python: 1,107; xml: 198; sh: 133; makefile: 62
file content (44 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from .mpris import setup_mpris
from .playerctl import PlayerctlCli

import asyncio
import pytest

# TODO: test sending a command to all players


@pytest.mark.asyncio
async def test_commands(bus_address):
    [mpris] = await setup_mpris('commands', bus_address=bus_address)

    mpris.shuffle = False
    mpris.volume = 1.0
    mpris.loop_status = 'Track'

    commands = ('play', 'pause', 'play-pause', 'stop', 'next', 'previous')
    setters = ('volume 0.8', 'loop playlist', 'shuffle on')

    def get_called(cmd):
        return getattr(mpris, f'{cmd.replace("-", "_")}_called')

    playerctl = PlayerctlCli(bus_address)

    results = await asyncio.gather(*(playerctl.run(f'-p commands {cmd}')
                                     for cmd in commands + setters))

    for result in results:
        assert result.returncode == 0, result.stderr

    for i, cmd in enumerate(commands):
        result = results[i]
        assert get_called(cmd), f'{cmd} was not called: {result.stderr}'

    assert mpris.shuffle
    assert mpris.volume == 0.8
    assert mpris.loop_status == 'Playlist'

    await playerctl.run('-p commands shuffle toggle')

    assert not mpris.shuffle

    await mpris.disconnect()