[tests] Fix failing tests
* better checks for "brightness" modules * add mocking for output config
This commit is contained in:
parent
48cb15b063
commit
c4cf1da337
2 changed files with 25 additions and 14 deletions
|
@ -15,6 +15,7 @@ except NameError:
|
||||||
|
|
||||||
import tests.mocks as mocks
|
import tests.mocks as mocks
|
||||||
|
|
||||||
|
import bumblebee.util
|
||||||
from bumblebee.config import Config
|
from bumblebee.config import Config
|
||||||
from bumblebee.input import WHEEL_UP, WHEEL_DOWN
|
from bumblebee.input import WHEEL_UP, WHEEL_DOWN
|
||||||
from bumblebee.modules.brightness import Module
|
from bumblebee.modules.brightness import Module
|
||||||
|
@ -22,6 +23,21 @@ from bumblebee.modules.brightness import Module
|
||||||
class TestBrightnessModule(unittest.TestCase):
|
class TestBrightnessModule(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
mocks.setup_test(self, Module)
|
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):
|
def tearDown(self):
|
||||||
mocks.teardown_test(self)
|
mocks.teardown_test(self)
|
||||||
|
@ -32,27 +48,17 @@ class TestBrightnessModule(unittest.TestCase):
|
||||||
|
|
||||||
def test_wheel_up(self):
|
def test_wheel_up(self):
|
||||||
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module)
|
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):
|
def test_wheel_down(self):
|
||||||
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=self.module)
|
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):
|
def test_custom_step(self):
|
||||||
self.config.set("brightness.step", "10")
|
self.config.set("brightness.step", "10")
|
||||||
module = Module(engine=self.engine, config={"config": self.config})
|
module = Module(engine=self.engine, config={"config": self.config})
|
||||||
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module)
|
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module)
|
||||||
self.popen.assert_call("xbacklight -10%")
|
self.popen.assert_call("{} {}".format(self.tool, self.down.format(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%"))
|
|
||||||
|
|
||||||
@mock.patch('bumblebee.modules.brightness.open', create=True)
|
@mock.patch('bumblebee.modules.brightness.open', create=True)
|
||||||
def test_error(self,mock_open):
|
def test_error(self,mock_open):
|
||||||
|
|
|
@ -26,7 +26,12 @@ class TestI3BarOutput(unittest.TestCase):
|
||||||
self.theme.bg.return_value = "#ababab"
|
self.theme.bg.return_value = "#ababab"
|
||||||
self.theme.align.return_value = None
|
self.theme.align.return_value = None
|
||||||
self.theme.minwidth.return_value = ""
|
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 = mock.patch("bumblebee.output.sys.stdout", new_callable=StringIO)
|
||||||
self.stdout = self._stdout.start()
|
self.stdout = self._stdout.start()
|
||||||
|
|
Loading…
Reference in a new issue