From 180a87e0c3165da8e34298bc336c3184786cb825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Sun, 4 Oct 2020 15:57:48 -0300 Subject: [PATCH] Create dunstctl tests --- bumblebee_status/modules/contrib/dunstctl.py | 1 + tests/modules/contrib/test_dunstctl.py | 67 ++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/modules/contrib/test_dunstctl.py diff --git a/bumblebee_status/modules/contrib/dunstctl.py b/bumblebee_status/modules/contrib/dunstctl.py index 1b7649c..24b93f0 100644 --- a/bumblebee_status/modules/contrib/dunstctl.py +++ b/bumblebee_status/modules/contrib/dunstctl.py @@ -27,6 +27,7 @@ class Module(core.module.Module): def toggle_status(self, event): self._paused = self.__isPaused() + if self._paused: util.cli.execute("dunstctl set-paused false") else: diff --git a/tests/modules/contrib/test_dunstctl.py b/tests/modules/contrib/test_dunstctl.py new file mode 100644 index 0000000..e6a7ce3 --- /dev/null +++ b/tests/modules/contrib/test_dunstctl.py @@ -0,0 +1,67 @@ +import pytest + +import util.cli +import core.config +import modules.contrib.dunstctl + +def build_module(): + return modules.contrib.dunstctl.Module( + config=core.config.Config([]), + theme=None + ) + +def test_load_module(): + __import__("modules.contrib.dunstctl") + +def test_dunst_running(mocker): + command = mocker.patch('util.cli.execute', return_value='false') + + module = build_module() + module.update() + + command.assert_called_with('dunstctl is-paused') + + widget = module.widget() + assert module.state(widget) == ['unmuted'] + +def test_dunst_paused(mocker): + command = mocker.patch('util.cli.execute', return_value='true') + + module = build_module() + module.update() + + command.assert_called_with('dunstctl is-paused') + + widget = module.widget() + assert module.state(widget) == ['muted', 'warning'] + +def test_toggle_status_pause(mocker): + command = mocker.patch('util.cli.execute') + command.side_effect = ['true', 'true', None] + + module = build_module() + module.toggle_status(False) + + command.assert_any_call('dunstctl set-paused false') + +def test_toggle_status_unpause(mocker): + command = mocker.patch('util.cli.execute') + command.side_effect = ['false', 'false', None] + + module = build_module() + module.toggle_status(False) + + command.assert_called_with('dunstctl set-paused true') + +def test_input_register(mocker): + command = mocker.patch('util.cli.execute') + 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 + ) +