From c4cf1da337858ae0303af984b130009322de9b56 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 26 Dec 2019 13:56:53 +0100 Subject: [PATCH] [tests] Fix failing tests * better checks for "brightness" modules * add mocking for output config --- tests/modules/test_brightness.py | 32 +++++++++++++++++++------------- tests/test_i3baroutput.py | 7 ++++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/modules/test_brightness.py b/tests/modules/test_brightness.py index 4bc373a..54cc253 100644 --- a/tests/modules/test_brightness.py +++ b/tests/modules/test_brightness.py @@ -15,6 +15,7 @@ except NameError: import tests.mocks as mocks +import bumblebee.util from bumblebee.config import Config from bumblebee.input import WHEEL_UP, WHEEL_DOWN from bumblebee.modules.brightness import Module @@ -22,6 +23,21 @@ from bumblebee.modules.brightness import Module class TestBrightnessModule(unittest.TestCase): def setUp(self): mocks.setup_test(self, Module) + self.tool = "" + self.up = "" + self.down = "" + if bumblebee.util.which("light"): + self.tool = "light" + self.up = "-A {}%" + self.down = "-U {}%" + elif bumblebee.util.which("brightnessctl"): + self.tool = "brightnessctl" + self.up = "s {}%+" + self.down = "s {}%-" + else: + self.tool = "xbacklight" + self.up = "+{}%" + self.down = "-{}%" def tearDown(self): mocks.teardown_test(self) @@ -32,27 +48,17 @@ class TestBrightnessModule(unittest.TestCase): def test_wheel_up(self): mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module) - self.popen.assert_call("xbacklight +2%") + self.popen.assert_call("{} {}".format(self.tool, self.up.format(2))) def test_wheel_down(self): mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=self.module) - self.popen.assert_call("xbacklight -2%") + self.popen.assert_call("{} {}".format(self.tool, self.down.format(2))) def test_custom_step(self): self.config.set("brightness.step", "10") module = Module(engine=self.engine, config={"config": self.config}) mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module) - self.popen.assert_call("xbacklight -10%") - -# @mock.patch('bumblebee.modules.brightness.open', create=True) -# def test_update(self, mock_open): -# mock_open.side_effect = [ -# mock.mock_open(read_data="20").return_value, -# mock.mock_open(read_data="100").return_value -# ] -# self.module.update_all() -# self.assertEquals(self.module.brightness(self.anyWidget), "020%") -# self.assertEquals(len(self.module.brightness(self.anyWidget)), len("100%")) + self.popen.assert_call("{} {}".format(self.tool, self.down.format(10))) @mock.patch('bumblebee.modules.brightness.open', create=True) def test_error(self,mock_open): diff --git a/tests/test_i3baroutput.py b/tests/test_i3baroutput.py index 8c566ef..a350ceb 100644 --- a/tests/test_i3baroutput.py +++ b/tests/test_i3baroutput.py @@ -26,7 +26,12 @@ class TestI3BarOutput(unittest.TestCase): self.theme.bg.return_value = "#ababab" self.theme.align.return_value = None self.theme.minwidth.return_value = "" - self.output = I3BarOutput(self.theme) + + self.config = mock.Mock() + self.config.markup.return_value = "" + self.config.unused_keys.return_value = [] + + self.output = I3BarOutput(self.theme, self.config) self._stdout = mock.patch("bumblebee.output.sys.stdout", new_callable=StringIO) self.stdout = self._stdout.start()