2017-03-05 12:30:37 +01:00
|
|
|
# pylint: disable=C0103,C0111
|
|
|
|
|
|
|
|
import mock
|
2017-03-05 13:49:52 +01:00
|
|
|
import unittest
|
2017-03-05 12:30:37 +01:00
|
|
|
|
|
|
|
import tests.mocks as mocks
|
|
|
|
|
2017-03-05 13:01:28 +01:00
|
|
|
from bumblebee.input import LEFT_MOUSE
|
2017-03-05 12:30:37 +01:00
|
|
|
from bumblebee.modules.cpu import Module
|
|
|
|
|
|
|
|
class TestCPUModule(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2017-03-05 13:01:28 +01:00
|
|
|
mocks.setup_test(self, Module)
|
2017-03-05 12:30:37 +01:00
|
|
|
self._psutil = mock.patch("bumblebee.modules.cpu.psutil")
|
|
|
|
self.psutil = self._psutil.start()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self._psutil.stop()
|
2017-03-05 13:01:28 +01:00
|
|
|
mocks.teardown_test(self)
|
2017-03-05 12:30:37 +01:00
|
|
|
|
|
|
|
def test_format(self):
|
|
|
|
self.psutil.cpu_percent.return_value = 21.0
|
|
|
|
self.module.update_all()
|
|
|
|
for widget in self.module.widgets():
|
|
|
|
self.assertEquals(len(widget.full_text()), len("100.00%"))
|
|
|
|
|
|
|
|
def test_leftclick(self):
|
|
|
|
mocks.mouseEvent(stdin=self.stdin, button=LEFT_MOUSE, inp=self.input, module=self.module)
|
|
|
|
self.popen.assert_call("gnome-system-monitor")
|
|
|
|
|
|
|
|
def test_warning(self):
|
|
|
|
self.config.set("cpu.critical", "20")
|
|
|
|
self.config.set("cpu.warning", "18")
|
|
|
|
self.psutil.cpu_percent.return_value = 19.0
|
|
|
|
self.module.update_all()
|
|
|
|
self.assertTrue("warning" in self.module.state(self.anyWidget))
|
|
|
|
|
|
|
|
def test_critical(self):
|
|
|
|
self.config.set("cpu.critical", "20")
|
|
|
|
self.config.set("cpu.warning", "19")
|
|
|
|
self.psutil.cpu_percent.return_value = 21.0
|
|
|
|
self.module.update_all()
|
|
|
|
self.assertTrue("critical" in self.module.state(self.anyWidget))
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|