[core/module] Add very basic widget capability
This commit is contained in:
parent
da792f9b7b
commit
7a9cb8b533
2 changed files with 21 additions and 0 deletions
|
@ -12,9 +12,15 @@ def load(module_name):
|
|||
return getattr(mod, 'Module')()
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, widgets):
|
||||
self._widgets = widgets if isinstance(widgets, list) else [ widgets ]
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def widgets(self):
|
||||
return self._widgets
|
||||
|
||||
class Error(Module):
|
||||
def __init__(self, loaded_module_name):
|
||||
self._loaded_module_name = loaded_module_name
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import unittest
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
|
||||
class module(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._invalidModuleName = 'invalid-module-name'
|
||||
self._validModuleName = 'test'
|
||||
self.someWidget = core.widget.Widget('randomeWidgetContent')
|
||||
self.anotherWidget = core.widget.Widget('more Widget content')
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
@ -20,4 +23,16 @@ class module(unittest.TestCase):
|
|||
self.assertEqual('modules.{}'.format(self._validModuleName), module.__class__.__module__, 'module must be a modules.<name> object')
|
||||
self.assertEqual('Module', module.__class__.__name__, 'a valid module must have a Module class')
|
||||
|
||||
def test_empty_widgets(self):
|
||||
module = core.module.Module(widgets=[])
|
||||
self.assertEqual([], module.widgets())
|
||||
|
||||
def test_single_widget(self):
|
||||
module = core.module.Module(widgets=self.someWidget)
|
||||
self.assertEqual([self.someWidget], module.widgets())
|
||||
|
||||
def test_widget_list(self):
|
||||
module = core.module.Module(widgets=[ self.someWidget, self.anotherWidget ])
|
||||
self.assertEqual([ self.someWidget, self.anotherWidget ], module.widgets())
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Reference in a new issue