|
|
|
@ -10,7 +10,7 @@ from tiramisu.config import KernelConfig
|
|
|
|
|
from tiramisu.setting import groups, owners
|
|
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
|
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
|
|
|
|
|
undefined, Calculation, Params, ParamOption, ParamValue, ParamContext, calc_value
|
|
|
|
|
undefined, Calculation, Params, ParamOption, ParamValue, ParamContext, ParamIndex, calc_value
|
|
|
|
|
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
|
|
|
|
|
from tiramisu.i18n import _
|
|
|
|
|
from tiramisu.storage import list_sessions
|
|
|
|
@ -252,7 +252,7 @@ def test_freeze_and_has_callback():
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback(config_type):
|
|
|
|
|
def test_callback_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_val)
|
|
|
|
|
val2 = StrOption('val2', "")
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
@ -269,6 +269,20 @@ def test_callback(config_type):
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_val))
|
|
|
|
|
val2 = StrOption('val2', "")
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
cfg.option('val1').value.set('new-val')
|
|
|
|
|
assert cfg.option('val1').value.get() == 'new-val'
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_params_without_callback():
|
|
|
|
|
raises(ValueError, "StrOption('val2', '', callback_params=Params(ParamValue('yes')))")
|
|
|
|
|
|
|
|
|
@ -287,7 +301,7 @@ def test_param_option():
|
|
|
|
|
raises(AssertionError, "ParamOption(val1, 'str')")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_invalid():
|
|
|
|
|
def test_callback_invalid_legacy():
|
|
|
|
|
raises(AssertionError, 'val1 = StrOption("val1", "", callback="string")')
|
|
|
|
|
raises(AssertionError, 'val1 = StrOption("val1", "", callback=return_val, callback_params="string")')
|
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
@ -299,7 +313,7 @@ def test_callback_invalid():
|
|
|
|
|
raises(AssertionError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1,),)})")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context():
|
|
|
|
|
def test_callback_with_context_legacy():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
value = ParamValue('string')
|
|
|
|
|
params = Params((context,), {'value': value})
|
|
|
|
@ -309,7 +323,17 @@ def test_callback_with_context():
|
|
|
|
|
assert cfg.option('val1').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context_named():
|
|
|
|
|
def test_callback_with_context():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
value = ParamValue('string')
|
|
|
|
|
params = Params((context,), {'value': value})
|
|
|
|
|
val1 = StrOption("val1", "", Calculation(is_config, params))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context_named_legacy():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
params = Params(kwargs={'config': context})
|
|
|
|
|
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
|
|
|
|
@ -318,7 +342,16 @@ def test_callback_with_context_named():
|
|
|
|
|
assert cfg.option('val1').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_error(config_type):
|
|
|
|
|
def test_callback_with_context_named():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
params = Params(kwargs={'config': context})
|
|
|
|
|
val1 = StrOption("val1", "", Calculation(is_config, params))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_error_legacy(config_type):
|
|
|
|
|
val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')}))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
@ -326,7 +359,15 @@ def test_callback_with_error(config_type):
|
|
|
|
|
assert cfg.option('val1').value.get() == 'no'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context_value():
|
|
|
|
|
def test_callback_with_error(config_type):
|
|
|
|
|
val1 = StrOption("val1", "", Calculation(is_config, Params(ParamValue('string'), kwargs={'value': ParamValue('string')})))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'no'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context_value_legacy():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
params = Params((context,))
|
|
|
|
|
val1 = StrOption("val1", "")
|
|
|
|
@ -341,7 +382,22 @@ def test_callback_with_context_value():
|
|
|
|
|
assert cfg.option('val2').value.get() == 'no'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value(config_type):
|
|
|
|
|
def test_callback_with_context_value():
|
|
|
|
|
context = ParamContext()
|
|
|
|
|
params = Params((context,))
|
|
|
|
|
val1 = StrOption("val1", "")
|
|
|
|
|
val2 = StrOption("val2", "", Calculation(ret_from_config, params))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.option('val1').value.set('yes')
|
|
|
|
|
assert cfg.option('val1').value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'yes'
|
|
|
|
|
cfg.option('val1').value.set('no')
|
|
|
|
|
assert cfg.option('val1').value.get() == 'no'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'no'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
|
|
|
|
@ -366,7 +422,32 @@ def test_callback_value(config_type):
|
|
|
|
|
assert cfg.option('val5').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_tuple(config_type):
|
|
|
|
|
def test_callback_value(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))))
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)})))
|
|
|
|
|
val5 = StrOption('val5', "", Calculation(return_value, Params(ParamValue('yes'))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val4').value.get() == 'val'
|
|
|
|
|
cfg.option('val1').value.set('new-val')
|
|
|
|
|
assert cfg.option('val1').value.get() == 'new-val'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'new-val'
|
|
|
|
|
assert cfg.option('val4').value.get() == 'new-val'
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val3').value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val4').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val5').value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_tuple_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2))))
|
|
|
|
@ -385,7 +466,26 @@ def test_callback_value_tuple(config_type):
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val1.val2'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive2(config_type):
|
|
|
|
|
def test_callback_value_tuple(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_concat, Params((ParamOption(val1), ParamOption(val2)))))
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_concat, Params((ParamValue('yes'), ParamValue('no')))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val1'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val1.val2'
|
|
|
|
|
assert cfg.option('val4').value.get() == 'yes.no'
|
|
|
|
|
cfg.option('val1').value.set('new-val')
|
|
|
|
|
assert cfg.option('val3').value.get() == 'new-val.val2'
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val1.val2'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive2_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
|
|
|
|
@ -399,7 +499,21 @@ def test_callback_value_force_permissive2(config_type):
|
|
|
|
|
raises(ConfigError, "get_config(cfg, config_type)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive_kwargs():
|
|
|
|
|
def test_callback_value_force_permissive2(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1, True))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_only()
|
|
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
|
raises(ConfigError, "cfg.option('val2').value.get()")
|
|
|
|
|
cfg.option('val3').value.get() is None
|
|
|
|
|
else:
|
|
|
|
|
raises(ConfigError, "get_config(cfg, config_type)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive_kwargs_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(value=ParamOption(val1)))
|
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(value=ParamOption(val1, True)))
|
|
|
|
@ -410,7 +524,18 @@ def test_callback_value_force_permissive_kwargs():
|
|
|
|
|
cfg.option('val3').value.get() is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_symlink(config_type):
|
|
|
|
|
def test_callback_value_force_permissive_kwargs():
|
|
|
|
|
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(value=ParamOption(val1))))
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(value=ParamOption(val1, True))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_only()
|
|
|
|
|
raises(ConfigError, "cfg.option('val2').value.get()")
|
|
|
|
|
cfg.option('val3').value.get() is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_symlink_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
|
val2 = SymLinkOption('val2', val1)
|
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2)))
|
|
|
|
@ -429,7 +554,26 @@ def test_callback_symlink(config_type):
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list():
|
|
|
|
|
def test_callback_symlink(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
|
val2 = SymLinkOption('val2', val1)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val2))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val2').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val'
|
|
|
|
|
cfg.option('val1').value.set('new-val')
|
|
|
|
|
assert cfg.option('val1').value.get() == 'new-val'
|
|
|
|
|
assert cfg.option('val3').value.get() == 'new-val'
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
|
assert cfg.option('val3').value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_list)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
@ -437,7 +581,15 @@ def test_callback_list():
|
|
|
|
|
raises(ValueError, "cfg.option('val1').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list2():
|
|
|
|
|
def test_callback_list():
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_list))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(ValueError, "cfg.option('val1').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list2_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_list)
|
|
|
|
|
#val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]})
|
|
|
|
@ -449,7 +601,18 @@ def test_callback_list2():
|
|
|
|
|
raises(ValueError, "cfg.option('val2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi(config_type):
|
|
|
|
|
def test_callback_list2():
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_list))
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(ValueError, "cfg.option('val1').value.get()")
|
|
|
|
|
#cfg.val2
|
|
|
|
|
raises(ValueError, "cfg.option('val2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_val, multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
@ -464,11 +627,23 @@ def test_callback_multi(config_type):
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_value(config_type):
|
|
|
|
|
def test_callback_multi(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
cfg.option('val1').value.set(['new-val'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val']
|
|
|
|
|
cfg.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_value_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", ['val'], multi=True)
|
|
|
|
|
#val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
#val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes')))
|
|
|
|
|
#val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params={'': ((val1, False), 'yes')})
|
|
|
|
|
option = ParamOption(val1)
|
|
|
|
|
params1 = Params((option,))
|
|
|
|
|
value = ParamValue('yes')
|
|
|
|
@ -502,7 +677,42 @@ def test_callback_multi_value(config_type):
|
|
|
|
|
assert cfg.option('val2').value.get() == ['val', 'new']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list(config_type):
|
|
|
|
|
def test_callback_multi_value(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", ['val'], multi=True)
|
|
|
|
|
option = ParamOption(val1)
|
|
|
|
|
params1 = Params((option,))
|
|
|
|
|
value = ParamValue('yes')
|
|
|
|
|
params2 = Params((value,))
|
|
|
|
|
params3 = Params((option, value))
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, params1), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", [Calculation(return_value, params2)], multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_list2, params3), multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val2').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val4').value.get() == ['val', 'yes']
|
|
|
|
|
cfg.option('val1').value.set(['new-val'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val']
|
|
|
|
|
assert cfg.option('val2').value.get() == ['new-val']
|
|
|
|
|
assert cfg.option('val4').value.get() == ['new-val', 'yes']
|
|
|
|
|
cfg.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
|
assert cfg.option('val2').value.get() == ['new-val', 'new-val2']
|
|
|
|
|
assert cfg.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val2').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val3').value.get() == ['yes']
|
|
|
|
|
assert cfg.option('val4').value.get() == ['val', 'yes']
|
|
|
|
|
cfg.option('val2').value.set(['val', 'new'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val2').value.get() == ['val', 'new']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_list, multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
@ -517,7 +727,22 @@ def test_callback_multi_list(config_type):
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_extend(config_type):
|
|
|
|
|
def test_callback_multi_list(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_list), multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val', 'val']
|
|
|
|
|
cfg.option('val1').value.set(['new-val'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val']
|
|
|
|
|
cfg.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
|
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
|
assert cfg.option('val1').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_extend_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
@ -526,7 +751,16 @@ def test_callback_multi_list_extend(config_type):
|
|
|
|
|
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_callback(config_type):
|
|
|
|
|
def test_callback_multi_list_extend(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_list2, Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5'])))), multi=True)
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_callback_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_val)
|
|
|
|
|
interface1 = OptionDescription('val1', '', [val1])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
@ -538,7 +772,31 @@ def test_callback_multi_callback(config_type):
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader(config_type):
|
|
|
|
|
def test_callback_multi_callback(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
|
|
|
|
|
interface1 = OptionDescription('val1', '', [val1])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val']
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', undefined])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', None]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_callback_default(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", default_multi=Calculation(return_val), multi=True)
|
|
|
|
|
interface1 = OptionDescription('val1', '', [val1])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', undefined])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_val)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -553,7 +811,22 @@ def test_callback_leader_and_followers_leader(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_follower(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", default=[Calculation(return_val)], default_multi=Calculation(return_val), multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val']
|
|
|
|
|
cfg.option('val1.val1').value.set([undefined, undefined])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_follower_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -577,7 +850,31 @@ def test_callback_follower(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 3).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader2(config_type):
|
|
|
|
|
def test_callback_follower(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value3, Params(ParamValue(['string', 'new']), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set(['val'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val1'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val1', 'val2'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == None
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 3).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader2_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2')
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
|
|
|
|
@ -593,7 +890,23 @@ def test_callback_leader_and_followers_leader2(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory1(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader2(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2')
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set(['val'])
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory1_legacy(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
|
|
|
|
@ -623,7 +936,37 @@ def test_callback_leader_and_followers_leader_mandatory1(config_type):
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val4', 1).value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory2(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory1(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val))), properties=('mandatory',), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_index, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_index, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
|
|
|
|
cfg_ori = Config(maconfig)
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val']
|
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
|
cfg.send()
|
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set([undefined, 'val3'])
|
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
|
cfg.send()
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
|
# FIXME
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val3', 1).value.get()")
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val4', 1).value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory2_legacy(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val_ = StrOption('val_', "", default='val_')
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val), {'val2': ParamOption(val_)}), properties=('mandatory',))
|
|
|
|
@ -656,7 +999,40 @@ def test_callback_leader_and_followers_leader_mandatory2(config_type):
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory3(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory2(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val_ = StrOption('val_', "", default='val_')
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_index, Params(ParamOption(val), {'val2': ParamOption(val_)})), properties=('mandatory',), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_index, Params(ParamOption(val1), {'val2': ParamOption(val_), 'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_index, Params(ParamOption(val1), {'val2': ParamOption(val_), 'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
|
|
|
|
cfg_ori = Config(maconfig)
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
|
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
|
# FIXME
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val3', 2).value.get()")
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val4', 2).value.get()")
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory3_legacy(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val_ = StrOption('val_', "", default='val_')
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val), {'val': ParamOption(val_)}), properties=('mandatory',))
|
|
|
|
@ -686,7 +1062,37 @@ def test_callback_leader_and_followers_leader_mandatory3(config_type):
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory4(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory3(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val_ = StrOption('val_', "", default='val_')
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val), {'val': ParamOption(val_)})), properties=('mandatory',), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
|
|
|
|
cfg_ori = Config(maconfig)
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
|
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val3', 2).value.get() == 'val3'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
|
assert cfg.option('val1.val4', 2).value.get() == 'val3'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory4_legacy(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
|
|
|
|
@ -712,7 +1118,33 @@ def test_callback_leader_and_followers_leader_mandatory4(config_type):
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val3'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader3():
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory4(config_type):
|
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val))), properties=('mandatory',), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
|
|
|
|
cfg_ori = Config(maconfig)
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
#raises(IndexError, "cfg.option('val1.val3').value.get()")
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val']
|
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val3'])
|
|
|
|
|
cfg_ori.property.read_only()
|
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val3'
|
|
|
|
|
assert cfg.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val4', 1).value.get() == 'val3'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader3_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
|
|
|
|
@ -725,7 +1157,20 @@ def test_callback_leader_and_followers_leader3():
|
|
|
|
|
assert list(cfg.value.mandatory()) == ['val1.val1']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader4():
|
|
|
|
|
def test_callback_leader_and_followers_leader3():
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
# FIXME cfg = get_config(cfg, config_type)
|
|
|
|
|
assert list(cfg.value.mandatory()) == ['val1.val1']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader4_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
|
|
|
|
@ -740,6 +1185,21 @@ def test_callback_leader_and_followers_leader4():
|
|
|
|
|
assert list(cfg.value.mandatory()) == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader4():
|
|
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
# FIXME cfg = get_config(cfg, config_type)
|
|
|
|
|
cfg.property.add('expert')
|
|
|
|
|
cfg.permissive.set(frozenset(['expert']))
|
|
|
|
|
assert list(cfg.value.mandatory()) == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_leader_and_followers_leader_mandatory_transitive():
|
|
|
|
|
#default value
|
|
|
|
|
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
|
|
|
@ -783,7 +1243,7 @@ def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
|
|
|
|
|
assert list(cfg.value.mandatory()) == ["val1.val1"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_list(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_list_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -808,7 +1268,32 @@ def test_callback_leader_and_followers_leader_list(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_follower_list(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_list(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_list), multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
|
cfg.option('val1.val1').value.set(['val', 'val', undefined])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val', None]
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == None
|
|
|
|
|
cfg.option('val1.val1').value.reset()
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
|
cfg.option('val1.val1').value.pop(1)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_follower_list_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -825,7 +1310,24 @@ def test_callback_leader_and_followers_leader_follower_list(config_type):
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower(config_type):
|
|
|
|
|
def test_callback_leader_and_followers_leader_follower_list(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_list), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
|
# when "tiramisu-api", raise when set and not in get function
|
|
|
|
|
raises(ConfigError, "cfg.option('val1.val1').value.set(['val1'])")
|
|
|
|
|
else:
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1'])
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -866,7 +1368,48 @@ def test_callback_leader_and_followers_follower(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers():
|
|
|
|
|
def test_callback_leader_and_followers_follower(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.pop(2)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val2', 0).value.set('val2')
|
|
|
|
|
cfg.option('val1.val2', 1).value.set('val2')
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
@ -875,7 +1418,16 @@ def test_callback_leader_and_followers():
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_cal(config_type):
|
|
|
|
|
def test_callback_leader_and_followers():
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_cal_legacy(config_type):
|
|
|
|
|
val3 = StrOption('val3', "", multi=True)
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
|
|
|
@ -917,6 +1469,48 @@ def test_callback_leader_and_followers_follower_cal(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_cal(config_type):
|
|
|
|
|
val3 = StrOption('val3', "", multi=True)
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamOption(val3))), multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
#
|
|
|
|
|
assert cfg.option('val3').value.get() == []
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1'])
|
|
|
|
|
cfg.option('val3').value.set(['val1'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.reset()
|
|
|
|
|
cfg.option('val1.val2', 0).value.set('val')
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val3').value.set(['val1', 'val2'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
|
# len of follower is higher than leader's one
|
|
|
|
|
cfg.option('val1.val2', 0).value.set('val1')
|
|
|
|
|
cfg.option('val1.val2', 1).value.set('val2')
|
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
|
# when "tiramisu-api", raise when set and not in get function
|
|
|
|
|
raises(ConfigError, "cfg.option('val3').value.set(['val1'])")
|
|
|
|
|
else:
|
|
|
|
|
cfg.option('val3').value.set(['val1'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1']
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val3').value.set(['val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_disabled():
|
|
|
|
|
#properties must be transitive
|
|
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',))
|
|
|
|
@ -930,7 +1524,7 @@ def test_callback_leader_and_followers_leader_disabled():
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('val1.val2', 0).value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_callback_disabled():
|
|
|
|
|
def test_callback_leader_and_followers_leader_callback_disabled_legacy():
|
|
|
|
|
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
@ -946,6 +1540,22 @@ def test_callback_leader_and_followers_leader_callback_disabled():
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_callback_disabled():
|
|
|
|
|
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
|
|
|
|
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamOption(val0))), multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(ConfigError, "cfg.option('val1.val1').value.get()")
|
|
|
|
|
raises(ConfigError, "cfg.option('val1.val2').value.get()")
|
|
|
|
|
cfg.property.pop('disabled')
|
|
|
|
|
cfg.option('val1.val1').value.set([])
|
|
|
|
|
cfg.property.add('disabled')
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_disabled():
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
|
|
|
|
@ -972,7 +1582,7 @@ def test_callback_leader_and_followers_follower_disabled():
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'no1'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_callback_disabled():
|
|
|
|
|
def test_callback_leader_and_followers_follower_callback_disabled_legacy():
|
|
|
|
|
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
|
|
|
|
@ -991,7 +1601,26 @@ def test_callback_leader_and_followers_follower_callback_disabled():
|
|
|
|
|
cfg.option('val1.val1').value.pop(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_value():
|
|
|
|
|
def test_callback_leader_and_followers_follower_callback_disabled():
|
|
|
|
|
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val0))), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
cfg.option('val1.val1').value.set(['yes'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['yes']
|
|
|
|
|
cfg.property.pop('disabled')
|
|
|
|
|
cfg.option('val1.val2', 0).value.set('no')
|
|
|
|
|
cfg.option('val1.val1').value.set(['yes', 'yes1'])
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'no'
|
|
|
|
|
cfg.property.add('disabled')
|
|
|
|
|
cfg.option('val1.val1').value.pop(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_value_legacy():
|
|
|
|
|
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
@ -1062,13 +1691,84 @@ def test_callback_leader_and_followers_value():
|
|
|
|
|
assert cfg.option('val1.val3', 2).value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader():
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value)
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
|
|
|
|
|
def test_callback_leader_and_followers_value():
|
|
|
|
|
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
|
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))), multi=True)
|
|
|
|
|
val5 = StrOption('val5', "", Calculation(return_value, Params(ParamOption(val4))), multi=True)
|
|
|
|
|
val6 = StrOption('val6', "", Calculation(return_value, Params(ParamOption(val5))), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg.option('val4').value.get() == ['val10', 'val11']
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
#raises(LeadershipError, "cfg.val1.val1")
|
|
|
|
|
#raises(LeadershipError, "cfg.val1.val2")
|
|
|
|
|
#raises(LeadershipError, "cfg.val1.val3")
|
|
|
|
|
#raises(LeadershipError, "cfg.val1.val5")
|
|
|
|
|
#raises(LeadershipError, "cfg.val1.val6")
|
|
|
|
|
#
|
|
|
|
|
#default calculation has greater length
|
|
|
|
|
#raises(LeadershipError, "cfg.option('val1.val1').value.set(['val1']")
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'yes'
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val5', 0).value.get()")
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val5', 1).value.get()")
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val6', 0).value.get()")
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val6', 1).value.get()")
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val3'
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val1.val3', 2).value.get() == 'yes'
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val5', 2).value.get()")
|
|
|
|
|
raises(LeadershipError, "cfg.option('val1.val6', 2).value.get()")
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.pop(2)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'yes'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val2', 0).value.set('val2')
|
|
|
|
|
cfg.option('val1.val2', 1).value.set('val2')
|
|
|
|
|
cfg.option('val1.val3', 0).value.set('val2')
|
|
|
|
|
cfg.option('val1.val3', 1).value.set('val2')
|
|
|
|
|
cfg.option('val1.val5', 0).value.set('val2')
|
|
|
|
|
cfg.option('val1.val5', 1).value.set('val2')
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val3', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val3', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val5', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val5', 1).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val6', 0).value.get() == 'val2'
|
|
|
|
|
assert cfg.option('val1.val6', 1).value.get() == 'val2'
|
|
|
|
|
#
|
|
|
|
|
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'val3'
|
|
|
|
|
assert cfg.option('val1.val3', 2).value.get() == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_legacy():
|
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, multi=True)
|
|
|
|
|
val1 = StrOption('val1', "", callback=return_value, callback_params=Params(ParamOption(val2)), multi=True)
|
|
|
|
|
raises(ValueError, "Leadership('val1', '', [val1, val2])")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_different_type(config_type):
|
|
|
|
|
def test_callback_different_type_legacy(config_type):
|
|
|
|
|
val = IntOption('val', "", default=2)
|
|
|
|
|
val_ = IntOption('val_', "", default=3)
|
|
|
|
|
val1 = IntOption('val1', "", multi=True)
|
|
|
|
@ -1093,7 +1793,32 @@ def test_callback_different_type(config_type):
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden():
|
|
|
|
|
def test_callback_different_type(config_type):
|
|
|
|
|
val = IntOption('val', "", default=2)
|
|
|
|
|
val_ = IntOption('val_', "", default=3)
|
|
|
|
|
val1 = IntOption('val1', "", multi=True)
|
|
|
|
|
val2 = IntOption('val2', "", Calculation(return_calc, Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)})), multi=True)
|
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
|
cfg.option('val1.val1').value.set([1])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == [1]
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 6
|
|
|
|
|
cfg.option('val1.val1').value.set([1, 3])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == [1, 3]
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 6
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 8
|
|
|
|
|
cfg.option('val1.val1').value.set([1, 3, 5])
|
|
|
|
|
assert cfg.option('val1.val1').value.get() == [1, 3, 5]
|
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 6
|
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 8
|
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
@ -1106,7 +1831,20 @@ def test_callback_hidden():
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive():
|
|
|
|
|
def test_callback_hidden():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
|
|
|
|
|
# do not raise, forcepermissive
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
@ -1119,7 +1857,20 @@ def test_callback_hidden_permissive():
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive_callback():
|
|
|
|
|
def test_callback_hidden_permissive():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.permissive.set(frozenset(['hidden']))
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive_callback_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1, True)))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
@ -1131,7 +1882,19 @@ def test_callback_hidden_permissive_callback():
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled():
|
|
|
|
|
def test_callback_hidden_permissive_callback():
|
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1, True))))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1142,7 +1905,18 @@ def test_callback_two_disabled():
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled2():
|
|
|
|
|
def test_callback_two_disabled():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('disabled',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled2_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('hidden',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('hidden',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1155,7 +1929,20 @@ def test_callback_two_disabled2():
|
|
|
|
|
assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_invalid():
|
|
|
|
|
def test_callback_two_disabled2():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('hidden',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('hidden',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg.permissive.set(frozenset(['hidden']))
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_invalid_legacy():
|
|
|
|
|
opt1 = IntOption('opt1', '', 1)
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1168,7 +1955,20 @@ def test_callback_calculating_invalid():
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_disabled():
|
|
|
|
|
def test_callback_calculating_invalid():
|
|
|
|
|
opt1 = IntOption('opt1', '', 1)
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(ValueError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
cfg.unrestraint.option('od2.opt2').property.add('disabled')
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_disabled_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1179,7 +1979,18 @@ def test_callback_calculating_disabled():
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_mandatory():
|
|
|
|
|
def test_callback_calculating_disabled():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_mandatory_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1190,7 +2001,18 @@ def test_callback_calculating_mandatory():
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_mandatory_multi():
|
|
|
|
|
def test_callback_calculating_mandatory():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('mandatory',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_only()
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_mandatory_multi_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', multi=True, callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1201,7 +2023,18 @@ def test_callback_calculating_mandatory_multi():
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled_multi():
|
|
|
|
|
def test_callback_calculating_mandatory_multi():
|
|
|
|
|
opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('mandatory',), multi=True)
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_only()
|
|
|
|
|
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_two_disabled_multi_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',), multi=True)
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1212,7 +2045,18 @@ def test_callback_two_disabled_multi():
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params(config_type):
|
|
|
|
|
def test_callback_two_disabled_multi():
|
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('disabled',), multi=True)
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
@ -1223,7 +2067,18 @@ def test_callback_multi_list_params(config_type):
|
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params_key(config_type):
|
|
|
|
|
def test_callback_multi_list_params(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_list, Params(ParamOption(val1))), multi=True)
|
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params_key_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)}))
|
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
@ -1234,7 +2089,18 @@ def test_callback_multi_list_params_key(config_type):
|
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_leadership_callback_description(config_type):
|
|
|
|
|
def test_callback_multi_list_params_key(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_list, Params(kwargs={'value': ParamOption(val1)})), multi=True)
|
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_leadership_callback_description_legacy(config_type):
|
|
|
|
|
st1 = StrOption('st1', "", multi=True)
|
|
|
|
|
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
|
|
|
|
|
stm = Leadership('st1', '', [st1, st2])
|
|
|
|
@ -1253,7 +2119,26 @@ def test_leadership_callback_description(config_type):
|
|
|
|
|
assert cfg.option('od.st.st1.st2', 0).owner.get() == owner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_raise():
|
|
|
|
|
def test_leadership_callback_description(config_type):
|
|
|
|
|
st1 = StrOption('st1', "", multi=True)
|
|
|
|
|
st2 = StrOption('st2', "", Calculation(return_value, Params(ParamOption(st1))), multi=True)
|
|
|
|
|
stm = Leadership('st1', '', [st1, st2])
|
|
|
|
|
st = OptionDescription('st', '', [stm])
|
|
|
|
|
od = OptionDescription('od', '', [st])
|
|
|
|
|
od2 = OptionDescription('od', '', [od])
|
|
|
|
|
cfg = Config(od2)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
owner = cfg.owner.get()
|
|
|
|
|
assert cfg.option('od.st.st1.st1').value.get() == []
|
|
|
|
|
assert cfg.option('od.st.st1.st1').owner.isdefault()
|
|
|
|
|
##
|
|
|
|
|
cfg.option('od.st.st1.st1').value.set(['yes'])
|
|
|
|
|
cfg.option('od.st.st1.st2', 0).value.set('yes')
|
|
|
|
|
assert cfg.option('od.st.st1.st1').owner.get() == owner
|
|
|
|
|
assert cfg.option('od.st.st1.st2', 0).owner.get() == owner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_raise_legacy():
|
|
|
|
|
opt1 = BoolOption('opt1', 'Option 1', callback=return_raise)
|
|
|
|
|
opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror)
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
@ -1271,7 +2156,25 @@ def test_callback_raise():
|
|
|
|
|
assert '"Option 2"' in str(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_simple(config_type):
|
|
|
|
|
def test_callback_raise():
|
|
|
|
|
opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise))
|
|
|
|
|
opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror))
|
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
try:
|
|
|
|
|
cfg.option('od1.opt1').value.get()
|
|
|
|
|
except ConfigError as err:
|
|
|
|
|
assert '"Option 1"' in str(err)
|
|
|
|
|
try:
|
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
|
except ConfigError as err:
|
|
|
|
|
assert '"Option 2"' in str(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_simple_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1)))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2])
|
|
|
|
@ -1280,7 +2183,16 @@ def test_calc_value_simple(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_multi(config_type):
|
|
|
|
|
def test_calc_value_simple(config_type):
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1))))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_multi_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True)))
|
|
|
|
@ -1290,7 +2202,17 @@ def test_calc_value_multi(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_disabled():
|
|
|
|
|
def test_calc_value_multi(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True))), multi=True)
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_disabled_legacy():
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True), default=ParamValue('default_value')))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2])
|
|
|
|
@ -1301,7 +2223,18 @@ def test_calc_value_disabled():
|
|
|
|
|
assert cfg.value.dict() == {'val2': 'default_value'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_condition(config_type):
|
|
|
|
|
def test_calc_value_disabled():
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1, True), default=ParamValue('default_value'))))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
|
|
|
|
|
cfg.option('val1').property.add('disabled')
|
|
|
|
|
assert cfg.value.dict() == {'val2': 'default_value'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_condition_legacy(config_type):
|
|
|
|
|
boolean = BoolOption('boolean', '', True)
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True),
|
|
|
|
@ -1317,7 +2250,23 @@ def test_calc_value_condition(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_allow_none(config_type):
|
|
|
|
|
def test_calc_value_condition(config_type):
|
|
|
|
|
boolean = BoolOption('boolean', '', True)
|
|
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
|
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1, True),
|
|
|
|
|
default=ParamValue('default_value'),
|
|
|
|
|
condition=ParamOption(boolean),
|
|
|
|
|
expected=ParamValue(True))))
|
|
|
|
|
od = OptionDescription('root', '', [boolean, val1, val2])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'}
|
|
|
|
|
cfg.option('boolean').value.set(False)
|
|
|
|
|
assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_allow_none_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "")
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True)))
|
|
|
|
@ -1327,7 +2276,17 @@ def test_calc_value_allow_none(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_remove_duplicate(config_type):
|
|
|
|
|
def test_calc_value_allow_none(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "")
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True))), multi=True)
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_remove_duplicate_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val1')
|
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True)))
|
|
|
|
@ -1337,7 +2296,17 @@ def test_calc_value_remove_duplicate(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_join(config_type):
|
|
|
|
|
def test_calc_value_remove_duplicate(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val1')
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True))), multi=True)
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_join_legacy(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.')))
|
|
|
|
@ -1347,7 +2316,17 @@ def test_calc_value_join(config_type):
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_min():
|
|
|
|
|
def test_calc_value_join(config_type):
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.'))))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_min_legacy():
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", 'val3')
|
|
|
|
@ -1360,7 +2339,20 @@ def test_calc_value_min():
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_add(config_type):
|
|
|
|
|
def test_calc_value_min():
|
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
|
val3 = StrOption('val3', "", 'val3')
|
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3, True)), join=ParamValue('.'), min_args_len=ParamValue(3))))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3, val4])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg.property.read_write()
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
|
|
|
|
|
cfg.option('val3').property.add('disabled')
|
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_add_legacy(config_type):
|
|
|
|
|
val1 = IntOption('val1', "", 1)
|
|
|
|
|
val2 = IntOption('val2', "", 2)
|
|
|
|
|
val3 = IntOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add')))
|
|
|
|
@ -1368,3 +2360,12 @@ def test_calc_value_add(config_type):
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}
|
|
|
|
|
|
|
|
|
|
def test_calc_value_add(config_type):
|
|
|
|
|
val1 = IntOption('val1', "", 1)
|
|
|
|
|
val2 = IntOption('val2', "", 2)
|
|
|
|
|
val3 = IntOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add'))))
|
|
|
|
|
od = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
|
cfg = Config(od)
|
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
|
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}
|
|
|
|
|