[modules/nic] Re-enable NIC module

Re-add the NIC module with all its functionality (hopefully...).

This introduces a new concept: Instead of having separate queries for
critical and warning (which really are just another set of states), a
module can now return a list of states for each widget. All the state
information is then merged together into a single theme. So, for
instance, the NIC module can return a state saying "critical -
wlan-down", which applies the theme information for both "critical" and
"wlan-down".

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-10 11:25:02 +01:00
parent c820223d0c
commit a045962d00
8 changed files with 104 additions and 19 deletions

View file

@ -43,7 +43,7 @@ class TestCPUModule(unittest.TestCase):
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")
self.assertEquals(self.module.widgets()[0].state(), ["warning"])
@mock.patch("psutil.cpu_percent")
def test_critical(self, mock_psutil):
@ -51,6 +51,6 @@ class TestCPUModule(unittest.TestCase):
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")
self.assertEquals(self.module.widgets()[0].state(), ["critical"])
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -15,6 +15,8 @@ class TestGenericModules(unittest.TestCase):
for mod in all_modules():
cls = importlib.import_module("bumblebee.modules.{}".format(mod["name"]))
self.objects[mod["name"]] = getattr(cls, "Module")(engine, {"config": config})
for widget in self.objects[mod["name"]].widgets():
self.assertEquals(widget.get("variable", None), None)
def test_widgets(self):
for mod in self.objects:
@ -23,6 +25,8 @@ class TestGenericModules(unittest.TestCase):
widget.link_module(self.objects[mod])
self.assertEquals(widget.module, mod)
assertWidgetAttributes(self, widget)
widget.set("variable", "value")
self.assertEquals(widget.get("variable", None), "value")
def test_update(self):
for mod in self.objects:

View file

@ -102,11 +102,11 @@ class TestTheme(unittest.TestCase):
self.assertEquals(theme.fg(self.anyWidget), data["defaults"]["fg"])
self.assertEquals(theme.bg(self.anyWidget), data["defaults"]["bg"])
self.anyWidget.attr_state = "critical"
self.anyWidget.attr_state = ["critical"]
self.assertEquals(theme.fg(self.anyWidget), data["defaults"]["critical"]["fg"])
self.assertEquals(theme.bg(self.anyWidget), data["defaults"]["critical"]["bg"])
self.themedWidget.attr_state = "critical"
self.themedWidget.attr_state = ["critical"]
self.assertEquals(theme.fg(self.themedWidget), data[self.widgetTheme]["critical"]["fg"])
# if elements are missing in the state theme, they are taken from the
# widget theme instead (i.e. no fallback to a more general state theme)

View file

@ -70,7 +70,7 @@ class MockWidget(Widget):
super(MockWidget, self).__init__(text)
self._text = text
self.module = None
self.attr_state = "state-default"
self.attr_state = ["state-default"]
self.id = "none"
def state(self):