From 9ddf100118d913c2f4225cca1adb65317b512d84 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 16 Sep 2013 15:02:14 +0200 Subject: [PATCH] when we get an option's value, we need it's values to calculate properties (ie for mandatory's option) if a disabled option has a callback to an other disabled value, it's raise ConfigError now only raise if option has no other propertiesError --- test/test_option_calculation.py | 11 +++++++++++ tiramisu/value.py | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/test/test_option_calculation.py b/test/test_option_calculation.py index 0266855..d57072f 100644 --- a/test/test_option_calculation.py +++ b/test/test_option_calculation.py @@ -498,3 +498,14 @@ def test_callback_hidden(): cfg.read_write() raises(PropertiesOptionError, 'cfg.od1.opt1') cfg.od2.opt2 + + +def test_callback_disable_make_dict(): + opt1 = BoolOption('opt1', '', properties=('disabled',)) + opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': (('od1.opt1', False),)}, properties=('disabled',)) + od1 = OptionDescription('od1', '', [opt1]) + od2 = OptionDescription('od2', '', [opt2]) + maconfig = OptionDescription('rootconfig', '', [od1, od2]) + cfg = Config(maconfig) + cfg.read_write() + raises(PropertiesOptionError, 'cfg.od1.opt1') diff --git a/tiramisu/value.py b/tiramisu/value.py index ffd34d6..3d172dc 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -179,6 +179,7 @@ class Values(object): is_frozen = 'frozen' in setting[opt] # if value is callback and is not set # or frozen with force_default_on_freeze + config_error = None if opt.impl_has_callback() and ( self._is_default_owner(path) or (is_frozen and 'force_default_on_freeze' in setting[opt])): @@ -193,11 +194,15 @@ class Values(object): no_value_slave = True if not no_value_slave: - value = self._getcallback_value(opt) - if (opt.impl_is_multi() and - opt.impl_get_multitype() == multitypes.slave): - if not isinstance(value, list): - value = [value for i in range(lenmaster)] + try: + value = self._getcallback_value(opt) + except ConfigError as config_error: + value = None + else: + if (opt.impl_is_multi() and + opt.impl_get_multitype() == multitypes.slave): + if not isinstance(value, list): + value = [value for i in range(lenmaster)] if opt.impl_is_multi(): value = Multi(value, self.context, opt, path, validate) # suppress value if already set @@ -218,6 +223,8 @@ class Values(object): setting.validate_properties(opt, False, False, value=value, path=path, force_permissive=force_permissive, force_properties=force_properties) + if config_error is not None: + raise ConfigError(config_error) return value def __setitem__(self, opt, value):