2016-12-09 07:27:01 +01:00
|
|
|
# pylint: disable=C0103,C0111
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import importlib
|
2016-12-10 19:45:13 +01:00
|
|
|
import mock
|
2016-12-09 07:27:01 +01:00
|
|
|
|
2016-12-09 08:43:14 +01:00
|
|
|
from bumblebee.engine import all_modules
|
2016-12-09 08:23:53 +01:00
|
|
|
from bumblebee.config import Config
|
2016-12-09 07:27:01 +01:00
|
|
|
from tests.util import assertWidgetAttributes, MockEngine
|
|
|
|
|
2016-12-10 19:45:13 +01:00
|
|
|
class MockCommunicate(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.returncode = 0
|
|
|
|
|
|
|
|
def communicate(self):
|
|
|
|
return (str.encode("1"), "error")
|
|
|
|
|
2016-12-09 07:27:01 +01:00
|
|
|
class TestGenericModules(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
engine = MockEngine()
|
2016-12-09 08:23:53 +01:00
|
|
|
config = Config()
|
2016-12-09 07:27:01 +01:00
|
|
|
self.objects = {}
|
2016-12-09 08:43:14 +01:00
|
|
|
for mod in all_modules():
|
2016-12-09 07:27:01 +01:00
|
|
|
cls = importlib.import_module("bumblebee.modules.{}".format(mod["name"]))
|
2016-12-09 08:43:14 +01:00
|
|
|
self.objects[mod["name"]] = getattr(cls, "Module")(engine, {"config": config})
|
2016-12-10 11:25:02 +01:00
|
|
|
for widget in self.objects[mod["name"]].widgets():
|
|
|
|
self.assertEquals(widget.get("variable", None), None)
|
2016-12-09 07:27:01 +01:00
|
|
|
|
2016-12-11 12:26:28 +01:00
|
|
|
@mock.patch("subprocess.Popen")
|
|
|
|
def test_widgets(self, mock_output):
|
|
|
|
mock_output.return_value = MockCommunicate()
|
2016-12-09 07:27:01 +01:00
|
|
|
for mod in self.objects:
|
|
|
|
widgets = self.objects[mod].widgets()
|
|
|
|
for widget in widgets:
|
2016-12-09 11:49:59 +01:00
|
|
|
widget.link_module(self.objects[mod])
|
|
|
|
self.assertEquals(widget.module, mod)
|
2016-12-09 07:27:01 +01:00
|
|
|
assertWidgetAttributes(self, widget)
|
2016-12-10 11:25:02 +01:00
|
|
|
widget.set("variable", "value")
|
|
|
|
self.assertEquals(widget.get("variable", None), "value")
|
2016-12-11 11:37:24 +01:00
|
|
|
self.assertTrue(isinstance(widget.full_text(), str))
|
2016-12-09 07:27:01 +01:00
|
|
|
|
2016-12-10 19:35:38 +01:00
|
|
|
@mock.patch("subprocess.Popen")
|
|
|
|
def test_update(self, mock_output):
|
2016-12-10 19:45:13 +01:00
|
|
|
mock_output.return_value = MockCommunicate()
|
2016-12-09 07:27:01 +01:00
|
|
|
for mod in self.objects:
|
|
|
|
widgets = self.objects[mod].widgets()
|
|
|
|
self.objects[mod].update(widgets)
|
|
|
|
self.test_widgets()
|
|
|
|
self.assertEquals(widgets, self.objects[mod].widgets())
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|