Merge branch 'master' into better_warnings

This commit is contained in:
Emmanuel Garette 2014-03-12 22:13:20 +01:00
commit 88b5af9810
3 changed files with 39 additions and 10 deletions

View File

@ -115,6 +115,18 @@ def test_make_dict():
raises(ValueError, 'd2 = config.make_dict(withvalue="3")') 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(): def test_find_in_config():
"finds option in config" "finds option in config"
descr = make_description() descr = make_description()

View File

@ -359,3 +359,17 @@ def test_consistency_permissive():
c.cfgimpl_get_settings().setpermissive(('hidden',)) c.cfgimpl_get_settings().setpermissive(('hidden',))
c.read_write() c.read_write()
c.a = 1 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

View File

@ -448,17 +448,20 @@ class SubConfig(object):
return pathsvalues return pathsvalues
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten): def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
if isinstance(opt, OptionDescription): try:
pathsvalues += getattr(self, path).make_dict(flatten, if isinstance(opt, OptionDescription):
_currpath + pathsvalues += getattr(self, path).make_dict(flatten,
path.split('.')) _currpath +
else: path.split('.'))
value = self._getattr(opt._name)
if flatten:
name = opt._name
else: else:
name = '.'.join(_currpath + [opt._name]) value = self._getattr(opt._name)
pathsvalues.append((name, value)) if flatten:
name = opt._name
else:
name = '.'.join(_currpath + [opt._name])
pathsvalues.append((name, value))
except PropertiesOptionError:
pass
def cfgimpl_get_path(self): def cfgimpl_get_path(self):
descr = self.cfgimpl_get_description() descr = self.cfgimpl_get_description()