From 52f5315ec5cc877a56585ea969fa06398e616775 Mon Sep 17 00:00:00 2001 From: Ambika Nair Date: Fri, 19 Jun 2020 06:12:30 -0400 Subject: [PATCH 1/2] Added more tests for mpd module --- pytests/modules/contrib/test_mpd.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pytests/modules/contrib/test_mpd.py b/pytests/modules/contrib/test_mpd.py index 77bb253..eaceb80 100644 --- a/pytests/modules/contrib/test_mpd.py +++ b/pytests/modules/contrib/test_mpd.py @@ -7,10 +7,26 @@ import modules.contrib.mpd def mpd_module(): return modules.contrib.mpd.Module(config=core.config.Config([]), theme=None) -def test_shuffle_off_by_default(mpd_module): - assert not mpd_module._shuffle - -def test_shuffle_state(mocker, mpd_module): +def _test_state(mocker, mpd_module, widget_name, expected_output): widget = mocker.Mock() - widget.name = 'mpd.shuffle' - assert mpd_module.state(widget) == 'shuffle-off' + widget.name = widget_name + return mpd_module.state(widget) == expected_output + +def test_states(mocker, mpd_module): + 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') + +def test_no_host(mpd_module): + assert mpd_module._hostcmd == '' + +def test_host(): + 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' + +def test_bad_layout(): + pytest.raises(KeyError, modules.contrib.mpd.Module, config=core.config.Config(['-p', 'mpd.layout="mpd.inexistent"']), theme=None) + +def test_hidden_on_creation(mpd_module): + assert mpd_module.hidden() From 6271a0b91dc43d71770db70643315e6225c138db Mon Sep 17 00:00:00 2001 From: Ambika Nair Date: Fri, 19 Jun 2020 06:35:15 -0400 Subject: [PATCH 2/2] Added mpd module tests for update and layout --- pytests/modules/contrib/test_mpd.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pytests/modules/contrib/test_mpd.py b/pytests/modules/contrib/test_mpd.py index eaceb80..fe5451a 100644 --- a/pytests/modules/contrib/test_mpd.py +++ b/pytests/modules/contrib/test_mpd.py @@ -30,3 +30,11 @@ def test_bad_layout(): def test_hidden_on_creation(mpd_module): assert mpd_module.hidden() + +def test_update_calls_load_song(mocker, mpd_module): + mocker.patch.object(mpd_module, '_load_song') + mpd_module.update() + mpd_module._load_song.assert_called_once() + +def test_default_layout(mpd_module): + assert mpd_module._layout == "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat"