From 826c5686256756f507627de3c22031302b752d65 Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 5 Mar 2017 13:30:10 +0100 Subject: [PATCH] [tests] Add generic module tests These tests check that all widgets of all modules conform to some basic principles, at least. --- bumblebee/modules/dnf.py | 2 -- tests/test_modules.py | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/test_modules.py diff --git a/bumblebee/modules/dnf.py b/bumblebee/modules/dnf.py index 8dc000f..f36dfa9 100644 --- a/bumblebee/modules/dnf.py +++ b/bumblebee/modules/dnf.py @@ -53,9 +53,7 @@ class Module(bumblebee.engine.Module): def __init__(self, engine, config): widget = bumblebee.output.Widget(full_text=self.updates) super(Module, self).__init__(engine, config, widget) - self._next_check = 0 - widget def updates(self, widget): result = [] diff --git a/tests/test_modules.py b/tests/test_modules.py new file mode 100644 index 0000000..aa135e1 --- /dev/null +++ b/tests/test_modules.py @@ -0,0 +1,51 @@ +# pylint: disable=C0103,C0111 + +import mock +import unittest +import importlib + +import tests.mocks as mocks + +from bumblebee.engine import all_modules +from bumblebee.output import Widget +from bumblebee.config import Config + +class TestGenericModules(unittest.TestCase): + def setUp(self): + self.popen = mocks.MockPopen() + self.popen.mock.communicate.return_value = (str.encode("1"), "error") + self.popen.mock.returncode = 0 + + engine = mock.Mock() + engine.input = mock.Mock() + config = Config() + self.objects = {} + 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 tearDown(self): + self.popen.cleanup() + + def test_widgets(self): + for mod in self.objects: + widgets = self.objects[mod].widgets() + for widget in widgets: + widget.link_module(self.objects[mod]) + self.assertEquals(widget.module, mod) + self.assertTrue(isinstance(widget, Widget)) + self.assertTrue(hasattr(widget, "full_text")) + widget.set("variable", "value") + self.assertEquals(widget.get("variable", None), "value") + self.assertTrue(isinstance(widget.full_text(), str) or isinstance(widget.full_text(), unicode)) + + def test_update(self): + 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