Merge branch 'jmg5e-master'
This commit is contained in:
commit
62f60a172f
3 changed files with 35 additions and 11 deletions
|
@ -91,7 +91,6 @@ Modules and commandline utilities are only required for modules, the core itself
|
|||
|
||||
# Required commandline utilities
|
||||
|
||||
* xbacklight (for the module 'brightness')
|
||||
* xset (for the module 'caffeine')
|
||||
* notify-send (for the module 'caffeine')
|
||||
* cmus-remote (for the module 'cmus')
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
"""Displays the brightness of a display
|
||||
|
||||
Requires the following executable:
|
||||
* xbacklight
|
||||
|
||||
Parameters:
|
||||
* brightness.step: The amount of increase/decrease on scroll in % (defaults to 2)
|
||||
* brightness.device_path: The device path (defaults to /sys/class/backlight/intel_backlight)
|
||||
|
||||
"""
|
||||
|
||||
|
@ -21,6 +19,7 @@ class Module(bumblebee.engine.Module):
|
|||
)
|
||||
self._brightness = 0
|
||||
|
||||
self._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight")
|
||||
step = self.parameter("step", 2)
|
||||
|
||||
engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP,
|
||||
|
@ -29,9 +28,19 @@ class Module(bumblebee.engine.Module):
|
|||
cmd="xbacklight -{}%".format(step))
|
||||
|
||||
def brightness(self, widget):
|
||||
if isinstance(self._brightness, float):
|
||||
return "{:03.0f}%".format(self._brightness)
|
||||
else:
|
||||
return "n/a"
|
||||
|
||||
def update(self, widgets):
|
||||
self._brightness = float(bumblebee.util.execute("xbacklight -get"))
|
||||
try:
|
||||
with open("{}/brightness".format(self._device_path)) as f:
|
||||
backlight = int(f.readline())
|
||||
with open("{}/max_brightness".format(self._device_path)) as f:
|
||||
max_brightness = int(f.readline())
|
||||
self._brightness=float(backlight*100/max_brightness)
|
||||
except:
|
||||
return "Error"
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -8,8 +8,14 @@ try:
|
|||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
try:
|
||||
FileNotFoundError
|
||||
except NameError:
|
||||
FileNotFoundError = IOError
|
||||
|
||||
import tests.mocks as mocks
|
||||
|
||||
from bumblebee.config import Config
|
||||
from bumblebee.input import WHEEL_UP, WHEEL_DOWN
|
||||
from bumblebee.modules.brightness import Module
|
||||
|
||||
|
@ -20,9 +26,9 @@ class TestBrightnessModule(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
mocks.teardown_test(self)
|
||||
|
||||
def test_format(self):
|
||||
for widget in self.module.widgets():
|
||||
self.assertEquals(len(widget.full_text()), len("100%"))
|
||||
# def test_format(self):
|
||||
# for widget in self.module.widgets():
|
||||
# self.assertEquals(len(widget.full_text()), len("100%"))
|
||||
|
||||
def test_wheel_up(self):
|
||||
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_UP, inp=self.input, module=self.module)
|
||||
|
@ -38,10 +44,20 @@ class TestBrightnessModule(unittest.TestCase):
|
|||
mocks.mouseEvent(stdin=self.stdin, button=WHEEL_DOWN, inp=self.input, module=module)
|
||||
self.popen.assert_call("xbacklight -10%")
|
||||
|
||||
def test_update(self):
|
||||
self.popen.mock.communicate.return_value = ("20.0", None)
|
||||
@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')
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue