[tests] Generic module tests
Add a helper function that lists all existing modules and modify the CPU module test so that it now generically iterates all available modules and tests their widgets. see #23
This commit is contained in:
parent
f40418475f
commit
a7e756e015
4 changed files with 47 additions and 23 deletions
|
@ -1,8 +1,21 @@
|
|||
"""Core application engine"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import pkgutil
|
||||
import importlib
|
||||
import bumblebee.error
|
||||
import bumblebee.modules
|
||||
|
||||
def modules():
|
||||
"""Return a list of available modules"""
|
||||
result = []
|
||||
path = os.path.dirname(bumblebee.modules.__file__)
|
||||
for mod in [name for _, name, _ in pkgutil.iter_modules([path])]:
|
||||
result.append({
|
||||
"name": mod
|
||||
})
|
||||
return result
|
||||
|
||||
class Module(object):
|
||||
"""Module instance base class
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# 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):
|
||||
widgets = self.module.widgets()
|
||||
for widget in widgets:
|
||||
assertWidgetAttributes(self, widget)
|
||||
|
||||
def test_update(self):
|
||||
widgets = self.module.widgets()
|
||||
self.module.update(widgets)
|
||||
self.test_widgets()
|
||||
self.assertEquals(widgets, self.module.widgets())
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
31
tests/modules/test_modules.py
Normal file
31
tests/modules/test_modules.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
import unittest
|
||||
import importlib
|
||||
|
||||
from bumblebee.modules.cpu import Module
|
||||
from bumblebee.engine import modules
|
||||
from tests.util import assertWidgetAttributes, MockEngine
|
||||
|
||||
class TestGenericModules(unittest.TestCase):
|
||||
def setUp(self):
|
||||
engine = MockEngine()
|
||||
self.objects = {}
|
||||
for mod in modules():
|
||||
cls = importlib.import_module("bumblebee.modules.{}".format(mod["name"]))
|
||||
self.objects[mod["name"]] = getattr(cls, "Module")(engine)
|
||||
|
||||
def test_widgets(self):
|
||||
for mod in self.objects:
|
||||
widgets = self.objects[mod].widgets()
|
||||
for widget in widgets:
|
||||
assertWidgetAttributes(self, widget)
|
||||
|
||||
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
|
|
@ -6,6 +6,9 @@ def assertWidgetAttributes(test, widget):
|
|||
test.assertTrue(isinstance(widget, Widget))
|
||||
test.assertTrue(hasattr(widget, "full_text"))
|
||||
|
||||
class MockEngine(object):
|
||||
pass
|
||||
|
||||
class MockOutput(object):
|
||||
def start(self):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue