From b5395fe764c8b580475459e073a480f27525bb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Mon, 11 Oct 2021 19:07:28 -0300 Subject: [PATCH 1/3] chore: public toggle method --- bumblebee_status/modules/contrib/dunstctl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumblebee_status/modules/contrib/dunstctl.py b/bumblebee_status/modules/contrib/dunstctl.py index 3c803a4..f082f1b 100644 --- a/bumblebee_status/modules/contrib/dunstctl.py +++ b/bumblebee_status/modules/contrib/dunstctl.py @@ -24,12 +24,12 @@ import util.cli class Module(core.module.Module): def __init__(self, config, theme): super().__init__(config, theme, core.widget.Widget("")) - core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.__toggle_state) + core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle_state) self.__states = {"unknown": ["unknown", "critical"], "true": ["muted", "warning"], "false": ["unmuted"]} - def __toggle_state(self, event): + def toggle_state(self, event): util.cli.execute("dunstctl set-paused toggle", ignore_errors=True) def state(self, widget): From 40de07ba2ed659abaa417ab7d76dff54c423b6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Mon, 11 Oct 2021 19:08:46 -0300 Subject: [PATCH 2/3] chore: create dunst tests --- tests/modules/contrib/test_dunst.py | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/modules/contrib/test_dunst.py b/tests/modules/contrib/test_dunst.py index 2ca2d40..75e3151 100644 --- a/tests/modules/contrib/test_dunst.py +++ b/tests/modules/contrib/test_dunst.py @@ -1,5 +1,58 @@ import pytest +import core.config +import modules.contrib.dunst + + +def build_module(): + return modules.contrib.dunst.Module( + config=core.config.Config([]), + theme=None + ) + + def test_load_module(): __import__("modules.contrib.dunst") +def test_input_registration(mocker): + input_register = mocker.patch('core.input.register') + + module = build_module() + + input_register.assert_called_with( + module, + button=core.input.LEFT_MOUSE, + cmd=module.toggle_status + ) + +def test_dunst_toggle(mocker): + start_command = mocker.patch('util.cli.execute') + + module = build_module() + start_command.assert_called_with('killall -s SIGUSR2 dunst', ignore_errors=True) + + toggle_command = mocker.patch('util.cli.execute') + module.toggle_status(None) + toggle_command.assert_called_with('killall -s SIGUSR1 dunst') + + widget = module.widget() + actual = module.state(widget) + assert actual == ['muted', 'warning'] + + module.toggle_status(None) + toggle_command.assert_called_with('killall -s SIGUSR2 dunst') + + widget = module.widget() + actual = module.state(widget) + assert actual == ['unmuted'] + +def test_dunst_toggle_exception(mocker): + module = build_module() + + toggle_command = mocker.patch('util.cli.execute', side_effect=Exception) + module.toggle_status(None) + toggle_command.assert_called_with('killall -s SIGUSR1 dunst') + + widget = module.widget() + actual = module.state(widget) + assert actual == ['unmuted'] From 15809514740dcf0848b15e0328ff12f7d02420d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Mon, 11 Oct 2021 19:09:15 -0300 Subject: [PATCH 3/3] chore: create missing dunstctl tests --- tests/modules/contrib/test_dunstctl.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/modules/contrib/test_dunstctl.py b/tests/modules/contrib/test_dunstctl.py index db77fe3..2391f7e 100644 --- a/tests/modules/contrib/test_dunstctl.py +++ b/tests/modules/contrib/test_dunstctl.py @@ -1,6 +1,5 @@ import pytest -import util.cli import core.config import modules.contrib.dunstctl @@ -13,6 +12,25 @@ def build_module(): def test_load_module(): __import__("modules.contrib.dunstctl") +def test_input_registration(mocker): + input_register = mocker.patch('core.input.register') + + module = build_module() + + input_register.assert_called_with( + module, + button=core.input.LEFT_MOUSE, + cmd=module.toggle_state + ) + +def test_dunst_toggle_state(mocker): + command = mocker.patch('util.cli.execute') + + module = build_module() + + module.toggle_state(None) + command.assert_called_with('dunstctl set-paused toggle', ignore_errors=True) + def test_dunst_running(mocker): command = mocker.patch('util.cli.execute', return_value=(0, "false"))