From 7a9cb8b53354e16b65509f3cb7ff94eaab1721ff Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 26 Jan 2020 14:06:09 +0100 Subject: [PATCH] [core/module] Add very basic widget capability --- core/module.py | 6 ++++++ tests/core/test_module.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/module.py b/core/module.py index 829ca46..31c2c2a 100644 --- a/core/module.py +++ b/core/module.py @@ -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 diff --git a/tests/core/test_module.py b/tests/core/test_module.py index 85a3e17..b28eca8 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -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. 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