From 9a5a6d354ac6011af75326d14c5501947dbffd8c Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 3 Dec 2016 20:54:57 +0100 Subject: [PATCH] [core/config] Add module aliases Allow the user to provide aliases when loading a module multiple times so that the modules can be differentiated (e.g. for passing parameters to a module). see #23 --- bumblebee/config.py | 5 ++++- runtests.sh | 6 ++++++ tests/test_config.py | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bumblebee/config.py b/bumblebee/config.py index d33219c..17e679d 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -8,7 +8,10 @@ class Config(object): self._args = parser.parse_args(args) def modules(self): - return list(map(lambda x: { "name": x, "module": x }, self._args.modules)) + return list(map(lambda x: { + "module": x.split(":")[0], + "name": x if not ":" in x else x.split(":")[1] + }, self._args.modules)) def _create_parser(self): parser = argparse.ArgumentParser(description="display system data in the i3bar") diff --git a/runtests.sh b/runtests.sh index 089f936..8786182 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,5 +1,11 @@ #!/bin/sh test=$(which nosetests) + +echo "testing $(python2 -V 2>&1)" python2 $test --rednose -v tests/ + +echo + +echo "testing $(python3 -V 2>&1)" python3 $test --rednose -v tests/ diff --git a/tests/test_config.py b/tests/test_config.py index d344932..aa860f6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -6,13 +6,23 @@ class TestConfig(unittest.TestCase): def setUp(self): self.defaultConfig = Config() self.someSimpleModules = [ "foo", "bar", "baz" ] + self.someAliasModules = [ "foo:a", "bar:b", "baz:c" ] + def test_no_modules_by_default(self): self.assertEquals(self.defaultConfig.modules(), []) def test_load_simple_modules(self): cfg = Config([ "-m" ] + self.someSimpleModules) - self.assertEquals(cfg.modules(), - list(map(lambda x: { "name": x, "module": x }, self.someSimpleModules))) + self.assertEquals(cfg.modules(), list(map(lambda x: { + "name": x, "module": x + }, self.someSimpleModules))) + + def test_load_alias_modules(self): + cfg = Config([ "-m" ] + self.someAliasModules) + self.assertEquals(cfg.modules(), list(map(lambda x: { + "module": x.split(":")[0], + "name": x.split(":")[1] + }, self.someAliasModules))) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4