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
def make_dict(self, flatten=False, _currpath=None, withoption=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()
{'od2.var4': None, 'od2.var5': None, 'od2.var6': None}
-
-
-
+
+
+
:param flatten: returns a dict(name=value) instead of a dict(path=value)
::
>>> print cfg.make_dict(flatten=True)
{'var5': None, 'var4': None, 'var6': None}
-
+
:param withoption: returns the options that are present in the very same
`OptionDescription` than the `withoption` itself::
>>> print cfg.make_dict(withoption='var1')
- {'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
- 'od2.var1': u'value', 'od1.var1': None,
+ {'od2.var4': None, 'od2.var5': None, 'od2.var6': None,
+ 'od2.var1': u'value', 'od1.var1': None,
'od1.var3': None, 'od1.var2': None}
:param withvalue: returns the options that have the value `withvalue`
::
>>> 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'}
:returns: dict of Option's name (or path) and values
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
: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)