[modules/cpu] Add configurable warning and critical thresholds

The cpu module now has cpu.warning and cpu.critical thresholds. If the
CPU utilization is higher than any of those values, the widget's state
changes to warning or critical, respectively.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-10 08:09:13 +01:00
parent 87e76b9e40
commit 225d471c6a
5 changed files with 60 additions and 17 deletions

View file

@ -7,14 +7,17 @@ import mock
import bumblebee.input
from bumblebee.input import I3BarInput
from bumblebee.modules.cpu import Module
from tests.util import MockEngine, assertPopen
from tests.util import MockEngine, MockConfig, assertPopen
class TestCPUModule(unittest.TestCase):
def setUp(self):
self.engine = MockEngine()
self.engine.input = I3BarInput()
self.engine.input.need_event = True
self.module = Module(engine=self.engine, config={})
self.config = MockConfig()
self.module = Module(engine=self.engine, config={ "config": self.config })
for widget in self.module.widgets():
widget.link_module(self.module)
@mock.patch("sys.stdout")
def test_format(self, mock_output):
@ -34,4 +37,20 @@ class TestCPUModule(unittest.TestCase):
mock_input.readline.assert_any_call()
assertPopen(mock_output, "gnome-system-monitor")
@mock.patch("psutil.cpu_percent")
def test_warning(self, mock_psutil):
self.config.set("cpu.critical", "20")
self.config.set("cpu.warning", "18")
mock_psutil.return_value = 19.0
self.module.update(self.module.widgets())
self.assertEquals(self.module.widgets()[0].state(), "warning")
@mock.patch("psutil.cpu_percent")
def test_critical(self, mock_psutil):
self.config.set("cpu.critical", "20")
self.config.set("cpu.warning", "19")
mock_psutil.return_value = 21.0
self.module.update(self.module.widgets())
self.assertEquals(self.module.widgets()[0].state(), "critical")
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4