2020-06-19 10:13:52 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
import core.config
|
|
|
|
import modules.contrib.mpd
|
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 10:13:52 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def mpd_module():
|
|
|
|
return modules.contrib.mpd.Module(config=core.config.Config([]), theme=None)
|
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
def _test_state(mocker, mpd_module, widget_name, expected_output):
|
2020-06-19 11:00:56 +02:00
|
|
|
widget = mocker.Mock()
|
2020-06-19 12:12:30 +02:00
|
|
|
widget.name = widget_name
|
|
|
|
return mpd_module.state(widget) == expected_output
|
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
def test_states(mocker, mpd_module):
|
2020-06-20 15:11:53 +02:00
|
|
|
assert _test_state(mocker, mpd_module, "mpd.repeat", "repeat-off")
|
|
|
|
assert _test_state(mocker, mpd_module, "mpd.shuffle", "shuffle-off")
|
|
|
|
assert _test_state(mocker, mpd_module, "mpd.prev", "prev")
|
|
|
|
assert _test_state(mocker, mpd_module, "mpd.next", "next")
|
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
|
|
|
|
def test_no_host(mpd_module):
|
2020-06-20 15:11:53 +02:00
|
|
|
assert mpd_module._hostcmd == ""
|
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
|
|
|
|
def test_host():
|
2020-06-20 15:11:53 +02:00
|
|
|
module_with_host = modules.contrib.mpd.Module(
|
|
|
|
config=core.config.Config(["-p", "mpd.host=sample-host"]), theme=None
|
|
|
|
)
|
|
|
|
assert module_with_host._hostcmd == " -h sample-host"
|
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
|
2020-06-20 13:36:21 +02:00
|
|
|
def test_host2(mocker):
|
|
|
|
cli = mocker.patch("modules.contrib.mpd.util.cli")
|
2020-06-20 15:11:53 +02:00
|
|
|
module_with_host = modules.contrib.mpd.Module(
|
|
|
|
config=core.config.Config(["-p", "mpd.host=sample-host"]), theme=None
|
|
|
|
)
|
2020-06-20 13:36:21 +02:00
|
|
|
module_with_host.update()
|
|
|
|
args, kwargs = cli.execute.call_args
|
|
|
|
|
2020-06-20 13:38:00 +02:00
|
|
|
assert " -h sample-host" in args[0] and "mpc" in args[0]
|
2020-06-20 13:36:21 +02:00
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
def test_bad_layout():
|
2020-06-20 15:11:53 +02:00
|
|
|
pytest.raises(
|
|
|
|
KeyError,
|
|
|
|
modules.contrib.mpd.Module,
|
|
|
|
config=core.config.Config(["-p", 'mpd.layout="mpd.inexistent"']),
|
|
|
|
theme=None,
|
|
|
|
)
|
|
|
|
|
2020-06-19 12:12:30 +02:00
|
|
|
|
|
|
|
def test_hidden_on_creation(mpd_module):
|
|
|
|
assert mpd_module.hidden()
|
2020-06-19 12:35:15 +02:00
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 12:35:15 +02:00
|
|
|
def test_update_calls_load_song(mocker, mpd_module):
|
2020-06-20 15:11:53 +02:00
|
|
|
mocker.patch.object(mpd_module, "_load_song")
|
2020-06-19 12:35:15 +02:00
|
|
|
mpd_module.update()
|
2020-06-20 15:07:16 +02:00
|
|
|
mpd_module._load_song.assert_called_with()
|
2020-06-19 12:35:15 +02:00
|
|
|
|
2020-06-20 15:11:53 +02:00
|
|
|
|
2020-06-19 12:35:15 +02:00
|
|
|
def test_default_layout(mpd_module):
|
|
|
|
assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"
|