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