From 544cd93c733c6033549b5972b95d894cd5cf2461 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 12 Mar 2014 14:57:36 +0100 Subject: [PATCH 1/2] can make_dict with disabled suboption --- test/test_config_api.py | 12 ++++++++++++ tiramisu/config.py | 23 +++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/test/test_config_api.py b/test/test_config_api.py index 4be9e80..93f8c95 100644 --- a/test/test_config_api.py +++ b/test/test_config_api.py @@ -115,6 +115,18 @@ def test_make_dict(): raises(ValueError, 'd2 = config.make_dict(withvalue="3")') +def test_make_dict_with_disabled(): + descr = OptionDescription("opt", "", [ + OptionDescription("s1", "", [ + BoolOption("a", "", default=False), + BoolOption("b", "", default=False, properties=('disabled',))]), + IntOption("int", "", default=42)]) + config = Config(descr) + config.read_only() + d = config.make_dict() + assert d == {"s1.a": False, "int": 42} + + def test_find_in_config(): "finds option in config" descr = make_description() diff --git a/tiramisu/config.py b/tiramisu/config.py index c9fb992..4c59dbe 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -448,17 +448,20 @@ class SubConfig(object): return pathsvalues def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten): - if isinstance(opt, OptionDescription): - pathsvalues += getattr(self, path).make_dict(flatten, - _currpath + - path.split('.')) - else: - value = self._getattr(opt._name) - if flatten: - name = opt._name + try: + if isinstance(opt, OptionDescription): + pathsvalues += getattr(self, path).make_dict(flatten, + _currpath + + path.split('.')) else: - name = '.'.join(_currpath + [opt._name]) - pathsvalues.append((name, value)) + value = self._getattr(opt._name) + if flatten: + name = opt._name + else: + name = '.'.join(_currpath + [opt._name]) + pathsvalues.append((name, value)) + except PropertiesOptionError: + pass def cfgimpl_get_path(self): descr = self.cfgimpl_get_description() From 5f46763696f2b5cc3758d6efa568005cbb250a68 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 12 Mar 2014 16:44:48 +0100 Subject: [PATCH 2/2] add test for consistency with callback --- test/test_option_consistency.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index b40c340..45e8213 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -345,3 +345,17 @@ def test_consistency_permissive(): c.cfgimpl_get_settings().setpermissive(('hidden',)) c.read_write() c.a = 1 + + +def return_val(*args, **kwargs): + return '192.168.1.1' + + +def test_consistency_with_callback(): + a = NetworkOption('a', '', default='192.168.1.0') + b = NetmaskOption('b', '', default='255.255.255.0') + c = IPOption('c', '', callback=return_val, callback_params={'': ((a, False),)}) + od = OptionDescription('od', '', [a, b, c]) + c.impl_add_consistency('in_network', a, b) + cfg = Config(od) + cfg.c