|
From: Jeremy G. <jr...@gm...> - 2009-10-16 23:21:48
|
Hi Michael,
I think I've isolated this to whether the spec contains defaults for
items in the section that goes missing. if there are defaults
specified, the section gets recreated using the defaults, and
validation succeeds (== the section is not reported as missing). its
very cool to have the option to recreate the section from defaults,
but it would seem nice to be warned about that situation too. is this
expected behavior? is there a way to tell configobj what to do? sorry
if I just missed this on the web page(s).
original example that succeeds (validate reports missing section):
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>> a = ['baz = 3']
>>> b = ['baz = integer', '[foo]', 'bar=integer']
>>> c = ConfigObj(a, configspec=b)
>>> v = Validator()
>>> r = c.validate(v)
>>> r
{'foo': False, 'baz': True}
adding 'default=2' WITHIN the section in b that is missing from a
(namely section [foo]): validate does not report the missing section:
>>> a = ['baz = 3']
>>> b = ['baz = integer', '[foo]', 'bar=integer(default=2)']
>>> c = ConfigObj(a, configspec=b)
>>> r = c.validate(v)
>>> r
True
adding 'default=2', but outside the section that is missing: validate
does report the missing section:
>>> b = ['baz = integer(default=2)', '[foo]', 'bar=integer']
>>> c = ConfigObj(a, configspec=b)
>>> r = c.validate(v)
>>> r
{'foo': False, 'baz': True}
--Jeremy
|