2016-12-08 08:44:54 +01:00
|
|
|
# pylint: disable=C0103,C0111,W0703
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from bumblebee.engine import Module
|
2016-12-09 07:57:21 +01:00
|
|
|
from bumblebee.config import Config
|
2016-12-08 08:44:54 +01:00
|
|
|
from tests.util import MockWidget
|
|
|
|
|
|
|
|
class TestModule(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.widget = MockWidget("foo")
|
2016-12-09 07:57:21 +01:00
|
|
|
self.config = Config()
|
2016-12-08 08:44:54 +01:00
|
|
|
self.moduleWithoutWidgets = Module(engine=None, widgets=None)
|
|
|
|
self.moduleWithOneWidget = Module(engine=None, widgets=self.widget)
|
|
|
|
self.moduleWithMultipleWidgets = Module(engine=None,
|
|
|
|
widgets=[self.widget, self.widget, self.widget]
|
|
|
|
)
|
|
|
|
|
2016-12-09 07:57:21 +01:00
|
|
|
self.anyModule = Module(engine=None, widgets = self.widget)
|
|
|
|
self.anotherModule = Module(engine=None, widgets = self.widget)
|
|
|
|
self.anyConfigName = "cfg"
|
|
|
|
self.anotherConfigName = "cfg2"
|
|
|
|
self.anyKey = "some-parameter"
|
|
|
|
self.anyValue = "value"
|
|
|
|
self.anotherValue = "another-value"
|
|
|
|
self.emptyKey = "i-do-not-exist"
|
|
|
|
self.config.set("{}.{}".format(self.anyConfigName, self.anyKey), self.anyValue)
|
|
|
|
self.config.set("{}.{}".format(self.anotherConfigName, self.anyKey), self.anotherValue)
|
|
|
|
self.anyModule.set_config(self.config, self.anyConfigName)
|
|
|
|
self.anotherModule.set_config(self.config, self.anotherConfigName)
|
|
|
|
|
2016-12-08 08:44:54 +01:00
|
|
|
def test_empty_widgets(self):
|
|
|
|
self.assertEquals(self.moduleWithoutWidgets.widgets(), [])
|
|
|
|
|
|
|
|
def test_single_widget(self):
|
|
|
|
self.assertEquals(self.moduleWithOneWidget.widgets(), [self.widget])
|
|
|
|
|
|
|
|
def test_multiple_widgets(self):
|
|
|
|
for widget in self.moduleWithMultipleWidgets.widgets():
|
|
|
|
self.assertEquals(widget, self.widget)
|
2016-12-09 07:57:21 +01:00
|
|
|
|
|
|
|
def test_parameters(self):
|
|
|
|
self.assertEquals(self.anyModule.parameter(self.anyKey), self.anyValue)
|
|
|
|
self.assertEquals(self.anotherModule.parameter(self.anyKey), self.anotherValue)
|
|
|
|
|
|
|
|
def test_default_parameters(self):
|
|
|
|
self.assertEquals(self.anyModule.parameter(self.emptyKey), None)
|
|
|
|
self.assertEquals(self.anyModule.parameter(self.emptyKey, self.anyValue), self.anyValue)
|