default value if option is set to None

This commit is contained in:
gwen 2012-07-10 15:15:35 +02:00
parent 166ffc72f7
commit a80b868cae
3 changed files with 26 additions and 4 deletions

View File

@ -330,6 +330,7 @@ class Config(object):
child.setowner(self, ['default' for i in range(len(child.getdefault()))])
else:
child.setowner(self, 'default')
self._cfgimpl_values[name] = child.getdefault()
else:
child.setowner(self, newowner)
else:

View File

@ -7,7 +7,28 @@ from error import SpecialOwnersError
def make_description():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
## dummy 1
gcdummy = BoolOption('dummy', 'dummy', default=False, callback="toto")
objspaceoption = ChoiceOption('objspace', 'Object space',
['std', 'thunk'], 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
floatoption = FloatOption('float', 'Test float option', default=2.3)
stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=['boolop'])
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=['boolop'])
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
def make_description2():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
objspaceoption = ChoiceOption('objspace', 'Object space',
['std', 'thunk'], 'std')
@ -30,9 +51,9 @@ def make_description():
def test_override_are_default_owner():
"config.override() implies that the owner is 'default' again"
descr = make_description()
descr = make_description2()
config = Config(descr, bool=False)
# defaut
# default
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
# user
config.gc.dummy = True

View File

@ -47,7 +47,7 @@ def test_reset():
assert config.string == "foo"
assert config._cfgimpl_value_owners['string'] == 'user'
config.string = None
assert config.string == None
assert config.string == 'string'
assert config._cfgimpl_value_owners['string'] == 'default'
def test_idontexist():