callback with option in params which is in an hidden optiondescription

This commit is contained in:
Emmanuel Garette 2013-06-26 16:26:42 +02:00
parent 32de14b731
commit 75f7e7ce5d
3 changed files with 24 additions and 12 deletions

View File

@ -487,3 +487,14 @@ def test_callback_master_and_slaves_value():
assert cfg.val1.val2 == ['val2', 'val2', 'val3']
def test_callback_hidden():
opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': (('od1.opt1', False),)})
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.cfgimpl_get_settings().set_permissive(('hidden',))
cfg.read_write()
raises(PropertiesOptionError, 'cfg.od1.opt1')
cfg.od2.opt2

View File

@ -49,7 +49,7 @@ def carry_out_calculation(name, config, callback, callback_params, index=None):
raise ConfigError(_('no config specified but needed'))
try:
opt_value = config._getattr(path, force_permissive=True)
opt = config.unwrap_from_path(path)
opt = config.unwrap_from_path(path, force_permissive=True)
except PropertiesOptionError, err:
if check_disabled:
continue

View File

@ -466,7 +466,7 @@ class CommonConfig(SubConfig):
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
return self.cfgimpl_get_values().getowner(opt)
def unwrap_from_path(self, path):
def unwrap_from_path(self, path, force_permissive=False):
"""convenience method to extract and Option() object from the Config()
and it is **fast**: finds the option directly in the appropriate
namespace
@ -474,7 +474,8 @@ class CommonConfig(SubConfig):
:returns: Option()
"""
if '.' in path:
homeconfig, path = self.cfgimpl_get_home_by_path(path)
homeconfig, path = self.cfgimpl_get_home_by_path(path,
force_permissive=force_permissive)
return getattr(homeconfig.cfgimpl_get_description(), path)
return getattr(self.cfgimpl_get_description(), path)