fix: do not modify the default_multi attribute
This commit is contained in:
parent
3d8eb2c80d
commit
7ecec88881
4 changed files with 14 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetworkOption, NetmaskOption, \
|
||||
StrOption, OptionDescription, Leadership, Config, Calculation, ParamValue, calc_value, Params
|
||||
StrOption, OptionDescription, Leadership, Config, Calculation, ParamValue, ParamOption, calc_value, Params, submulti
|
||||
from tiramisu.error import LeadershipError, PropertiesOptionError, ConfigError
|
||||
|
||||
|
||||
|
|
@ -1105,3 +1105,13 @@ def test_follower_value_not_list():
|
|||
cfg.property.read_write()
|
||||
with pytest.raises(ValueError):
|
||||
cfg.option('od.interface0.ip_admin_eth0').value.set(None)
|
||||
|
||||
|
||||
def test_default_calc():
|
||||
var1 = StrOption('var1', "", multi=True, default=['leader1', 'leader2'], properties=frozenset({"mandatory",}))
|
||||
var2 = StrOption('var2', "", default_multi=[Calculation(calc_value, Params((ParamOption(var1))))], multi=submulti, properties=frozenset({"mandatory",}))
|
||||
leader = Leadership('interface0', '', [var1, var2])
|
||||
od1 = OptionDescription('od', '', [leader])
|
||||
od2 = OptionDescription('root', '', [od1])
|
||||
cfg = Config(od2)
|
||||
assert parse_od_get(cfg.value.get()) == {'od.interface0.var1': [{'od.interface0.var1': 'leader1', 'od.interface0.var2': ['leader1']}, {'od.interface0.var1': 'leader2', 'od.interface0.var2': ['leader2']}]}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ def get_calculated_value(
|
|||
has_calculation = True
|
||||
elif isinstance(value, list):
|
||||
# if value is a list, do subcalculation
|
||||
value = value.copy()
|
||||
for idx, val in enumerate(value):
|
||||
value[idx], _has_calculation = get_calculated_value(
|
||||
subconfig,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ def get_common_path(path1, path2):
|
|||
return common_path
|
||||
if common_path.endswith("."):
|
||||
return common_path[:-1]
|
||||
if "." in common_path:
|
||||
elif "." in common_path:
|
||||
return common_path.rsplit(".", 1)[0]
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class Leadership(OptionDescription):
|
|||
if not child.impl_is_multi():
|
||||
raise ValueError(
|
||||
_(
|
||||
"only multi option allowed in leadership {0} but option "
|
||||
"only multi option are allowed in leadership {0} but option "
|
||||
"{1} is not a multi"
|
||||
""
|
||||
).format(
|
||||
|
|
|
|||
Loading…
Reference in a new issue