suppression of the override
This commit is contained in:
parent
1de236d2a8
commit
09dba4b959
|
@ -18,7 +18,7 @@ def make_description():
|
||||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
|
@ -39,27 +39,28 @@ def test_reset_value():
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
assert cfg.gc.dummy == False
|
assert cfg.gc.dummy == False
|
||||||
cfg.gc.dummy = True
|
cfg.gc.dummy = True
|
||||||
assert cfg.gc.dummy == True
|
assert cfg.gc.dummy == True
|
||||||
cfg.gc.dummy = None
|
cfg.gc.dummy = None
|
||||||
|
|
||||||
def test_base_config_and_groups():
|
def test_base_config_and_groups():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
# overrides the booloption default value
|
# overrides the booloption default value
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
assert config.gc.name == 'ref'
|
assert config.gc.name == 'ref'
|
||||||
assert config.bool == False
|
assert config.bool == False
|
||||||
nm = config.unwrap_from_path('gc.name')
|
nm = config.unwrap_from_path('gc.name')
|
||||||
assert nm._name == 'name'
|
assert nm._name == 'name'
|
||||||
gc = config.unwrap_from_path('gc')
|
gc = config.unwrap_from_path('gc')
|
||||||
assert gc._name == 'gc'
|
assert gc._name == 'gc'
|
||||||
nm = config.unwrap_from_name('name')
|
nm = config.unwrap_from_name('name')
|
||||||
assert nm._name == 'name'
|
assert nm._name == 'name'
|
||||||
|
|
||||||
def test_base_config_in_a_tree():
|
def test_base_config_in_a_tree():
|
||||||
"how options are organized into a tree"
|
"how options are organized into a tree"
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
assert config.gc.name == 'ref'
|
assert config.gc.name == 'ref'
|
||||||
config.gc.name = 'framework'
|
config.gc.name = 'framework'
|
||||||
assert config.gc.name == 'framework'
|
assert config.gc.name == 'framework'
|
||||||
|
@ -68,7 +69,7 @@ def test_base_config_in_a_tree():
|
||||||
assert config.objspace == 'std'
|
assert config.objspace == 'std'
|
||||||
config.objspace = 'thunk'
|
config.objspace = 'thunk'
|
||||||
assert config.objspace == 'thunk'
|
assert config.objspace == 'thunk'
|
||||||
|
|
||||||
assert config.gc.float == 2.3
|
assert config.gc.float == 2.3
|
||||||
assert config.int == 0
|
assert config.int == 0
|
||||||
config.gc.float = 3.4
|
config.gc.float = 3.4
|
||||||
|
@ -84,21 +85,24 @@ def test_base_config_in_a_tree():
|
||||||
|
|
||||||
raises(AttributeError, 'config.gc.foo = "bar"')
|
raises(AttributeError, 'config.gc.foo = "bar"')
|
||||||
|
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
assert config.gc.name == 'ref'
|
assert config.gc.name == 'ref'
|
||||||
config.wantframework = True
|
config.wantframework = True
|
||||||
|
|
||||||
def test_config_values():
|
def test_config_values():
|
||||||
"_cfgimpl_values appears to be a simple dict"
|
"_cfgimpl_values appears to be a simple dict"
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
config.set(dummy=False)
|
config.set(dummy=False)
|
||||||
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||||
|
|
||||||
def test_cfgimpl_get_home_by_path():
|
def test_cfgimpl_get_home_by_path():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
assert config._cfgimpl_get_home_by_path('gc.dummy')[1] == 'dummy'
|
assert config._cfgimpl_get_home_by_path('gc.dummy')[1] == 'dummy'
|
||||||
assert config._cfgimpl_get_home_by_path('dummy')[1] == 'dummy'
|
assert config._cfgimpl_get_home_by_path('dummy')[1] == 'dummy'
|
||||||
assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||||
assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||||
|
|
|
@ -30,7 +30,8 @@ def test_compare_configs():
|
||||||
"config object comparison"
|
"config object comparison"
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
conf1 = Config(descr)
|
conf1 = Config(descr)
|
||||||
conf2 = Config(descr, wantref=True)
|
conf2 = Config(descr)
|
||||||
|
conf2.wantref = True
|
||||||
assert conf1 != conf2
|
assert conf1 != conf2
|
||||||
assert hash(conf1) != hash(conf2)
|
assert hash(conf1) != hash(conf2)
|
||||||
assert conf1.getkey() != conf2.getkey()
|
assert conf1.getkey() != conf2.getkey()
|
||||||
|
@ -183,4 +184,4 @@ def test_find_in_config():
|
||||||
# assert c.booloption2 is False
|
# assert c.booloption2 is False
|
||||||
# c.booloption2 = False
|
# c.booloption2 = False
|
||||||
# assert c.booloption2 is False
|
# assert c.booloption2 is False
|
||||||
#
|
#
|
||||||
|
|
|
@ -54,16 +54,16 @@ def make_description_duplicates():
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
def test_identical_paths():
|
def test_identical_paths():
|
||||||
"""If in the schema (the option description) there is something that
|
"""If in the schema (the option description) there is something that
|
||||||
have the same name, an exection is raised
|
have the same name, an exection is raised
|
||||||
"""
|
"""
|
||||||
descr = make_description_duplicates()
|
descr = make_description_duplicates()
|
||||||
raises(ConflictConfigError, "cfg = Config(descr)")
|
raises(ConflictConfigError, "cfg = Config(descr)")
|
||||||
|
|
||||||
#def test_identical_for_names():
|
#def test_identical_for_names():
|
||||||
# """if there is something that
|
# """if there is something that
|
||||||
# have the same name, an exection is raised
|
# have the same name, an exection is raised
|
||||||
# """
|
# """
|
||||||
# descr = make_description_duplicates()
|
# descr = make_description_duplicates()
|
||||||
# raises(ConflictConfigError, "cfg = Config(descr)")
|
# raises(ConflictConfigError, "cfg = Config(descr)")
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ def make_description2():
|
||||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||||
|
|
||||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||||
|
|
||||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||||
['std', 'thunk'], 'std')
|
['std', 'thunk'], 'std')
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
|
@ -89,7 +89,7 @@ def make_description2():
|
||||||
default=False,
|
default=False,
|
||||||
requires=['boolop'])
|
requires=['boolop'])
|
||||||
wantframework_option.enable_multi()
|
wantframework_option.enable_multi()
|
||||||
|
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
|
@ -97,20 +97,20 @@ def make_description2():
|
||||||
intoption, boolop])
|
intoption, boolop])
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
# FIXME: XXX would you mind putting the multi validations anywhere else
|
# FIXME: XXX would you mind putting the multi validations anywhere else
|
||||||
# than in the requires !!!
|
# than in the requires !!!
|
||||||
#def test_multi_constraints():
|
#def test_multi_constraints():
|
||||||
# "a multi in a constraint has to have the same length"
|
# "a multi in a constraint has to have the same length"
|
||||||
# descr = make_description2()
|
# descr = make_description2()
|
||||||
# cfg = Config(descr)
|
# cfg = Config(descr)
|
||||||
# cfg.boolop = [True, True, False]
|
# cfg.boolop = [True, True, False]
|
||||||
# cfg.wantframework = [False, False, True]
|
# cfg.wantframework = [False, False, True]
|
||||||
#
|
#
|
||||||
#def test_multi_raise():
|
#def test_multi_raise():
|
||||||
# "a multi in a constraint has to have the same length"
|
# "a multi in a constraint has to have the same length"
|
||||||
# # FIXME fusionner les deux tests, MAIS PROBLEME :
|
# # FIXME fusionner les deux tests, MAIS PROBLEME :
|
||||||
# # il ne devrait pas etre necessaire de refaire une config
|
# # il ne devrait pas etre necessaire de refaire une config
|
||||||
# # si la valeur est modifiee une deuxieme fois ->
|
# # si la valeur est modifiee une deuxieme fois ->
|
||||||
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||||
# # ExceptionFailure: 'DID NOT RAISE'
|
# # ExceptionFailure: 'DID NOT RAISE'
|
||||||
# descr = make_description2()
|
# descr = make_description2()
|
||||||
|
@ -130,12 +130,14 @@ def test_newoption_add_in_subdescr():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||||
descr.gc.add_child(newoption)
|
descr.gc.add_child(newoption)
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
assert config.gc.newoption == False
|
assert config.gc.newoption == False
|
||||||
|
|
||||||
def test_newoption_add_in_config():
|
def test_newoption_add_in_config():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||||
descr.add_child(newoption)
|
descr.add_child(newoption)
|
||||||
config.cfgimpl_update()
|
config.cfgimpl_update()
|
||||||
|
@ -146,14 +148,14 @@ def make_description_requires():
|
||||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||||
|
|
||||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||||
|
|
||||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||||
['std', 'thunk'], 'std')
|
['std', 'thunk'], 'std')
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
stroption = StrOption('str', 'Test string option', default="abc",
|
stroption = StrOption('str', 'Test string option', default="abc",
|
||||||
requires=[('int', 1, 'hide')])
|
requires=[('int', 1, 'hide')])
|
||||||
|
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||||
stroption, intoption])
|
stroption, intoption])
|
||||||
|
@ -175,15 +177,15 @@ def test_hidden_if_in_with_group():
|
||||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||||
|
|
||||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||||
|
|
||||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||||
['std', 'thunk'], 'std')
|
['std', 'thunk'], 'std')
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
stroption = StrOption('str', 'Test string option', default="abc")
|
stroption = StrOption('str', 'Test string option', default="abc")
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||||
requires=[('int', 1, 'hide')])
|
requires=[('int', 1, 'hide')])
|
||||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||||
objspaceoption, stroption, intoption])
|
objspaceoption, stroption, intoption])
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
assert not gcgroup._is_hidden()
|
assert not gcgroup._is_hidden()
|
||||||
|
@ -196,19 +198,18 @@ def test_disabled_with_group():
|
||||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||||
|
|
||||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||||
|
|
||||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||||
['std', 'thunk'], 'std')
|
['std', 'thunk'], 'std')
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
stroption = StrOption('str', 'Test string option', default="abc")
|
stroption = StrOption('str', 'Test string option', default="abc")
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||||
requires=[('int', 1, 'disable')])
|
requires=[('int', 1, 'disable')])
|
||||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||||
objspaceoption, stroption, intoption])
|
objspaceoption, stroption, intoption])
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
assert not gcgroup._is_disabled()
|
assert not gcgroup._is_disabled()
|
||||||
cfg.int = 1
|
cfg.int = 1
|
||||||
raises(PropertiesOptionError, "cfg.gc.name")
|
raises(PropertiesOptionError, "cfg.gc.name")
|
||||||
assert gcgroup._is_disabled()
|
assert gcgroup._is_disabled()
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ def make_description():
|
||||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||||
default=False,
|
default=False,
|
||||||
requires=['boolop'])
|
requires=['boolop'])
|
||||||
|
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
|
@ -60,8 +60,8 @@ def test_mandatory():
|
||||||
config.dummy1 = True
|
config.dummy1 = True
|
||||||
assert config.dummy1 == True
|
assert config.dummy1 == True
|
||||||
raises(MandatoryError, 'config.dummy2 == None')
|
raises(MandatoryError, 'config.dummy2 == None')
|
||||||
raises(MandatoryError, "config.override({'dummy2':None})")
|
# raises(MandatoryError, "config.override({'dummy2':None})")
|
||||||
config.set(dummy2=True)
|
config.set(dummy2=True)
|
||||||
config.dummy2 = False
|
config.dummy2 = False
|
||||||
assert config.dummy2 == False
|
assert config.dummy2 == False
|
||||||
|
|
||||||
|
@ -81,13 +81,13 @@ def test_force_default_on_freeze():
|
||||||
|
|
||||||
def test_override_are_defaults():
|
def test_override_are_defaults():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
config.gc.dummy = True
|
config.gc.dummy = True
|
||||||
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
||||||
#Options have an available default setting and can give it back
|
#Options have an available default setting and can give it back
|
||||||
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
||||||
config.override({'gc.dummy':True})
|
# config.override({'gc.dummy':True})
|
||||||
#assert config.gc.dummy == True
|
#assert config.gc.dummy == True
|
||||||
#assert config._cfgimpl_descr._children[0]._children[1].getdefault() == True
|
#assert config._cfgimpl_descr._children[0]._children[1].getdefault() == True
|
||||||
#assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'default'
|
#assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'default'
|
||||||
|
@ -98,8 +98,8 @@ def test_overrides_changes_option_value():
|
||||||
BoolOption("b", "", default=False)])
|
BoolOption("b", "", default=False)])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
config.b = True
|
config.b = True
|
||||||
config.override({'b': False})
|
# config.override({'b': False})
|
||||||
assert config.b == False
|
# assert config.b == False
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
# test various option types
|
# test various option types
|
||||||
def test_choice_with_no_default():
|
def test_choice_with_no_default():
|
||||||
|
@ -114,7 +114,7 @@ def test_choice_with_default():
|
||||||
ChoiceOption("backend", "", ["c", "cli"], default="cli")])
|
ChoiceOption("backend", "", ["c", "cli"], default="cli")])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert config.backend == "cli"
|
assert config.backend == "cli"
|
||||||
|
|
||||||
def test_arbitrary_option():
|
def test_arbitrary_option():
|
||||||
descr = OptionDescription("top", "", [
|
descr = OptionDescription("top", "", [
|
||||||
ArbitraryOption("a", "no help", default=None)
|
ArbitraryOption("a", "no help", default=None)
|
||||||
|
@ -132,4 +132,3 @@ def test_arbitrary_option():
|
||||||
c1.a.append(1)
|
c1.a.append(1)
|
||||||
assert c2.a == []
|
assert c2.a == []
|
||||||
assert c1.a == [1]
|
assert c1.a == [1]
|
||||||
|
|
||||||
|
|
|
@ -48,28 +48,30 @@ def make_description2():
|
||||||
intoption, boolop])
|
intoption, boolop])
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
def test_override_are_default_owner():
|
#def test_override_are_default_owner():
|
||||||
"config.override() implies that the owner is 'default' again"
|
# "config.override() implies that the owner is 'default' again"
|
||||||
descr = make_description2()
|
# descr = make_description2()
|
||||||
config = Config(descr, bool=False)
|
# config = Config(descr)
|
||||||
# default
|
# config.bool = False
|
||||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
# # default
|
||||||
# user
|
# assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
||||||
config.gc.dummy = True
|
# # user
|
||||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
# config.gc.dummy = True
|
||||||
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
# assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
||||||
#Options have an available default setting and can give it back
|
# assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
||||||
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
# #Options have an available default setting and can give it back
|
||||||
config.override({'gc.dummy':True})
|
# assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
||||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
# config.override({'gc.dummy':True})
|
||||||
# user again
|
# assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
||||||
config.gc.dummy = False
|
# # user again
|
||||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
# config.gc.dummy = False
|
||||||
|
# assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
||||||
|
|
||||||
def test_has_callback():
|
def test_has_callback():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
# here the owner is 'default'
|
# here the owner is 'default'
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
# because dummy has a callback
|
# because dummy has a callback
|
||||||
dummy = config.unwrap_from_path('gc.dummy')
|
dummy = config.unwrap_from_path('gc.dummy')
|
||||||
config.cfgimpl_freeze()
|
config.cfgimpl_freeze()
|
||||||
|
@ -79,7 +81,8 @@ def test_has_callback():
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
def test_freeze_and_has_callback_with_setoption():
|
def test_freeze_and_has_callback_with_setoption():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
config.cfgimpl_freeze()
|
config.cfgimpl_freeze()
|
||||||
dummy = config.unwrap_from_path('gc.dummy')
|
dummy = config.unwrap_from_path('gc.dummy')
|
||||||
dummy.freeze()
|
dummy.freeze()
|
||||||
|
|
|
@ -18,7 +18,7 @@ def make_description():
|
||||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||||
default=False)
|
default=False)
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
|
@ -43,7 +43,7 @@ def test_setitem():
|
||||||
print config.string[1]
|
print config.string[1]
|
||||||
config.string[1] = "titi"
|
config.string[1] = "titi"
|
||||||
print config.string[1]
|
print config.string[1]
|
||||||
|
|
||||||
def test_reset():
|
def test_reset():
|
||||||
"if value is None, resets to default owner"
|
"if value is None, resets to default owner"
|
||||||
s = StrOption("string", "", default="string")
|
s = StrOption("string", "", default="string")
|
||||||
|
@ -52,7 +52,7 @@ def test_reset():
|
||||||
config.string = "foo"
|
config.string = "foo"
|
||||||
assert config.string == "foo"
|
assert config.string == "foo"
|
||||||
assert config._cfgimpl_value_owners['string'] == 'user'
|
assert config._cfgimpl_value_owners['string'] == 'user'
|
||||||
config.string = None
|
config.unwrap_from_path("string").reset(config)
|
||||||
assert config.string == 'string'
|
assert config.string == 'string'
|
||||||
assert config._cfgimpl_value_owners['string'] == 'default'
|
assert config._cfgimpl_value_owners['string'] == 'default'
|
||||||
|
|
||||||
|
@ -60,13 +60,15 @@ def test_reset_with_multi():
|
||||||
s = StrOption("string", "", default=["string"], default_multi="string" , multi=True)
|
s = StrOption("string", "", default=["string"], default_multi="string" , multi=True)
|
||||||
descr = OptionDescription("options", "", [s])
|
descr = OptionDescription("options", "", [s])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
config.string = []
|
# config.string = []
|
||||||
|
config.unwrap_from_path("string").reset(config)
|
||||||
assert config.string == ["string"]
|
assert config.string == ["string"]
|
||||||
assert config._cfgimpl_value_owners['string'] == ['default']
|
assert config._cfgimpl_value_owners['string'] == ['default']
|
||||||
config.string = ["eggs", "spam", "foo"]
|
config.string = ["eggs", "spam", "foo"]
|
||||||
assert config._cfgimpl_value_owners['string'] == ['user', 'user', 'user']
|
assert config._cfgimpl_value_owners['string'] == ['user', 'user', 'user']
|
||||||
config.string = []
|
config.string = []
|
||||||
assert config.string == ["string"]
|
config.unwrap_from_path("string").reset(config)
|
||||||
|
# assert config.string == ["string"]
|
||||||
assert config._cfgimpl_value_owners['string'] == ['default']
|
assert config._cfgimpl_value_owners['string'] == ['default']
|
||||||
raises(ConfigError, "config.string = None")
|
raises(ConfigError, "config.string = None")
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ def test_default_with_multi():
|
||||||
descr = OptionDescription("options", "", [s])
|
descr = OptionDescription("options", "", [s])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert config.string == []
|
assert config.string == []
|
||||||
|
|
||||||
def test_idontexist():
|
def test_idontexist():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
|
@ -124,7 +126,7 @@ def test_access_with_multi_default():
|
||||||
def test_multi_with_requires():
|
def test_multi_with_requires():
|
||||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi = "abc",
|
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi = "abc",
|
||||||
requires=[('int', 1, 'hide')], multi=True)
|
requires=[('int', 1, 'hide')], multi=True)
|
||||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
@ -148,7 +150,7 @@ def test_multi_with_requires_in_another_group():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
descr = OptionDescription("options", "", [intoption])
|
descr = OptionDescription("options", "", [intoption])
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||||
requires=[('int', 1, 'hide')], multi=True)
|
requires=[('int', 1, 'hide')], multi=True)
|
||||||
descr = OptionDescription("opt", "", [stroption])
|
descr = OptionDescription("opt", "", [stroption])
|
||||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||||
|
@ -162,7 +164,7 @@ def test_apply_requires_from_config():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
descr = OptionDescription("options", "", [intoption])
|
descr = OptionDescription("options", "", [intoption])
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||||
requires=[('int', 1, 'hide')], multi=True)
|
requires=[('int', 1, 'hide')], multi=True)
|
||||||
descr = OptionDescription("opt", "", [stroption])
|
descr = OptionDescription("opt", "", [stroption])
|
||||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||||
|
@ -172,15 +174,15 @@ def test_apply_requires_from_config():
|
||||||
try:
|
try:
|
||||||
config.opt.str
|
config.opt.str
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
assert stroption._is_hidden()
|
assert stroption._is_hidden()
|
||||||
|
|
||||||
|
|
||||||
def test_apply_requires_with_disabled():
|
def test_apply_requires_with_disabled():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
descr = OptionDescription("options", "", [intoption])
|
descr = OptionDescription("options", "", [intoption])
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||||
requires=[('int', 1, 'disable')], multi=True)
|
requires=[('int', 1, 'disable')], multi=True)
|
||||||
descr = OptionDescription("opt", "", [stroption])
|
descr = OptionDescription("opt", "", [stroption])
|
||||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||||
|
@ -190,14 +192,14 @@ def test_apply_requires_with_disabled():
|
||||||
try:
|
try:
|
||||||
config.opt.str
|
config.opt.str
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
assert stroption._is_disabled()
|
assert stroption._is_disabled()
|
||||||
|
|
||||||
def test_multi_with_requires_with_disabled_in_another_group():
|
def test_multi_with_requires_with_disabled_in_another_group():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
descr = OptionDescription("options", "", [intoption])
|
descr = OptionDescription("options", "", [intoption])
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||||
requires=[('int', 1, 'disable')], multi=True)
|
requires=[('int', 1, 'disable')], multi=True)
|
||||||
descr = OptionDescription("opt", "", [stroption])
|
descr = OptionDescription("opt", "", [stroption])
|
||||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||||
|
@ -210,7 +212,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||||
def test_multi_with_requires_that_is_multi():
|
def test_multi_with_requires_that_is_multi():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||||
requires=[('int', [1, 1], 'hide')], multi=True)
|
requires=[('int', [1, 1], 'hide')], multi=True)
|
||||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
|
@ -307,7 +309,7 @@ def test_set_with_unknown_option():
|
||||||
def test_set_symlink_option():
|
def test_set_symlink_option():
|
||||||
boolopt = BoolOption("b", "", default=False)
|
boolopt = BoolOption("b", "", default=False)
|
||||||
linkopt = SymLinkOption("c", "s1.b")
|
linkopt = SymLinkOption("c", "s1.b")
|
||||||
descr = OptionDescription("opt", "",
|
descr = OptionDescription("opt", "",
|
||||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
setattr(config, "s1.b", True)
|
setattr(config, "s1.b", True)
|
||||||
|
@ -320,18 +322,19 @@ def test_set_symlink_option():
|
||||||
config.c = False
|
config.c = False
|
||||||
assert config.s1.b == False
|
assert config.s1.b == False
|
||||||
assert config.c == False
|
assert config.c == False
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
def test_config_impl_values():
|
def test_config_impl_values():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr)
|
||||||
|
config.bool = False
|
||||||
# gcdummy.setoption(config, True, "user")
|
# gcdummy.setoption(config, True, "user")
|
||||||
# config.setoption("gc.dummy", True, "user")
|
# config.setoption("gc.dummy", True, "user")
|
||||||
#config.gc.dummy = True
|
#config.gc.dummy = True
|
||||||
# config.setoption("bool", False, "user")
|
# config.setoption("bool", False, "user")
|
||||||
config.set(dummy=False)
|
config.set(dummy=False)
|
||||||
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||||
## acces to the option object
|
## acces to the option object
|
||||||
# config.gc._cfgimpl_descr.dummy.setoption(config, True, "user")
|
# config.gc._cfgimpl_descr.dummy.setoption(config, True, "user")
|
||||||
assert config.gc.dummy == False
|
assert config.gc.dummy == False
|
||||||
# config.set(dummy=True)
|
# config.set(dummy=True)
|
||||||
|
@ -346,18 +349,18 @@ def test_accepts_multiple_changes_from_option():
|
||||||
assert s.getdefault() == "string"
|
assert s.getdefault() == "string"
|
||||||
assert config.string == "egg"
|
assert config.string == "egg"
|
||||||
s.setoption(config, 'blah', "default")
|
s.setoption(config, 'blah', "default")
|
||||||
assert s.getdefault() == "blah"
|
assert s.getdefault() == "string"
|
||||||
assert config.string == "blah"
|
assert config.string == "blah"
|
||||||
s.setoption(config, 'bol', "user")
|
s.setoption(config, 'bol', "user")
|
||||||
assert config.string == 'bol'
|
assert config.string == 'bol'
|
||||||
config.override({'string': "blurp"})
|
# config.override({'string': "blurp"})
|
||||||
assert config.string == 'blurp'
|
# assert config.string == 'blurp'
|
||||||
assert s.getdefault() == 'blurp'
|
# assert s.getdefault() == 'blurp'
|
||||||
|
|
||||||
def test_allow_multiple_changes_from_config():
|
def test_allow_multiple_changes_from_config():
|
||||||
"""
|
"""
|
||||||
a `setoption` from the config object is much like the attribute access,
|
a `setoption` from the config object is much like the attribute access,
|
||||||
except the fact that value owner can bet set
|
except the fact that value owner can bet set
|
||||||
"""
|
"""
|
||||||
s = StrOption("string", "", default="string")
|
s = StrOption("string", "", default="string")
|
||||||
s2 = StrOption("string2", "", default="string")
|
s2 = StrOption("string2", "", default="string")
|
||||||
|
@ -365,24 +368,25 @@ def test_allow_multiple_changes_from_config():
|
||||||
descr = OptionDescription("options", "", [s, suboption])
|
descr = OptionDescription("options", "", [s, suboption])
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
config.setoption("string", 'blah', "user")
|
config.setoption("string", 'blah', "user")
|
||||||
config.setoption("string", "oh", "user")
|
config.setoption("string", "oh", "user")
|
||||||
assert config.string == "oh"
|
assert config.string == "oh"
|
||||||
config.set(string2= 'blah')
|
config.set(string2= 'blah')
|
||||||
assert config.bip.string2 == 'blah'
|
assert config.bip.string2 == 'blah'
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
def test_overrides_are_defaults():
|
#def test_overrides_are_defaults():
|
||||||
descr = OptionDescription("test", "", [
|
# descr = OptionDescription("test", "", [
|
||||||
BoolOption("b1", "", default=False),
|
# BoolOption("b1", "", default=False),
|
||||||
BoolOption("b2", "", default=False),
|
# BoolOption("b2", "", default=False),
|
||||||
])
|
# ])
|
||||||
# overrides here
|
# # overrides here
|
||||||
config = Config(descr, b2=True)
|
# config = Config(descr)
|
||||||
assert config.b2
|
# config.b2 = True
|
||||||
# test with a require
|
# assert config.b2
|
||||||
config.b1 = True
|
# # test with a require
|
||||||
assert config.b2
|
# config.b1 = True
|
||||||
|
# assert config.b2
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
# accessing a value by the get method
|
# accessing a value by the get method
|
||||||
def test_access_by_get():
|
def test_access_by_get():
|
||||||
|
@ -407,4 +411,3 @@ def test_access_by_get_whith_hide():
|
||||||
])
|
])
|
||||||
c = Config(descr)
|
c = Config(descr)
|
||||||
raises(PropertiesOptionError, "c.get('b1')")
|
raises(PropertiesOptionError, "c.get('b1')")
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ def make_description():
|
||||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, gcdummy2])
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, gcdummy2])
|
||||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
|
@ -27,11 +27,11 @@ def make_description():
|
||||||
intoption, boolop])
|
intoption, boolop])
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
def test_base_config_and_groups():
|
#def test_base_config_and_groups():
|
||||||
descr = make_description()
|
# descr = make_description()
|
||||||
# overrides the booloption default value
|
# # overrides the booloption default value
|
||||||
config = Config(descr, bool=False)
|
# config = Config(descr, bool=False)
|
||||||
assert config.gc.hide == True
|
# assert config.gc.hide == True
|
||||||
|
|
||||||
def test_root_config_answers_ok():
|
def test_root_config_answers_ok():
|
||||||
"if you hide the root config, the options in this namespace behave normally"
|
"if you hide the root config, the options in this namespace behave normally"
|
||||||
|
@ -42,6 +42,3 @@ def test_root_config_answers_ok():
|
||||||
cfg.cfgimpl_enable_property('hiddend') #cfgimpl_hide()
|
cfg.cfgimpl_enable_property('hiddend') #cfgimpl_hide()
|
||||||
assert cfg.dummy == False
|
assert cfg.dummy == False
|
||||||
assert cfg.boolop == True
|
assert cfg.boolop == True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,12 @@ from tiramisu.error import (PropertiesOptionError, ConfigError, NotFoundError,
|
||||||
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
||||||
MandatoryError, MethodCallError, NoValueReturned)
|
MandatoryError, MethodCallError, NoValueReturned)
|
||||||
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
|
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
|
||||||
group_types, Multi, apply_requires)
|
group_types, Multi, apply_requires, Owner)
|
||||||
|
|
||||||
# ______________________________________________________________________
|
# ______________________________________________________________________
|
||||||
# generic owner. 'default' is the general config owner after init time
|
# generic owner. 'default' is the general config owner after init time
|
||||||
default_owner = 'user'
|
default_owner = 'user'
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
class Config(object):
|
class Config(object):
|
||||||
"properties attribute: the name of a property enables this property"
|
"properties attribute: the name of a property enables this property"
|
||||||
|
@ -41,12 +42,10 @@ class Config(object):
|
||||||
_cfgimpl_owner = default_owner
|
_cfgimpl_owner = default_owner
|
||||||
_cfgimpl_toplevel = None
|
_cfgimpl_toplevel = None
|
||||||
|
|
||||||
def __init__(self, descr, parent=None, **overrides):
|
def __init__(self, descr, parent=None):
|
||||||
""" Configuration option management master class
|
""" Configuration option management master class
|
||||||
:param descr: describes the configuration schema
|
:param descr: describes the configuration schema
|
||||||
:type descr: an instance of ``option.OptionDescription``
|
:type descr: an instance of ``option.OptionDescription``
|
||||||
:param overrides: can be used to set different default values
|
|
||||||
(see method ``override``)
|
|
||||||
:param parent: is None if the ``Config`` is root parent Config otherwise
|
:param parent: is None if the ``Config`` is root parent Config otherwise
|
||||||
:type parent: ``Config``
|
:type parent: ``Config``
|
||||||
"""
|
"""
|
||||||
|
@ -61,7 +60,7 @@ class Config(object):
|
||||||
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
|
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
|
||||||
'`freeze()` allows us to carry out this calculation again if necessary'
|
'`freeze()` allows us to carry out this calculation again if necessary'
|
||||||
self._cfgimpl_frozen = self._cfgimpl_toplevel._cfgimpl_frozen
|
self._cfgimpl_frozen = self._cfgimpl_toplevel._cfgimpl_frozen
|
||||||
self._cfgimpl_build(overrides)
|
self._cfgimpl_build()
|
||||||
|
|
||||||
def _validate_duplicates(self, children):
|
def _validate_duplicates(self, children):
|
||||||
"""duplicates Option names in the schema
|
"""duplicates Option names in the schema
|
||||||
|
@ -75,11 +74,10 @@ class Config(object):
|
||||||
raise ConflictConfigError('duplicate option name: '
|
raise ConflictConfigError('duplicate option name: '
|
||||||
'{0}'.format(dup._name))
|
'{0}'.format(dup._name))
|
||||||
|
|
||||||
def _cfgimpl_build(self, overrides):
|
def _cfgimpl_build(self):
|
||||||
"""
|
"""
|
||||||
- builds the config object from the schema
|
- builds the config object from the schema
|
||||||
- settles various default values for options
|
- settles various default values for options
|
||||||
:param overrides: dict of options name:default values
|
|
||||||
"""
|
"""
|
||||||
self._validate_duplicates(self._cfgimpl_descr._children)
|
self._validate_duplicates(self._cfgimpl_descr._children)
|
||||||
for child in self._cfgimpl_descr._children:
|
for child in self._cfgimpl_descr._children:
|
||||||
|
@ -99,7 +97,7 @@ class Config(object):
|
||||||
elif isinstance(child, OptionDescription):
|
elif isinstance(child, OptionDescription):
|
||||||
self._validate_duplicates(child._children)
|
self._validate_duplicates(child._children)
|
||||||
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
||||||
self.override(overrides)
|
# self.override(overrides)
|
||||||
|
|
||||||
def cfgimpl_set_permissive(self, permissive):
|
def cfgimpl_set_permissive(self, permissive):
|
||||||
if not isinstance(permissive, list):
|
if not isinstance(permissive, list):
|
||||||
|
@ -126,14 +124,14 @@ class Config(object):
|
||||||
if child._name not in self._cfgimpl_values:
|
if child._name not in self._cfgimpl_values:
|
||||||
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
||||||
|
|
||||||
def override(self, overrides):
|
# def override(self, overrides):
|
||||||
"""
|
# """
|
||||||
overrides default values. This marks the overridden values as defaults.
|
# overrides default values. This marks the overridden values as defaults.
|
||||||
:param overrides: is a dictionary of path strings to values.
|
# :param overrides: is a dictionary of path strings to values.
|
||||||
"""
|
# """
|
||||||
for name, value in overrides.iteritems():
|
# for name, value in overrides.iteritems():
|
||||||
homeconfig, name = self._cfgimpl_get_home_by_path(name)
|
# homeconfig, name = self._cfgimpl_get_home_by_path(name)
|
||||||
homeconfig.setoption(name, value, 'default')
|
# homeconfig.setoption(name, value, 'default')
|
||||||
|
|
||||||
def cfgimpl_set_owner(self, owner):
|
def cfgimpl_set_owner(self, owner):
|
||||||
":param owner: sets the default value for owner at the Config level"
|
":param owner: sets the default value for owner at the Config level"
|
||||||
|
@ -369,35 +367,22 @@ class Config(object):
|
||||||
:type who: string
|
:type who: string
|
||||||
"""
|
"""
|
||||||
child = getattr(self._cfgimpl_descr, name)
|
child = getattr(self._cfgimpl_descr, name)
|
||||||
if who == None:
|
|
||||||
if child.is_multi():
|
|
||||||
newowner = [self._cfgimpl_owner for i in range(len(value))]
|
|
||||||
else:
|
|
||||||
newowner = self._cfgimpl_owner
|
|
||||||
else:
|
|
||||||
if type(child) != SymLinkOption:
|
|
||||||
if child.is_multi():
|
|
||||||
if type(value) != Multi:
|
|
||||||
if type(value) == list:
|
|
||||||
value = Multi(value, self, child)
|
|
||||||
else:
|
|
||||||
raise ConfigError("invalid value for option:"
|
|
||||||
" {0} that is set to multi".format(name))
|
|
||||||
newowner = [who for i in range(len(value))]
|
|
||||||
else:
|
|
||||||
newowner = who
|
|
||||||
if type(child) != SymLinkOption:
|
if type(child) != SymLinkOption:
|
||||||
#if child.has_callback() and who=='default':
|
if who == None:
|
||||||
# raise TypeError("trying to set a default value to an option "
|
who = self._cfgimpl_owner
|
||||||
# "which has a callback: {0}".format(name))
|
if child.is_multi():
|
||||||
|
if type(value) != Multi:
|
||||||
|
if type(value) == list:
|
||||||
|
value = Multi(value, self, child)
|
||||||
|
else:
|
||||||
|
raise ConfigError("invalid value for option:"
|
||||||
|
" {0} that is set to multi".format(name))
|
||||||
|
newowner = [who for i in range(len(value))]
|
||||||
|
else:
|
||||||
|
newowner = who
|
||||||
child.setoption(self, value, who)
|
child.setoption(self, value, who)
|
||||||
if (value is None and who != 'default' and not child.is_multi()):
|
if child.is_multi() and value == [] and who != 'default':
|
||||||
child.setowner(self, 'default')
|
child.setowner(self, Owner(who))
|
||||||
self._cfgimpl_values[name] = copy(child.getdefault())
|
|
||||||
elif (value == [] and who != 'default' and child.is_multi()):
|
|
||||||
child.setowner(self, ['default' for i in range(len(child.getdefault()))])
|
|
||||||
self._cfgimpl_values[name] = Multi(copy(child.getdefault()),
|
|
||||||
config=self, child=child)
|
|
||||||
else:
|
else:
|
||||||
child.setowner(self, newowner)
|
child.setowner(self, newowner)
|
||||||
else:
|
else:
|
||||||
|
@ -757,4 +742,3 @@ def mandatory_warnings(config):
|
||||||
except PropertiesOptionError:
|
except PropertiesOptionError:
|
||||||
pass
|
pass
|
||||||
config._cfgimpl_get_toplevel()._cfgimpl_mandatory = mandatory
|
config._cfgimpl_get_toplevel()._cfgimpl_mandatory = mandatory
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,19 @@ master~slave group, the name of the group and the name of the
|
||||||
master option are identical.
|
master option are identical.
|
||||||
"""
|
"""
|
||||||
group_types = ['default', 'family', 'group', 'master']
|
group_types = ['default', 'family', 'group', 'master']
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
# multi types
|
# multi types
|
||||||
|
|
||||||
|
class Owner(str):
|
||||||
|
"an owner just for a multi Option that have no value set"
|
||||||
|
# we need a string that cannot be iterable
|
||||||
|
def __iter__(self):
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return 0
|
||||||
|
|
||||||
class Multi(list):
|
class Multi(list):
|
||||||
"container that support items for the values of list (multi) options"
|
"container that support items for the values of list (multi) options"
|
||||||
def __init__(self, lst, config, child):
|
def __init__(self, lst, config, child):
|
||||||
|
@ -58,23 +69,16 @@ class Multi(list):
|
||||||
def append(self, value):
|
def append(self, value):
|
||||||
self.setoption(value)
|
self.setoption(value)
|
||||||
|
|
||||||
def setoption(self, value, key=None):
|
def setoption(self, value, key=None, who=None):
|
||||||
#owners = self.child.getowner(self.config)
|
if who is None:
|
||||||
# None is replaced by default_multi
|
|
||||||
if value == None:
|
|
||||||
defval = self.child.getdefault()
|
|
||||||
if key is not None and len(defval) > key:
|
|
||||||
value = defval[key]
|
|
||||||
else:
|
|
||||||
value = self.child.default_multi
|
|
||||||
who = 'default'
|
|
||||||
else:
|
|
||||||
who = self.config._cfgimpl_owner
|
who = self.config._cfgimpl_owner
|
||||||
if not self.child._validate(value):
|
if not self.child._validate(value):
|
||||||
raise ConfigError("invalid value {0} "
|
raise ConfigError("invalid value {0} "
|
||||||
"for option {1}".format(str(value), self.child._name))
|
"for option {1}".format(str(value), self.child._name))
|
||||||
oldvalue = list(self)
|
oldvalue = list(self)
|
||||||
oldowner = self.child.getowner(self.config)
|
oldowner = self.child.getowner(self.config)
|
||||||
|
if isinstance(oldowner, Owner):
|
||||||
|
oldowner = []
|
||||||
if key is None:
|
if key is None:
|
||||||
ret = super(Multi, self).append(value)
|
ret = super(Multi, self).append(value)
|
||||||
oldvalue.append(None)
|
oldvalue.append(None)
|
||||||
|
@ -105,6 +109,11 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
requires=None, mandatory=False, multi=False, callback=None,
|
requires=None, mandatory=False, multi=False, callback=None,
|
||||||
callback_params=None):
|
callback_params=None):
|
||||||
|
"""
|
||||||
|
:param default: ['bla', 'bla', 'bla']
|
||||||
|
:param default_multi: 'bla' (used in case of a reset to default only at
|
||||||
|
a given index)
|
||||||
|
"""
|
||||||
self._name = name
|
self._name = name
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self._requires = requires
|
self._requires = requires
|
||||||
|
@ -211,7 +220,7 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
"""
|
"""
|
||||||
name = self._name
|
name = self._name
|
||||||
if self.is_multi():
|
if self.is_multi():
|
||||||
if not type(owner) == list:
|
if not type(owner) == list and not isinstance(owner, Owner):
|
||||||
raise ConfigError("invalid owner for multi "
|
raise ConfigError("invalid owner for multi "
|
||||||
"option: {0}".format(name))
|
"option: {0}".format(name))
|
||||||
config._cfgimpl_value_owners[name] = owner
|
config._cfgimpl_value_owners[name] = owner
|
||||||
|
@ -220,6 +229,27 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
"config *must* be only the **parent** config (not the toplevel config)"
|
"config *must* be only the **parent** config (not the toplevel config)"
|
||||||
return config._cfgimpl_value_owners[self._name]
|
return config._cfgimpl_value_owners[self._name]
|
||||||
|
|
||||||
|
def reset(self, config, idx=None):
|
||||||
|
"""resets the default value and owner
|
||||||
|
:param idx: if not None, resets only the element at index idx
|
||||||
|
"""
|
||||||
|
if self.is_multi():
|
||||||
|
if idx is not None:
|
||||||
|
defval = self.getdefault()
|
||||||
|
# if the default is ['a', 'b', 'c']
|
||||||
|
if len(defval) > idx:
|
||||||
|
# and idx = 4 -> there is actually no such value in the default
|
||||||
|
value.setoption(default_multi, idx, who='default')
|
||||||
|
else:
|
||||||
|
# and idx = 2 -> there is a value in the default
|
||||||
|
value.setoption(defval[idx], idx, who='default')
|
||||||
|
else:
|
||||||
|
value = Multi(self.getdefault(), config, self)
|
||||||
|
config.setoption(self._name, value, 'default')
|
||||||
|
else:
|
||||||
|
value = self.getdefault()
|
||||||
|
config.setoption(self._name, value, 'default')
|
||||||
|
|
||||||
def is_default_owner(self, config, all_default=True, at_index=None):
|
def is_default_owner(self, config, all_default=True, at_index=None):
|
||||||
"""
|
"""
|
||||||
:param config: *must* be only the **parent** config
|
:param config: *must* be only the **parent** config
|
||||||
|
@ -274,29 +304,7 @@ class Option(HiddenBaseType, DisabledBaseType):
|
||||||
if config.is_frozen() and self.is_frozen():
|
if config.is_frozen() and self.is_frozen():
|
||||||
raise TypeError('cannot change the value to %s for '
|
raise TypeError('cannot change the value to %s for '
|
||||||
'option %s' % (str(value), name))
|
'option %s' % (str(value), name))
|
||||||
if who == "default":
|
|
||||||
# changes the default value (and therefore resets the previous value)
|
|
||||||
if self._validate(value):
|
|
||||||
self.default = value
|
|
||||||
else:
|
|
||||||
raise ConfigError("invalid value %s for option %s" % (value, name))
|
|
||||||
apply_requires(self, config)
|
apply_requires(self, config)
|
||||||
# FIXME put the validation for the multi somewhere else
|
|
||||||
# # it is a multi **and** it has requires
|
|
||||||
# if self.multi == True:
|
|
||||||
# if type(value) != list:
|
|
||||||
# raise TypeError("value {0} must be a list".format(value))
|
|
||||||
# if self._requires is not None:
|
|
||||||
# for reqname in self._requires:
|
|
||||||
# # FIXME : verify that the slaves are all multi
|
|
||||||
# #option = getattr(config._cfgimpl_descr, reqname)
|
|
||||||
# # if not option.multi == True:
|
|
||||||
# # raise ConflictConfigError("an option with requires "
|
|
||||||
# # "has to be a list type : {0}".format(name))
|
|
||||||
# if len(config._cfgimpl_values[reqname]) != len(value):
|
|
||||||
# raise ConflictConfigError("an option with requires "
|
|
||||||
# "has not the same length of the others "
|
|
||||||
# "in the group : {0}".format(reqname))
|
|
||||||
if type(config._cfgimpl_values[name]) == Multi:
|
if type(config._cfgimpl_values[name]) == Multi:
|
||||||
config._cfgimpl_previous_values[name] = list(config._cfgimpl_values[name])
|
config._cfgimpl_previous_values[name] = list(config._cfgimpl_values[name])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue