diff --git a/core/module.py b/core/module.py index 60b2aba..86cf320 100644 --- a/core/module.py +++ b/core/module.py @@ -15,11 +15,23 @@ class Module(object): def __init__(self, config=None, widgets=[]): self._config = config self._widgets = widgets if isinstance(widgets, list) else [ widgets ] + self._name = None + + def parameter(self, key, default=None): + value = default + + for prefix in [ self.name(), self.module_name() ]: + value = self._config.get('{}.{}'.format(prefix, key), value) + # TODO retrieve from config file + return value def update(self): pass def name(self): + return self._name if self._name else self.module_name() + + def module_name(self): return self.__module__.split('.')[-1] def widgets(self): diff --git a/core/widget.py b/core/widget.py index a348e4a..9c1bd69 100644 --- a/core/widget.py +++ b/core/widget.py @@ -9,7 +9,7 @@ class Widget(util.store.Store): self._full_text = value else: if callable(self._full_text): - return self._full_text(self) + return self._full_text() return self._full_text # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_module.py b/tests/core/test_module.py index ae33b74..1a229a7 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -1,29 +1,29 @@ import unittest +import shlex + import core.module import core.widget +import core.config class TestModule(core.module.Module): pass class module(unittest.TestCase): def setUp(self): - self._invalidModuleName = 'invalid-module-name' - self._validModuleName = 'test' + 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 - - def test_load_invalid_module(self): - module = core.module.load(module_name=self._invalidModuleName) + def test_loadinvalid_module(self): + module = core.module.load(module_name=self.invalidModuleName) self.assertEqual('core.module', module.__class__.__module__, 'module must be a module object') self.assertEqual('Error', module.__class__.__name__, 'an invalid module must be a core.module.Error') - def test_load_valid_module(self): - module = core.module.load(module_name=self._validModuleName) - self.assertEqual('modules.{}'.format(self._validModuleName), module.__class__.__module__, 'module must be a modules. object') + def test_loadvalid_module(self): + module = core.module.load(module_name=self.validModuleName) + self.assertEqual('modules.{}'.format(self.validModuleName), module.__class__.__module__, 'module must be a modules. object') self.assertEqual('Module', module.__class__.__name__, 'a valid module must have a Module class') def test_empty_widgets(self): @@ -39,7 +39,23 @@ class module(unittest.TestCase): self.assertEqual([ self.someWidget, self.anotherWidget ], module.widgets()) def test_module_Name(self): - module = TestModule([]) + module = TestModule() self.assertEqual('test_module', module.name(), 'module has wrong name') + self.assertEqual('test_module', module.module_name(), 'module has wrong name') + + def testvalid_parameter(self): + cfg = core.config.Config(shlex.split('-p test_module.foo=5')) + module = TestModule(config=cfg) + self.assertEqual(5, int(module.parameter('foo'))) + + def test_default_parameter(self): + cfg = core.config.Config([]) + module = TestModule(config=cfg) + self.assertEqual('default', module.parameter('foo', 'default')) + + def test_default_is_none(self): + cfg = core.config.Config([]) + module = TestModule(config=cfg) + self.assertEqual(None, module.parameter('foo')) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_widget.py b/tests/core/test_widget.py index 011e09b..5845f45 100644 --- a/tests/core/test_widget.py +++ b/tests/core/test_widget.py @@ -28,11 +28,11 @@ class widget(unittest.TestCase): def test_callable_fulltext(self): newWidget = core.widget.Widget(full_text=self.someCallback) self.assertEqual(newWidget.full_text(), self.callbackReturnValue) - self.someCallback.assert_called_once_with(unittest.mock.ANY) + self.someCallback.assert_called_once_with() def test_set_callable_fulltext(self): self.someWidget.full_text(self.someCallback) self.assertEqual(self.someWidget.full_text(), self.callbackReturnValue) - self.someCallback.assert_called_once_with(unittest.mock.ANY) + self.someCallback.assert_called_once_with() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4