2020-01-19 16:06:21 +01:00
|
|
|
import unittest
|
|
|
|
|
2020-02-04 21:09:11 +01:00
|
|
|
import shlex
|
|
|
|
|
2020-01-19 16:06:21 +01:00
|
|
|
import core.module
|
2020-01-26 14:06:09 +01:00
|
|
|
import core.widget
|
2020-02-04 21:09:11 +01:00
|
|
|
import core.config
|
2020-01-19 16:06:21 +01:00
|
|
|
|
2020-02-03 21:30:06 +01:00
|
|
|
class TestModule(core.module.Module):
|
|
|
|
pass
|
|
|
|
|
2020-01-19 16:06:21 +01:00
|
|
|
class module(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2020-02-04 21:09:11 +01:00
|
|
|
self.invalidModuleName = 'invalid-module-name'
|
|
|
|
self.validModuleName = 'test'
|
2020-01-26 14:06:09 +01:00
|
|
|
self.someWidget = core.widget.Widget('randomeWidgetContent')
|
|
|
|
self.anotherWidget = core.widget.Widget('more Widget content')
|
2020-01-19 16:06:21 +01:00
|
|
|
|
2020-02-04 21:09:11 +01:00
|
|
|
def test_loadinvalid_module(self):
|
2020-02-23 14:55:13 +01:00
|
|
|
config = unittest.mock.MagicMock()
|
|
|
|
module = core.module.load(module_name=self.invalidModuleName, config=config)
|
2020-01-19 16:06:21 +01:00
|
|
|
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')
|
|
|
|
|
2020-02-04 21:09:11 +01:00
|
|
|
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.<name> object')
|
2020-01-19 16:06:21 +01:00
|
|
|
self.assertEqual('Module', module.__class__.__name__, 'a valid module must have a Module class')
|
|
|
|
|
2020-01-26 14:06:09 +01:00
|
|
|
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())
|
|
|
|
|
2020-02-03 21:30:06 +01:00
|
|
|
def test_module_Name(self):
|
2020-02-04 21:09:11 +01:00
|
|
|
module = TestModule()
|
2020-02-03 21:30:06 +01:00
|
|
|
self.assertEqual('test_module', module.name(), 'module has wrong name')
|
2020-02-04 21:09:11 +01:00
|
|
|
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'))
|
2020-02-03 21:30:06 +01:00
|
|
|
|
2020-01-19 16:06:21 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|