callback with option in params which is in an hidden optiondescription
This commit is contained in:
parent
32de14b731
commit
75f7e7ce5d
|
@ -487,3 +487,14 @@ def test_callback_master_and_slaves_value():
|
||||||
assert cfg.val1.val2 == ['val2', 'val2', 'val3']
|
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
|
||||||
|
|
|
@ -49,7 +49,7 @@ def carry_out_calculation(name, config, callback, callback_params, index=None):
|
||||||
raise ConfigError(_('no config specified but needed'))
|
raise ConfigError(_('no config specified but needed'))
|
||||||
try:
|
try:
|
||||||
opt_value = config._getattr(path, force_permissive=True)
|
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:
|
except PropertiesOptionError, err:
|
||||||
if check_disabled:
|
if check_disabled:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -351,32 +351,32 @@ class SubConfig(BaseInformation):
|
||||||
|
|
||||||
def make_dict(self, flatten=False, _currpath=None, withoption=None,
|
def make_dict(self, flatten=False, _currpath=None, withoption=None,
|
||||||
withvalue=None):
|
withvalue=None):
|
||||||
"""exports the whole config into a `dict`, for example:
|
"""exports the whole config into a `dict`, for example:
|
||||||
|
|
||||||
>>> print cfg.make_dict()
|
>>> print cfg.make_dict()
|
||||||
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
|
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:param flatten: returns a dict(name=value) instead of a dict(path=value)
|
:param flatten: returns a dict(name=value) instead of a dict(path=value)
|
||||||
::
|
::
|
||||||
|
|
||||||
>>> print cfg.make_dict(flatten=True)
|
>>> print cfg.make_dict(flatten=True)
|
||||||
{'var5': None, 'var4': None, 'var6': None}
|
{'var5': None, 'var4': None, 'var6': None}
|
||||||
|
|
||||||
:param withoption: returns the options that are present in the very same
|
:param withoption: returns the options that are present in the very same
|
||||||
`OptionDescription` than the `withoption` itself::
|
`OptionDescription` than the `withoption` itself::
|
||||||
|
|
||||||
>>> print cfg.make_dict(withoption='var1')
|
>>> print cfg.make_dict(withoption='var1')
|
||||||
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
|
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
|
||||||
'od2.var1': u'value', 'od1.var1': None,
|
'od2.var1': u'value', 'od1.var1': None,
|
||||||
'od1.var3': None, 'od1.var2': None}
|
'od1.var3': None, 'od1.var2': None}
|
||||||
|
|
||||||
:param withvalue: returns the options that have the value `withvalue`
|
:param withvalue: returns the options that have the value `withvalue`
|
||||||
::
|
::
|
||||||
|
|
||||||
>>> print c.make_dict(withoption='var1', withvalue=u'value')
|
>>> print c.make_dict(withoption='var1', withvalue=u'value')
|
||||||
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
|
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
|
||||||
'od2.var1': u'value'}
|
'od2.var1': u'value'}
|
||||||
|
|
||||||
:returns: dict of Option's name (or path) and values
|
:returns: dict of Option's name (or path) and values
|
||||||
|
@ -466,7 +466,7 @@ class CommonConfig(SubConfig):
|
||||||
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
|
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
|
||||||
return self.cfgimpl_get_values().getowner(opt)
|
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()
|
"""convenience method to extract and Option() object from the Config()
|
||||||
and it is **fast**: finds the option directly in the appropriate
|
and it is **fast**: finds the option directly in the appropriate
|
||||||
namespace
|
namespace
|
||||||
|
@ -474,7 +474,8 @@ class CommonConfig(SubConfig):
|
||||||
:returns: Option()
|
:returns: Option()
|
||||||
"""
|
"""
|
||||||
if '.' in path:
|
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(homeconfig.cfgimpl_get_description(), path)
|
||||||
return getattr(self.cfgimpl_get_description(), path)
|
return getattr(self.cfgimpl_get_description(), path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue