2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
2019-09-01 09:41:53 +02:00
|
|
|
import warnings
|
2013-05-08 18:14:42 +02:00
|
|
|
|
2018-08-14 22:15:40 +02:00
|
|
|
from tiramisu import Config
|
|
|
|
from tiramisu.config import KernelConfig
|
2014-04-12 11:53:58 +02:00
|
|
|
from tiramisu.setting import groups, owners
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2019-02-23 19:06:23 +01:00
|
|
|
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
|
2019-12-24 15:24:20 +01:00
|
|
|
undefined, Calculation, Params, ParamOption, ParamValue, ParamIndex, calc_value, \
|
2021-03-06 19:23:35 +01:00
|
|
|
valid_ip_netmask, ParamSelfOption, ParamInformation, ParamSelfInformation
|
2019-02-23 19:06:23 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
|
2018-04-10 22:42:20 +02:00
|
|
|
from tiramisu.i18n import _
|
2023-04-15 16:12:35 +02:00
|
|
|
from .config import config_type, get_config
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def return_val():
|
2013-06-11 15:10:38 +02:00
|
|
|
return 'val'
|
|
|
|
|
|
|
|
|
2013-09-19 21:38:46 +02:00
|
|
|
def return_concat(*args):
|
|
|
|
return '.'.join(list(args))
|
|
|
|
|
|
|
|
|
|
|
|
def return_list(value=None):
|
2013-06-12 10:22:50 +02:00
|
|
|
return ['val', 'val']
|
|
|
|
|
|
|
|
|
2013-09-19 21:38:46 +02:00
|
|
|
def return_list2(*args):
|
2013-12-09 15:08:14 +01:00
|
|
|
l = []
|
|
|
|
for arg in args:
|
|
|
|
if isinstance(arg, list):
|
|
|
|
l.extend(arg)
|
|
|
|
else:
|
|
|
|
l.append(arg)
|
|
|
|
return l
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def return_value(value=None):
|
2013-06-12 10:22:50 +02:00
|
|
|
return value
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def return_async_value(value=None):
|
2020-10-03 14:29:15 +02:00
|
|
|
return value
|
|
|
|
|
|
|
|
|
2013-09-23 22:40:10 +02:00
|
|
|
def return_value2(*args, **kwargs):
|
|
|
|
value = list(args)
|
|
|
|
value.extend(kwargs.values())
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
def return_value3(value=None, index=None):
|
|
|
|
if index is not None and isinstance(value, list):
|
|
|
|
if len(value) > index:
|
|
|
|
return value[index]
|
|
|
|
return None
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def return_index(val1, val2=None, index=None, self=None):
|
|
|
|
if index is None:
|
|
|
|
return [val1, val2]
|
|
|
|
if index == 0:
|
|
|
|
return val1
|
|
|
|
if index == 1:
|
|
|
|
return val2
|
|
|
|
|
2013-12-09 15:08:14 +01:00
|
|
|
def return_calc(i, j, k):
|
|
|
|
return i + j + k
|
|
|
|
|
|
|
|
|
2014-03-26 19:44:49 +01:00
|
|
|
def is_config(config, **kwargs):
|
2018-08-14 22:15:40 +02:00
|
|
|
if isinstance(config, KernelConfig):
|
2014-03-26 19:44:49 +01:00
|
|
|
return 'yes'
|
2019-12-24 15:24:20 +01:00
|
|
|
return 'no'
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
2017-02-11 18:11:05 +01:00
|
|
|
def return_raise(*arg):
|
|
|
|
raise Exception('test')
|
|
|
|
|
|
|
|
|
|
|
|
def return_valueerror(*arg):
|
|
|
|
raise ValueError('test')
|
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def make_description_duplicates():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
## dummy 1
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
2019-09-01 09:41:53 +02:00
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
2013-05-08 18:14:42 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
2019-09-01 09:41:53 +02:00
|
|
|
default=False)
|
2013-05-08 18:14:42 +02:00
|
|
|
# dummy2 (same path)
|
|
|
|
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
|
|
|
# dummy3 (same name)
|
|
|
|
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
|
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop, gcdummy3])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_identical_paths():
|
2013-05-08 18:14:42 +02:00
|
|
|
"""If in the schema (the option description) there is something that
|
|
|
|
have the same name, an exection is raised
|
|
|
|
"""
|
2019-09-01 09:41:53 +02:00
|
|
|
with warnings.catch_warnings(record=True) as w:
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ConflictError):
|
2019-12-24 15:24:20 +01:00
|
|
|
make_description_duplicates()
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_hidden_if_in2(config_type):
|
2013-05-08 18:14:42 +02:00
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2019-09-01 09:41:53 +02:00
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(intoption),
|
|
|
|
'expected': ParamValue(1),
|
|
|
|
'default': ParamValue(None)}))
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc", properties=(hidden_property,))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('constraints', '', [stroption, intoption])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert not 'hidden' in cfg.option('str').property.get()
|
|
|
|
cfg.option('int').value.set(1)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('str').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('str').value.set('uvw')
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
assert 'hidden' in cfg_ori.unrestraint.option('str').property.get()
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2023-05-11 15:44:48 +02:00
|
|
|
def test_hidden_if_in3(config_type):
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(intoption),
|
|
|
|
'expected': ParamValue(1),
|
|
|
|
'default_0': ParamValue(None)}))
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc", properties=(hidden_property,))
|
|
|
|
od1 = OptionDescription('constraints', '', [stroption, intoption])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert not 'hidden' in cfg.option('str').property.get()
|
|
|
|
cfg.option('int').value.set(1)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('str').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('str').value.set('uvw')
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
assert 'hidden' in cfg_ori.unrestraint.option('str').property.get()
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_hidden_if_in_with_group(config_type):
|
2013-05-08 18:14:42 +02:00
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
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")
|
2019-09-01 09:41:53 +02:00
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(intoption),
|
|
|
|
'expected': ParamValue(1),
|
|
|
|
'default': ParamValue(None)}))
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(hidden_property,))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('constraints', '', [gcgroup, booloption,
|
2013-05-08 18:14:42 +02:00
|
|
|
objspaceoption, stroption, intoption])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert not 'hidden' in cfg_ori.option('str').property.get()
|
|
|
|
cfg.option('int').value.set(1)
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg_ori.option('gc.name').value.get()
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_disabled_with_group():
|
2013-05-08 18:14:42 +02:00
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
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")
|
2019-09-01 09:41:53 +02:00
|
|
|
disabled_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('disabled'),
|
|
|
|
kwargs={'condition': ParamOption(intoption),
|
|
|
|
'expected': ParamValue(1),
|
|
|
|
'default': ParamValue(None)}))
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(disabled_property,))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('constraints', '', [gcgroup, booloption,
|
2018-03-19 08:33:53 +01:00
|
|
|
objspaceoption, stroption, intoption])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
assert cfg.option('gc.name').value.get()
|
|
|
|
cfg.option('int').value.set(1)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('gc.name').value.get()
|
|
|
|
# assert not list_sessions()
|
2013-05-08 18:14:42 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
|
|
|
|
|
|
|
|
def make_description_callback():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy')
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
2019-09-01 09:41:53 +02:00
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(boolop),
|
|
|
|
'expected': ParamValue(True),
|
|
|
|
'default': ParamValue(None)}))
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=(hidden_property,))
|
2013-05-08 18:14:42 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2019-09-01 09:41:53 +02:00
|
|
|
properties=(hidden_property,))
|
2013-05-08 18:14:42 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_has_callback():
|
|
|
|
od1 = make_description_callback()
|
2013-05-08 18:14:42 +02:00
|
|
|
# here the owner is 'default'
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.option('bool').value.set(False)
|
|
|
|
# because dummy has a callback
|
|
|
|
cfg.property.add('freeze')
|
|
|
|
cfg.option('gc.dummy').property.add('frozen')
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('gc.dummy').value.set(True)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_and_has_callback():
|
|
|
|
od1 = make_description_callback()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.option('bool').value.set(False)
|
|
|
|
cfg.property.add('freeze')
|
|
|
|
cfg.option('gc.dummy').property.add('frozen')
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('gc.dummy').value.set(True)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_val))
|
|
|
|
val2 = StrOption('val2', "")
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
2023-05-11 15:44:48 +02:00
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
assert cfg.option('val1').option.defaultmulti() == None
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg.option('val1').value.reset()
|
|
|
|
assert cfg.option('val1').value.get() == 'val'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_params():
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
Params('str')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
Params(('str',))
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
Params(kwargs={'a': 'str'})
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_param_option():
|
2018-09-12 21:05:14 +02:00
|
|
|
val1 = StrOption('val1', "")
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ParamOption('str')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AssertionError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ParamOption(val1, 'str')
|
2014-03-26 19:44:49 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_with_error(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption("val1", "", Calculation(is_config, Params(ParamValue('string'), kwargs={'value': ParamValue('string')})))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val1').value.get() == 'no'
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_value(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_async_value(config_type):
|
2020-10-03 14:29:15 +02:00
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_async_value, Params(ParamOption(val1))))
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_async_value, Params(ParamValue('yes'))))
|
|
|
|
val4 = StrOption('val4', "", Calculation(return_async_value, Params(kwargs={'value': ParamOption(val1)})))
|
|
|
|
val5 = StrOption('val5', "", Calculation(return_async_value, Params(ParamValue('yes'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_information(config_type):
|
2020-10-03 14:29:15 +02:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamInformation('information', 'no_value'))))
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamInformation('information'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val1').value.get() == 'no_value'
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val2').value.get()
|
|
|
|
cfg.information.set('information', 'new_value')
|
|
|
|
assert cfg.option('val1').value.get() == 'new_value'
|
|
|
|
assert cfg.option('val2').value.get() == 'new_value'
|
|
|
|
cfg.information.set('information', 'new_value2')
|
|
|
|
assert cfg.option('val1').value.get() == 'new_value2'
|
|
|
|
assert cfg.option('val2').value.get() == 'new_value2'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_information2(config_type):
|
2021-03-06 19:23:35 +01:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamSelfInformation('information', 'no_value'))))
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamSelfInformation('information'))))
|
|
|
|
val2.impl_set_information('information', 'new_value')
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamSelfInformation('information'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val1').value.get() == 'no_value'
|
|
|
|
assert cfg.option('val2').value.get() == 'new_value'
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val3').value.get()
|
|
|
|
cfg.option('val2').information.set('information', 'new_value2')
|
|
|
|
assert cfg.option('val2').value.get() == 'new_value2'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_tuple(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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')))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive2(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
if config_type != 'tiramisu-api':
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val2').value.get()
|
|
|
|
cfg.option('val3').value.get() is None
|
|
|
|
else:
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
get_config(cfg, config_type)
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_value_force_permissive_kwargs():
|
2019-09-28 16:32:48 +02:00
|
|
|
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))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val2').value.get()
|
|
|
|
cfg.option('val3').value.get() is None
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_symlink(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
val2 = SymLinkOption('val2', val1)
|
|
|
|
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val2))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list():
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_list))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('val1').value.get()
|
|
|
|
assert cfg.option('val1').value.valid() is False
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_list2():
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_list))
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('val1').value.get()
|
|
|
|
assert cfg.option('val1').value.valid() is False
|
|
|
|
#cfg.val2
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('val2').value.get()
|
|
|
|
assert cfg.option('val2').value.valid() is False
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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').option.defaultmulti() == None
|
|
|
|
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']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_value(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list(config_type):
|
2019-12-08 09:09:48 +01:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_list), multi=True, properties=('notunique',))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_extend(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_list2, Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5'])))), multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_multi_callback(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
|
|
|
|
interface1 = OptionDescription('val1', '', [val1])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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]
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_callback_default(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", default_multi=Calculation(return_val), multi=True)
|
|
|
|
interface1 = OptionDescription('val1', '', [val1])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader(config_type):
|
2019-12-08 09:09:48 +01:00
|
|
|
val1 = StrOption('val1', "", default=[Calculation(return_val)], default_multi=Calculation(return_val), multi=True, properties=('notunique',))
|
2019-09-28 16:32:48 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_follower(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_value3, Params(ParamValue(['string', 'new']), {'index': ParamIndex()})), multi=True)
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader2(config_type):
|
2014-04-02 12:04:50 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2')
|
2019-10-27 11:09:15 +01:00
|
|
|
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)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory1(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val, interface1])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
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
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val3', 1).value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val4', 1).value.get()
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory2(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val, val_, interface1])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
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
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val3', 2).value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val4', 2).value.get()
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory3(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val, val_, interface1])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
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']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_mandatory4(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val, interface1])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader4():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
# FIXME cfg = get_config(cfg, config_type)
|
|
|
|
cfg.property.add('expert')
|
|
|
|
cfg.permissive.add('expert')
|
|
|
|
assert list(cfg.value.mandatory()) == []
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_consistency_leader_and_followers_leader_mandatory_transitive():
|
2016-03-18 19:55:41 +01:00
|
|
|
#default value
|
|
|
|
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
2019-10-27 11:09:15 +01:00
|
|
|
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'), validators=[Calculation(valid_ip_netmask, Params((ParamOption(val1), ParamSelfOption())))])
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
# FIXME cfg = get_config(cfg, config_type)
|
|
|
|
try:
|
|
|
|
cfg.option('val1.val2', 0).value.get()
|
|
|
|
except PropertiesOptionError as error:
|
|
|
|
assert str(error) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'val2', _('property'), '"disabled"'))
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert list(cfg.value.mandatory()) == []
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_list(config_type):
|
2019-12-08 09:09:48 +01:00
|
|
|
val1 = StrOption('val1', "", Calculation(return_list), multi=True, properties=('notunique',))
|
2019-09-28 16:32:48 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True)
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_follower_list(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_list), multi=True)
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val1.val1').value.set(['val1'])
|
|
|
|
else:
|
|
|
|
cfg.option('val1.val1').value.set(['val1'])
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('val1.val2', 0).value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_leader_and_followers_follower(config_type):
|
2014-04-02 12:04:50 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
2019-09-28 16:32:48 +02:00
|
|
|
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers():
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_leader_and_followers_follower_cal(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val3').value.set(['val1'])
|
|
|
|
else:
|
|
|
|
cfg.option('val3').value.set(['val1'])
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['val1']
|
|
|
|
with pytest.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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_disabled():
|
2014-04-12 11:53:58 +02:00
|
|
|
#properties must be transitive
|
2019-10-27 11:09:15 +01:00
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True)
|
2014-04-12 11:53:58 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True)
|
2019-10-27 11:09:15 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2], properties=('disabled',))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val1').value.get()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val1').value.set(['yes'])
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('val1.val2', 0).value.get()
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_leader_callback_disabled():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1, val0])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('val1.val1').value.get()
|
|
|
|
with pytest.raises(ConfigError):
|
2023-04-27 11:34:35 +02:00
|
|
|
cfg.option('val1.val2', 0).value.get()
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg.property.remove('disabled')
|
|
|
|
cfg.option('val1.val1').value.set([])
|
|
|
|
cfg.property.add('disabled')
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_disabled():
|
2014-04-12 11:53:58 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
|
2019-02-23 19:06:23 +01:00
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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.remove('disabled')
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
cfg.option('val1.val2', 0).value.set('no')
|
|
|
|
cfg.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
|
|
|
|
cfg.option('val1.val2', 2).value.set('no1')
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == 'no'
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == None
|
|
|
|
assert cfg.option('val1.val2', 2).value.get() == 'no1'
|
|
|
|
cfg.property.add('disabled')
|
|
|
|
cfg.option('val1.val1').value.pop(0)
|
|
|
|
assert cfg.option('val1.val1').value.get() == ['yes2', 'yes3']
|
|
|
|
cfg.property.remove('disabled')
|
|
|
|
assert cfg.option('val1.val2', 0).value.get() == None
|
|
|
|
assert cfg.option('val1.val2', 1).value.get() == 'no1'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_follower_callback_disabled():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1, val0])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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.remove('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)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_leader_and_followers_value():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.option('val4').value.get() == ['val10', 'val11']
|
|
|
|
assert cfg.option('val1.val1').value.get() == []
|
|
|
|
#with pytest.raises(LeadershipError):
|
|
|
|
# cfg.val1.val1")
|
|
|
|
#with pytest.raises(LeadershipError):
|
|
|
|
# cfg.val1.val2")
|
|
|
|
#with pytest.raises(LeadershipError):
|
|
|
|
# cfg.val1.val3")
|
|
|
|
#with pytest.raises(LeadershipError):
|
|
|
|
# cfg.val1.val5")
|
|
|
|
#with pytest.raises(LeadershipError):
|
|
|
|
# cfg.val1.val6")
|
|
|
|
#
|
|
|
|
#default calculation has greater length
|
|
|
|
#with pytest.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'
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('val1.val5', 0).value.get()
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('val1.val5', 1).value.get()
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('val1.val6', 0).value.get()
|
|
|
|
with pytest.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'
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('val1.val5', 2).value.get()
|
|
|
|
with pytest.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'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_different_type(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1, val, val_])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od1.opt1').value.get()
|
|
|
|
# do not raise, forcepermissive
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_hidden_permissive():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od1.opt1').value.get()
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_hidden_permissive_callback():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1, True))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od1.opt1').value.get()
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_two_disabled():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('disabled',))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_two_disabled2():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '', properties=('hidden',))
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('hidden',))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_calculating_invalid():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = IntOption('opt1', '', 1)
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
assert cfg.option('od2.opt2').value.valid() is False
|
|
|
|
cfg.unrestraint.option('od2.opt2').property.add('disabled')
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_unvalid_value(config_type):
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = BoolOption('val2', '', Calculation(return_value, Params(ParamOption(val1))), multi=True)
|
|
|
|
interface1 = Leadership('val1', '', [val1, val2])
|
|
|
|
od1 = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
cfg.option('val1.val1').value.set(['val'])
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('val1.val2', 0).value.get()
|
|
|
|
assert cfg.option('val1.val2', 0).value.valid() is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_unrestraint():
|
2021-03-08 06:39:40 +01:00
|
|
|
opt1 = IntOption('opt1', '', 1)
|
|
|
|
opt2 = IntOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('disabled',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
assert cfg.unrestraint.option('od2.opt2').value.get() == 1
|
|
|
|
# assert not list_sessions()
|
2021-03-08 06:39:40 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_calculating_disabled():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_calculating_mandatory():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
|
|
|
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('mandatory',))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_only()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_calculating_mandatory_multi():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_only()
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_two_disabled_multi():
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
cfg.property.read_write()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('od2.opt2').value.get()
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_multi_list_params(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
2019-12-08 09:09:48 +01:00
|
|
|
val2 = StrOption('val2', "", Calculation(return_list, Params(ParamOption(val1))), multi=True, properties=('notunique',))
|
2019-09-28 16:32:48 +02:00
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_callback_multi_list_params_key(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
2019-12-08 09:09:48 +01:00
|
|
|
val2 = StrOption('val2', "", Calculation(return_list, Params(kwargs={'value': ParamOption(val1)})), multi=True, properties=('notunique',))
|
2019-09-28 16:32:48 +02:00
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val2.val2').value.get() == ['val', 'val']
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_leadership_callback_description(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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])
|
2023-04-15 16:12:35 +02:00
|
|
|
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
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_raise():
|
2019-09-28 16:32:48 +02:00
|
|
|
opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise))
|
|
|
|
opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror))
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od3 = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(od3)
|
|
|
|
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)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_simple(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_multi(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True))), multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_disabled():
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', '', 'val1')
|
|
|
|
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1, True), default=ParamValue('default_value'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_condition(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [boolean, val1, val2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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'}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_calc_value_allow_none(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_remove_duplicate(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
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)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_remove_duplicate2(config_type):
|
2023-04-12 12:01:56 +02:00
|
|
|
val1 = StrOption('val1', "", ['val1', 'val1'], multi=True, properties=('notunique',))
|
|
|
|
val2 = StrOption('val2', "", ['val1', 'val1'], multi=True, properties=('notunique',))
|
|
|
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True), join=ParamValue('-'))), multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': ['val1', 'val1'], 'val2': ['val1', 'val1'], 'val3': ['val1-val1']}
|
|
|
|
# assert not list_sessions()
|
2023-04-12 12:01:56 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_join(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
2020-08-04 16:43:40 +02:00
|
|
|
val3 = StrOption('val3', "")
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3)), join=ParamValue('.'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None}
|
|
|
|
cfg.option('val3').value.set('val3')
|
|
|
|
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
|
|
|
|
# assert not list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_join_multi(config_type):
|
2022-01-09 20:36:04 +01:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1)), join=ParamValue('.'), multi=ParamValue(True))), multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': [], 'val4': []}
|
|
|
|
cfg.option('val1').value.set(['val1'])
|
|
|
|
assert cfg.value.dict() == {'val1': ['val1'], 'val4': ['val1']}
|
|
|
|
# assert not list_sessions()
|
2022-01-09 20:36:04 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_join_multi_value(config_type):
|
2022-01-09 20:36:04 +01:00
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True)
|
|
|
|
val2 = StrOption('val2', "", ['val2'], multi=True)
|
|
|
|
val3 = StrOption('val3', "", [None], multi=True)
|
|
|
|
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3)), join=ParamValue('.'), multi=ParamValue(True))), multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': ['val1'], 'val2': ['val2'], 'val3': [None], 'val4': []}
|
|
|
|
cfg.option('val3').value.set(['val3'])
|
|
|
|
assert cfg.value.dict() == {'val1': ['val1'], 'val2': ['val2'], 'val3': ['val3'], 'val4': ['val1.val2.val3']}
|
|
|
|
# assert not list_sessions()
|
2022-01-09 20:36:04 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_value_min():
|
2019-09-28 16:32:48 +02:00
|
|
|
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))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(od1)
|
|
|
|
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': ''}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
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'))))
|
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}
|
|
|
|
# assert not list_sessions()
|
2020-01-22 20:46:18 +01:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_calc_dependencies(config_type):
|
2019-09-28 16:32:48 +02:00
|
|
|
val1 = IntOption('val1', "", 1)
|
|
|
|
val2 = IntOption('val2', "", 2)
|
|
|
|
val3 = IntOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add'))))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [val1, val2, val3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
dep = cfg.option('val1').option.dependencies()
|
|
|
|
assert len(dep) == 1
|
|
|
|
assert dep[0].option.get() == val3
|
|
|
|
#
|
|
|
|
dep = cfg.option('val2').option.dependencies()
|
|
|
|
assert len(dep) == 1
|
|
|
|
assert dep[0].option.get() == val3
|
|
|
|
#
|
|
|
|
assert cfg.option('val3').option.dependencies() == []
|
2023-05-11 15:44:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback__kwargs_wrong(config_type):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
Params(kwargs='string')
|