[modules/cpu] Add initial version of CPU utilization module
Re-enable the CPU utilization module as proof-of-concept for the new core engine. see #23
This commit is contained in:
parent
8855f1155b
commit
aacc56a4e2
9 changed files with 85 additions and 10 deletions
0
tests/modules/__init__.py
Normal file
0
tests/modules/__init__.py
Normal file
16
tests/modules/test_cpu.py
Normal file
16
tests/modules/test_cpu.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
import unittest
|
||||
|
||||
from bumblebee.modules.cpu import Module
|
||||
from tests.util import assertWidgetAttributes
|
||||
|
||||
class TestCPUModule(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.module = Module(None)
|
||||
|
||||
def test_widgets(self):
|
||||
widget = self.module.widgets()
|
||||
assertWidgetAttributes(self, widget)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
|
@ -1,13 +1,17 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
import unittest
|
||||
|
||||
from bumblebee.error import ModuleLoadError
|
||||
from bumblebee.engine import Engine
|
||||
from bumblebee.config import Config
|
||||
|
||||
from tests.util import MockOutput
|
||||
|
||||
class TestEngine(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.engine = Engine(Config())
|
||||
self.engine = Engine(config=Config(), output=MockOutput())
|
||||
self.singleWidgetModule = [{"module": "test"}]
|
||||
self.testModule = "test"
|
||||
self.invalidModule = "no-such-module"
|
||||
self.testModuleSpec = "bumblebee.modules.{}".format(self.testModule)
|
||||
|
@ -41,4 +45,11 @@ class TestEngine(unittest.TestCase):
|
|||
[self.testModuleSpec for module in modules]
|
||||
)
|
||||
|
||||
def test_run(self):
|
||||
self.engine.load_modules(self.singleWidgetModule)
|
||||
try:
|
||||
self.engine.run()
|
||||
except Exception as e:
|
||||
self.fail(e)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -32,14 +32,14 @@ class TestI3BarOutput(unittest.TestCase):
|
|||
def test_draw_single_widget(self, stdout):
|
||||
self.output.draw(self.someWidget)
|
||||
result = json.loads(stdout.getvalue())[0]
|
||||
self.assertEquals(result["full_text"], self.someWidget.text())
|
||||
self.assertEquals(result["full_text"], self.someWidget.full_text())
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_draw_multiple_widgets(self, stdout):
|
||||
self.output.draw([self.someWidget, self.someWidget])
|
||||
result = json.loads(stdout.getvalue())
|
||||
for res in result:
|
||||
self.assertEquals(res["full_text"], self.someWidget.text())
|
||||
self.assertEquals(res["full_text"], self.someWidget.full_text())
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_flush(self, stdout):
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
from bumblebee.output import Widget
|
||||
|
||||
def assertWidgetAttributes(test, widget):
|
||||
test.assertTrue(isinstance(widget, Widget))
|
||||
test.assertTrue(hasattr(widget, "full_text"))
|
||||
|
||||
class MockOutput(object):
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def draw(self, widgets, engine):
|
||||
engine.stop()
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
class MockWidget(object):
|
||||
def __init__(self, text):
|
||||
self._text = text
|
||||
|
||||
def text(self):
|
||||
def full_text(self):
|
||||
return self._text
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue