[core] Pass configuration parameters to modules
User can now use -p <key>=<value> to pass configuration parameters to modules. For this, the module gets a "parameter()" method. Parameter keys are in the format <name>.<key> where <name> is the name of the loaded module. This is either the name of the module itself (e.g. "cpu") or its alias, if the user specified it, for example: bumblebee-status -m cpu -p cpu.warning=90 vs. bumblebee-status -m cpu:test -p test.warning=90 see #23
This commit is contained in:
parent
c8a51b416f
commit
f33711f49f
4 changed files with 52 additions and 5 deletions
|
@ -3,17 +3,32 @@
|
|||
import unittest
|
||||
|
||||
from bumblebee.engine import Module
|
||||
from bumblebee.config import Config
|
||||
from tests.util import MockWidget
|
||||
|
||||
class TestModule(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.widget = MockWidget("foo")
|
||||
self.config = Config()
|
||||
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]
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
def test_empty_widgets(self):
|
||||
self.assertEquals(self.moduleWithoutWidgets.widgets(), [])
|
||||
|
||||
|
@ -23,3 +38,11 @@ class TestModule(unittest.TestCase):
|
|||
def test_multiple_widgets(self):
|
||||
for widget in self.moduleWithMultipleWidgets.widgets():
|
||||
self.assertEquals(widget, self.widget)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue