2017-03-05 11:24:30 +01:00
|
|
|
# pylint: disable=C0103,C0111
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
try:
|
|
|
|
from StringIO import StringIO
|
|
|
|
except ImportError:
|
|
|
|
from io import StringIO
|
|
|
|
|
2017-06-26 19:10:51 +02:00
|
|
|
try:
|
|
|
|
FileNotFoundError
|
|
|
|
except NameError:
|
|
|
|
FileNotFoundError = IOError
|
|
|
|
|
2017-03-05 11:24:30 +01:00
|
|
|
import tests.mocks as mocks
|
|
|
|
|
2019-12-26 13:56:53 +01:00
|
|
|
import bumblebee.util
|
2017-06-26 13:07:19 +02:00
|
|
|
from bumblebee.config import Config
|
2017-03-05 13:01:28 +01:00
|
|
|
from bumblebee.input import WHEEL_UP, WHEEL_DOWN
|
2017-03-05 11:24:30 +01:00
|
|
|
from bumblebee.modules.brightness import Module
|
|
|
|
|
|
|
|
class TestBrightnessModule(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2017-03-05 13:01:28 +01:00
|
|
|
mocks.setup_test(self, Module)
|
2019-12-26 13:56:53 +01:00
|
|
|
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 = "-{}%"
|
2017-03-05 11:24:30 +01:00
|
|
|
|
|
|
|
def tearDown(self):
|
2017-03-05 13:01:28 +01:00
|
|
|
mocks.teardown_test(self)
|
2017-03-05 11:24:30 +01:00
|
|
|
|
2017-06-26 13:07:19 +02:00
|
|
|
# def test_format(self):
|
|
|
|
# for widget in self.module.widgets():
|
|
|
|
# self.assertEquals(len(widget.full_text()), len("100%"))
|
2017-03-05 11:24:30 +01:00
|
|
|
|
|
|
|
def test_wheel_up(self):
|
|
|
|
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module)
|
2019-12-26 13:56:53 +01:00
|
|
|
self.popen.assert_call("{} {}".format(self.tool, self.up.format(2)))
|
2017-03-05 11:24:30 +01:00
|
|
|
|
|
|
|
def test_wheel_down(self):
|
|
|
|
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=self.module)
|
2019-12-26 13:56:53 +01:00
|
|
|
self.popen.assert_call("{} {}".format(self.tool, self.down.format(2)))
|
2017-03-05 11:24:30 +01:00
|
|
|
|
|
|
|
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)
|
2019-12-26 13:56:53 +01:00
|
|
|
self.popen.assert_call("{} {}".format(self.tool, self.down.format(10)))
|
2017-03-05 11:24:30 +01:00
|
|
|
|
2017-06-26 20:33:06 +02:00
|
|
|
@mock.patch('bumblebee.modules.brightness.open', create=True)
|
2017-06-26 13:07:19 +02:00
|
|
|
def test_error(self,mock_open):
|
|
|
|
mock_open.side_effect = FileNotFoundError
|
|
|
|
self.module.update_all()
|
|
|
|
self.assertEquals(self.module.brightness(self.anyWidget), "n/a")
|
2017-03-05 11:24:30 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|