fixed tests for brightness module

This commit is contained in:
jmg5e 2017-06-26 06:07:19 -05:00
parent 11f86b75c8
commit fc912a8fbc

View file

@ -10,6 +10,7 @@ except ImportError:
import tests.mocks as mocks import tests.mocks as mocks
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
@ -20,9 +21,9 @@ class TestBrightnessModule(unittest.TestCase):
def tearDown(self): def tearDown(self):
mocks.teardown_test(self) mocks.teardown_test(self)
def test_format(self): # def test_format(self):
for widget in self.module.widgets(): # for widget in self.module.widgets():
self.assertEquals(len(widget.full_text()), len("100%")) # self.assertEquals(len(widget.full_text()), len("100%"))
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)
@ -38,10 +39,20 @@ class TestBrightnessModule(unittest.TestCase):
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("xbacklight -10%")
def test_update(self): @mock.patch('bumblebee.modules.brightness.open', create=True)
self.popen.mock.communicate.return_value = ("20.0", None) 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.module.update_all()
self.assertEquals(self.module.brightness(self.anyWidget), "020%") self.assertEquals(self.module.brightness(self.anyWidget), "020%")
self.assertEquals(len(self.module.brightness(self.anyWidget)), len("100%"))
@mock.patch('bumblebee.modules.brightness.open')
def test_error(self,mock_open):
mock_open.side_effect = FileNotFoundError
self.module.update_all()
self.assertEquals(self.module.brightness(self.anyWidget), "n/a")
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4