feat: mandatory for a variable and replace suffix to identifier

This commit is contained in:
egarette@silique.fr 2024-10-22 10:16:48 +02:00
parent bbec439a5e
commit 7761758096
21 changed files with 404 additions and 358 deletions

View file

@ -13,9 +13,8 @@ import pytest
# submulti, undefined, owners, Params, ParamOption, Calculation # submulti, undefined, owners, Params, ParamOption, Calculation
from tiramisu import Config, DynOptionDescription, OptionDescription, Leadership, \ from tiramisu import Config, DynOptionDescription, OptionDescription, Leadership, \
StrOption, IntOption, ChoiceOption, SymLinkOption, \ StrOption, IntOption, ChoiceOption, SymLinkOption, \
Calculation, Params, ParamValue, ParamOption, ParamSelfOption, ParamInformation, ParamSelfInformation, ParamIndex, ParamSuffix, \ Calculation, Params, ParamValue, ParamOption, ParamSelfOption, ParamInformation, ParamSelfInformation, ParamIndex, ParamIdentifier, \
submulti, calc_value, owners submulti, calc_value, owners
from tiramisu.i18n import _
from tiramisu.option.baseoption import BaseOption from tiramisu.option.baseoption import BaseOption
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, LeadershipError from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, LeadershipError
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
@ -86,6 +85,9 @@ def build_variables(*,
base_name += 'dynamic_' base_name += 'dynamic_'
if hidden: if hidden:
base_name += 'hidden_' base_name += 'hidden_'
#str_mandatory_multi_hidden_information_deps
if base_name + 'information_deps' == 'str_mandatory_multi_hidden_information_deps':
print('blah', multi, properties, str1_5_informations)
str1 = StrOption(base_name + 'information_deps', str1 = StrOption(base_name + 'information_deps',
'', '',
multi=multi, multi=multi,
@ -211,10 +213,10 @@ def build_variables(*,
) )
) )
if dynoptiondescription: if dynoptiondescription:
default = Calculation(calc_value, Params(ParamSuffix())) default = Calculation(calc_value, Params(ParamIdentifier()))
if param_multi: if param_multi:
default = [default] default = [default]
variables.append(StrOption(base_name + 'calc_default_suffix', variables.append(StrOption(base_name + 'calc_default_identifier',
'', '',
default, default,
multi=multi, multi=multi,
@ -309,40 +311,43 @@ def build_root_variables(*,
follower_params['multi'] = submulti follower_params['multi'] = submulti
else: else:
follower_params['multi'] = True follower_params['multi'] = True
suffix = '' identifier = ''
if dynamic: if dynamic:
suffix += '_dynamic' identifier += '_dynamic'
lsuffix = suffix lidentifier = identifier
if hidden: if hidden:
lsuffix += '_hidden' lidentifier += '_hidden'
variables.append(Leadership('leadership' + lsuffix, '', [StrOption('leader_multi_deps' + lsuffix, variables.append(Leadership('leadership' + lidentifier, '', [StrOption('leader_multi_deps' + lidentifier,
'', '',
default=['l1', 'l2'], default=['l1', 'l2'],
multi=True, multi=True,
), ),
] + build_variables(**follower_params, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), ] + build_variables(**follower_params, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden),
)) ))
suffixes = StrOption('suffixes_multi_deps' + lsuffix, '', ['d1', 'd2'], multi=True) identifiers = StrOption('identifiers_multi_deps' + lidentifier, '', ['d1', 'd2'], multi=True)
variables.append(suffixes) variables.append(identifiers)
dynamic_name = 'dynamic_' dynamic_name = 'dynamic_'
if hidden: if hidden:
dynamic_name += 'hidden_' dynamic_name += 'hidden_'
variables.append(DynOptionDescription(dynamic_name, '', build_variables(**kwargs, dynoptiondescription=True, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), Calculation(return_var, Params(ParamOption(suffixes))))) variables.append(DynOptionDescription(dynamic_name, '', build_variables(**kwargs, dynoptiondescription=True, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), Calculation(return_var, Params(ParamOption(identifiers)))))
tree.reverse() tree.reverse()
for idx, t in enumerate(tree): for idx, t in enumerate(tree):
lsuffix = suffix lidentifier = identifier
variables.extend(parent_variables.pop(-1)) variables.extend(parent_variables.pop(-1))
if hidden and idx <= hidden_idx: if hidden and idx <= hidden_idx:
lsuffix = '_hidden' + suffix if t.startswith('h'):
lidentifier = '_self_hidden' + identifier
else:
lidentifier = '_hidden' + identifier
if t.startswith('h'): if t.startswith('h'):
t = t[1:] t = t[1:]
properties = frozenset(['hidden']) properties = frozenset(['hidden'])
else: else:
properties = frozenset() properties = frozenset()
if t == 'dod': if t == 'dod':
variables = [DynOptionDescription('tree_dynamic' + lsuffix, '', variables, Calculation(return_var, Params(ParamValue(['var1', 'var2']))), properties=properties)] variables = [DynOptionDescription('tree_dynamic' + lidentifier, '', variables, Calculation(return_var, Params(ParamValue(['var1', 'var2']))), properties=properties)]
else: else:
variables = [OptionDescription('tree' + lsuffix, '', variables, properties=properties)] variables = [OptionDescription('tree' + lidentifier, '', variables, properties=properties)]
od = OptionDescription('root', 'root', variables, informations={'cfg_key': 'cfg_info'}) od = OptionDescription('root', 'root', variables, informations={'cfg_key': 'cfg_info'})
return od return od
@ -445,21 +450,22 @@ def _test_option(option, without_index=False):
option.leadership() option.leadership()
assert option.isdynamic() == ('dynamic' in name) assert option.isdynamic() == ('dynamic' in name)
if option.isdynamic(): if option.isdynamic():
suffixes = [] identifiers = []
for path in option.path().split('.'): for path in option.path().split('.'):
if 'dynamicvar1' in path: if 'dynamicvar1' in path:
suffixes.append('var1') identifiers.append('var1')
if 'dynamicvar2' in path: if 'dynamicvar2' in path:
suffixes.append('var2') identifiers.append('var2')
if 'd1' in path: if 'd1' in path:
suffixes.append('d1') identifiers.append('d1')
if 'd2' in path: if 'd2' in path:
suffixes.append('d2') identifiers.append('d2')
assert option.suffixes() == suffixes assert option.identifiers() == identifiers
assert isinstance(option.description(), str) and option.description() == name and option.description(uncalculated=True) == '' assert isinstance(option.description(), str) and option.description() == name and option.description(uncalculated=True) == ''
assert isinstance(option.path(), str) and (option.path() == name or option.path().endswith(f'.{name}')) assert isinstance(option.path(), str) and (option.path() == name or option.path().endswith(f'.{name}'))
if '_deps' in name: if '_deps' in name:
assert option.has_dependency(False) assert option.has_dependency(False)
print(option.path())
assert option.dependencies() assert option.dependencies()
else: else:
assert not option.has_dependency(False) assert not option.has_dependency(False)
@ -467,11 +473,11 @@ def _test_option(option, without_index=False):
if option.isoptiondescription(): if option.isoptiondescription():
assert option.type() == 'optiondescription' assert option.type() == 'optiondescription'
elif 'index' in name: elif 'index' in name:
assert option.type() == _('integer') assert option.type() == 'integer'
elif 'choice' in name: elif 'choice' in name:
assert option.type() == _('choice') assert option.type() == 'choice'
else: else:
assert option.type() == _('string') assert option.type() == 'string'
# only option # only option
if option.isoptiondescription(): if option.isoptiondescription():
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
@ -485,9 +491,9 @@ def _test_option(option, without_index=False):
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
option.issymlinkoption() option.issymlinkoption()
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
option.default() option.value.default()
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
option.defaultmulti() option.value.defaultmulti()
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
option.pattern() option.pattern()
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
@ -514,14 +520,14 @@ def _test_option(option, without_index=False):
assert option.index() in [0, 1] assert option.index() in [0, 1]
else: else:
assert option.index() is None assert option.index() is None
if option.type() == _('integer'): if option.type() == 'integer':
assert option.pattern() == '^[0-9]+$' assert option.pattern() == '^[0-9]+$'
else: else:
assert not option.pattern() assert not option.pattern()
default = option.default() default = option.value.default(uncalculated=True)
if 'calc_default' in name: if 'calc_default' in name:
assert isinstance(default, Calculation) or (isinstance(default, list) and len(default) == 1 and isinstance(default[0], Calculation)) assert isinstance(default, Calculation) or (isinstance(default, list) and len(default) == 1 and isinstance(default[0], Calculation))
elif 'suffixes_multi' in name: elif 'identifiers_multi' in name:
assert default == ['d1', 'd2'] assert default == ['d1', 'd2']
elif 'leader_multi' in name: elif 'leader_multi' in name:
assert default == ['l1', 'l2'] assert default == ['l1', 'l2']
@ -530,9 +536,9 @@ def _test_option(option, without_index=False):
else: else:
assert default is None assert default is None
if option.issubmulti(): if option.issubmulti():
assert option.defaultmulti() == [] assert option.value.defaultmulti() == []
elif option.ismulti(): elif option.ismulti():
assert option.defaultmulti() is None assert option.value.defaultmulti() is None
def _test_information(cfg, option, without_index=False): def _test_information(cfg, option, without_index=False):
@ -764,8 +770,8 @@ def _get_value(name, option, unrestraint):
value = 'value' value = 'value'
if 'multi' in name: if 'multi' in name:
value = [value] value = [value]
elif 'calc_default_suffix' in name: elif 'calc_default_identifier' in name:
value = option.suffixes()[-1] value = option.identifiers()[-1]
if 'multi' in name: if 'multi' in name:
value = [value] value = [value]
elif 'calc_default_index' in name: elif 'calc_default_index' in name:
@ -776,7 +782,7 @@ def _get_value(name, option, unrestraint):
value = 'val' value = 'val'
if 'multi' in name: if 'multi' in name:
value = [value] value = [value]
elif 'suffixes_multi' in name: elif 'identifiers_multi' in name:
value = ['d1', 'd2'] value = ['d1', 'd2']
elif 'leader_multi_deps' in name: elif 'leader_multi_deps' in name:
value = ['l1', 'l2'] value = ['l1', 'l2']
@ -816,11 +822,11 @@ def _test_value_normal(name, cfg, option, unrestraint, without_index):
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
option.value.list() option.value.list()
else: else:
if option.type() == _('string'): if option.type() == 'string':
new_value = 'new_value' new_value = 'new_value'
new_value2 = 'new_value1' new_value2 = 'new_value1'
new_value3 = 'new_value2' new_value3 = 'new_value2'
elif option.type() == _('integer'): elif option.type() == 'integer':
new_value = 10 new_value = 10
new_value2 = 11 new_value2 = 11
new_value3 = 12 new_value3 = 12
@ -904,6 +910,7 @@ def _test_property(cfg, option, unrestraint=False, without_index=False):
if not unrestraint: if not unrestraint:
properties_only_raises.append('hidden') properties_only_raises.append('hidden')
properties_apply_requires.append('hidden') properties_apply_requires.append('hidden')
if 'self_hidden' in option.name():
properties_uncalculated.append('hidden') properties_uncalculated.append('hidden')
if name and 'mandatory' in name: if name and 'mandatory' in name:
properties.append('mandatory') properties.append('mandatory')

View file

@ -1,3 +0,0 @@
{
"options.unicode": null
}

View file

@ -32,6 +32,9 @@ def list_data(ext='.py'):
for filename in filenames: for filename in filenames:
# if filename.endswith(ext) and not filename.startswith('__'): # if filename.endswith(ext) and not filename.startswith('__'):
if filename.endswith(ext) and not filename.startswith('__') and not 'not_equal' in filename and not 'callback' in filename and not filename == 'unicode2_copy.py' and not filename == 'unicode2_multi_copy.py': if filename.endswith(ext) and not filename.startswith('__') and not 'not_equal' in filename and not 'callback' in filename and not filename == 'unicode2_copy.py' and not filename == 'unicode2_multi_copy.py':
# if 'leadership' in filename:
# print('FIXME')
# continue
ret.append(filename) ret.append(filename)
return ret return ret
@ -58,7 +61,7 @@ def load_config(filename,
form.extend(mod.get_form(add_extra_od)) form.extend(mod.get_form(add_extra_od))
config.property.read_write() config.property.read_write()
if root is None: if root is None:
values = loads(dumps(config.option.dict(remotable=remote, clearable=clearable, form=form))) values = loads(dumps(config.dict(remotable=remote, clearable=clearable, form=form)))
else: else:
values = loads(dumps(config.option(root).dict(remotable=remote, clearable=clearable, form=form))) values = loads(dumps(config.option(root).dict(remotable=remote, clearable=clearable, form=form)))
return values return values
@ -380,11 +383,12 @@ def test_updates(filename_mod):
if dico_ori is None: if dico_ori is None:
if clearable == 'minimum' and remote == 'minimum': if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.dict'), 'w') as fh: with open(join(datadir, modulepath + '.dict'), 'w') as fh:
dump(config.value.dict(), fh, indent=2) pouet
dump(config.value.get(), fh, indent=2)
else: else:
assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename_mod) assert config.value.get() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename_mod)
if root is None: if root is None:
suboption = config.option suboption = config
else: else:
suboption = config.option(root) suboption = config.option(root)
if with_model: if with_model:

View file

@ -201,7 +201,7 @@ def test_deref_symlink():
def test_deref_dyn(): def test_deref_dyn():
a = StrOption('a', '', ['val1', 'val2'], multi=True) a = StrOption('a', '', ['val1', 'val2'], multi=True)
b = StrOption('b', '') b = StrOption('b', '')
dod = DynOptionDescription('dod', '', [b], suffixes=Calculation(funcname, Params((ParamOption(a),)))) dod = DynOptionDescription('dod', '', [b], identifiers=Calculation(funcname, Params((ParamOption(a),))))
o = OptionDescription('od', '', [dod, a]) o = OptionDescription('od', '', [dod, a])
cfg = Config(o) cfg = Config(o)
w = weakref.ref(a) w = weakref.ref(a)

View file

@ -11,45 +11,47 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
OptionDescription, DynOptionDescription, submulti, Leadership, \ OptionDescription, DynOptionDescription, submulti, Leadership, \
Config, \ Config, \
Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, ParamSelfInformation, ParamInformation, \ Params, ParamOption, ParamValue, ParamIdentifier, ParamSelfOption, ParamDynOption, ParamIndex, ParamSelfInformation, ParamInformation, \
Calculation, calc_value Calculation, calc_value
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError, ValueOptionError from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError, ValueOptionError
def display_name(kls, subconfig) -> str: def display_name(kls, subconfig, with_quote=False) -> str:
"""Replace the Tiramisu display_name function to display path + description""" """Replace the Tiramisu display_name function to display path + description"""
doc = kls._get_information(subconfig, "doc", None) doc = kls._get_information(subconfig, "doc", None)
comment = f" ({doc})" if doc and doc != subconfig.path.rsplit('.', 1)[-1] else "" comment = f" ({doc})" if doc and doc != subconfig.path.rsplit('.', 1)[-1] else ""
if with_quote:
return f'"{subconfig.path}"{comment}'
return f"{subconfig.path}{comment}" return f"{subconfig.path}{comment}"
class ConvertDynOptionDescription(DynOptionDescription): class ConvertDynOptionDescription(DynOptionDescription):
def convert_suffix_to_path(self, suffix): def convert_identifier_to_path(self, identifier):
# remove dot with is illegal # remove dot with is illegal
return suffix.replace('.', '') return identifier.replace('.', '')
def return_true(value, param=None, suffix=None): def return_true(value, param=None, identifier=None):
if value == 'val' and param in [None, 'yes']: if value == 'val' and param in [None, 'yes']:
return return
raise ValueError('no value') raise ValueError('no value')
def return_dynval(value='val', suffix=None): def return_dynval(value='val', identifier=None):
return value return value
def return_list2(suffix): def return_list2(identifier):
return [str(suffix), 'val2'] return [str(identifier), 'val2']
def return_list(val=None, suffix=None): def return_list(val=None, identifier=None):
if val: if val:
return val return val
return ['val1', 'val2'] return ['val1', 'val2']
def return_list_dot(val=None, suffix=None): def return_list_dot(val=None, identifier=None):
return ['val.1', 'val.2'] return ['val.1', 'val.2']
@ -71,7 +73,7 @@ def return_str(*args, **kwargs):
def test_build_dyndescription(): def test_build_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None} assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None}
@ -82,23 +84,39 @@ def test_build_dyndescription():
# assert not list_sessions() # assert not list_sessions()
def test_dyndescription_suffixes(): def test_dyndescription_identifiers():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None} assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None}
assert cfg.option('dodval1').suffixes() == ['val1'] assert cfg.option('dodval1').identifiers() == ['val1']
assert cfg.option('dodval1.st').suffixes() == ['val1'] assert cfg.option('dodval1.st').identifiers() == ['val1']
assert cfg.option('dodval1').suffixes(only_self=True) == ['val1', 'val2'] assert cfg.option('dodval1').identifiers(only_self=True) == ['val1', 'val2']
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
cfg.option('dodval1.st').suffixes(only_self=True) cfg.option('dodval1.st').identifiers(only_self=True)
# assert not list_sessions()
def test_dyndescription_identifiers_2():
st1 = StrOption('st', '')
od = OptionDescription('od', '', [st1])
dod = DynOptionDescription('dod', '', [od], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dodval1.od.st': None, 'dodval2.od.st': None}
assert cfg.option('dodval1').identifiers() == ['val1']
assert cfg.option('dodval1.od').identifiers() == ['val1']
assert cfg.option('dodval1.od.st').identifiers() == ['val1']
assert cfg.option('dodval1').identifiers(only_self=True) == ['val1', 'val2']
with pytest.raises(ConfigError):
cfg.option('dodval1.od').identifiers(only_self=True)
# assert not list_sessions() # assert not list_sessions()
def test_build_dyndescription_with_int(): def test_build_dyndescription_with_int():
int1 = IntOption('int', '', default=Calculation(calc_value, Params(ParamSuffix()))) int1 = IntOption('int', '', default=Calculation(calc_value, Params(ParamIdentifier())))
dod = DynOptionDescription('dod', '', [int1], suffixes=Calculation(return_list, Params(ParamValue([1, 2])))) dod = DynOptionDescription('dod', '', [int1], identifiers=Calculation(return_list, Params(ParamValue([1, 2]))))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dod1.int': 1, 'dod2.int': 2} assert parse_od_get(cfg.value.get()) == {'dod1.int': 1, 'dod2.int': 2}
@ -106,8 +124,8 @@ def test_build_dyndescription_with_int():
def test_build_dyndescription_with_dot(): def test_build_dyndescription_with_dot():
st1 = StrOption('st', '', default=Calculation(calc_value, Params(ParamSuffix()))) st1 = StrOption('st', '', default=Calculation(calc_value, Params(ParamIdentifier())))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list_dot)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list_dot))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dodval_1.st': 'val.1', 'dodval_2.st': 'val.2'} assert parse_od_get(cfg.value.get()) == {'dodval_1.st': 'val.1', 'dodval_2.st': 'val.2'}
@ -116,7 +134,7 @@ def test_build_dyndescription_with_dot():
def test_build_dyndescription_raise(): def test_build_dyndescription_raise():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_raise)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_raise))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
@ -126,7 +144,7 @@ def test_build_dyndescription_raise():
def test_build_dyndescription_not_list(): def test_build_dyndescription_not_list():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_str)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_str))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -136,7 +154,7 @@ def test_build_dyndescription_not_list():
def test_subpath_dyndescription(): def test_subpath_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -146,7 +164,7 @@ def test_subpath_dyndescription():
def test_list_dyndescription(): def test_list_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -157,7 +175,7 @@ def test_list_dyndescription():
def test_unknown_dyndescription(): def test_unknown_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -174,7 +192,7 @@ def test_unknown_dyndescription():
def test_getdoc_dyndescription(): def test_getdoc_dyndescription():
st1 = StrOption('st', 'doc1') st1 = StrOption('st', 'doc1')
dod = DynOptionDescription('dod', 'doc2', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', 'doc2', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -193,7 +211,7 @@ def test_getdoc_dyndescription():
def test_dyndescription_path(): def test_dyndescription_path():
st1 = StrOption('st', 'doc1') st1 = StrOption('st', 'doc1')
dod = DynOptionDescription('dod', 'doc2', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', 'doc2', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -207,7 +225,7 @@ def test_dyndescription_path():
def test_mod_dyndescription(): def test_mod_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -234,7 +252,7 @@ def test_mod_dyndescription():
def test_del_dyndescription(): def test_del_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -250,7 +268,7 @@ def test_del_dyndescription():
def test_multi_dyndescription(): def test_multi_dyndescription():
st = StrOption('st', '', multi=True) st = StrOption('st', '', multi=True)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -278,7 +296,7 @@ def test_multi_dyndescription():
def test_prop_dyndescription(): def test_prop_dyndescription():
st = StrOption('st', '', properties=('test',)) st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -301,7 +319,7 @@ def test_prop_dyndescription():
def test_prop_dyndescription_force_store_value(): def test_prop_dyndescription_force_store_value():
st = StrOption('st', '', properties=('force_store_value',)) st = StrOption('st', '', properties=('force_store_value',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -312,8 +330,8 @@ def test_prop_dyndescription_force_store_value():
def test_prop_dyndescription_force_store_value_calculation_prefix(): def test_prop_dyndescription_force_store_value_calculation_prefix():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True) lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) st = StrOption('st', '', Calculation(return_list, Params(ParamIdentifier())) , properties=('force_store_value',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))))
od = OptionDescription('od', '', [dod, lst]) od = OptionDescription('od', '', [dod, lst])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -333,7 +351,7 @@ def test_prop_dyndescription_force_store_value_calculation_prefix():
def test_callback_dyndescription(): def test_callback_dyndescription():
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -358,7 +376,7 @@ def test_callback_dyndescription():
def test_callback_dyndescription_outside_wrong_param(): def test_callback_dyndescription_outside_wrong_param():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True) lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st)))) out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st))))
od = OptionDescription('od', '', [dod, out]) od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst]) od2 = OptionDescription('od', '', [od, lst])
@ -371,7 +389,7 @@ def test_callback_dyndescription_outside_wrong_param():
def test_callback_dyndescription_outside1(): def test_callback_dyndescription_outside1():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True) lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1'])))) out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1']))))
od = OptionDescription('od', '', [dod, out]) od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst]) od2 = OptionDescription('od', '', [od, lst])
@ -392,7 +410,7 @@ def test_callback_dyndescription_outside2():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True) lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
out = StrOption('out', '') out = StrOption('out', '')
st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(out)))) st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(out))))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))))
od = OptionDescription('od', '', [dod, out]) od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst]) od2 = OptionDescription('od', '', [od, lst])
cfg = Config(od2) cfg = Config(od2)
@ -402,9 +420,34 @@ def test_callback_dyndescription_outside2():
# assert not list_sessions() # assert not list_sessions()
def test_callback_dyndescription_outside3():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', 'val1')
dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))), properties=('hidden',))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1']))))
od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst])
cfg = Config(od2)
cfg.property.read_write()
assert parse_od_get(cfg.value.get()) == {'od.out': 'val1', 'lst': ['val1', 'val2']}
def test_callback_dyndescription_subdyn():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', 'val1')
dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst))))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1', None]))), multi=True, properties=('notunique',))
dod2 = DynOptionDescription('dod2', '', [dod, out], identifiers=Calculation(return_list, Params(ParamOption(lst))))
od = OptionDescription('od', '', [dod2])
od2 = OptionDescription('od', '', [od, lst])
cfg = Config(od2)
cfg.property.read_write()
assert parse_od_get(cfg.value.get()) == {'od.dod2val1.dodval1.st': 'val1', 'od.dod2val1.dodval2.st': 'val1', 'od.dod2val1.out': ['val1', 'val1'], 'od.dod2val2.dodval1.st': 'val1', 'od.dod2val2.dodval2.st': 'val1', 'od.dod2val2.out': ['val1', 'val1'], 'lst': ['val1', 'val2']}
def test_callback_list_dyndescription(): def test_callback_list_dyndescription():
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -423,7 +466,7 @@ def test_callback_list_dyndescription():
def test_mandatory_dyndescription(): def test_mandatory_dyndescription():
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -449,7 +492,7 @@ def test_mandatory_dyndescription():
def test_build_dyndescription_context(): def test_build_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
cfg = Config(od1) cfg = Config(od1)
assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'val1': ['val1', 'val2']} assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'val1': ['val1', 'val2']}
@ -459,7 +502,7 @@ def test_build_dyndescription_context():
def test_subpath_dyndescription_context(): def test_subpath_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -470,7 +513,7 @@ def test_subpath_dyndescription_context():
def test_list_dyndescription_context(): def test_list_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -484,7 +527,7 @@ def test_list_dyndescription_context():
def test_mod_dyndescription_context(): def test_mod_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -509,7 +552,7 @@ def test_mod_dyndescription_context():
def test_del_dyndescription_context(): def test_del_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -526,7 +569,7 @@ def test_del_dyndescription_context():
def test_multi_dyndescription_context(): def test_multi_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', multi=True, properties=('notunique',)) st = StrOption('st', '', multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -555,7 +598,7 @@ def test_multi_dyndescription_context():
def test_prop_dyndescription_context(): def test_prop_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('test',)) st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -573,7 +616,7 @@ def test_prop_dyndescription_context():
def test_callback_dyndescription_context(): def test_callback_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -598,7 +641,7 @@ def test_callback_dyndescription_context():
def test_mandatory_dyndescription_context(): def test_mandatory_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -624,7 +667,7 @@ def test_mandatory_dyndescription_context():
def test_increase_dyndescription_context(): def test_increase_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -643,7 +686,7 @@ def test_increase_dyndescription_context():
def test_decrease_dyndescription_context(): def test_decrease_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -680,13 +723,13 @@ def test_dyndescription_root():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,)) st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [boolean, st1], identifiers=Calculation(return_list))
with pytest.raises(ConfigError): with pytest.raises(ConfigError):
cfg = Config(dod) cfg = Config(dod)
# assert not list_sessions() # assert not list_sessions()
def test_dyndescription_disable_suffix_root(): def test_dyndescription_disable_identifier_root():
boolean = BoolOption('boolean', '', True) boolean = BoolOption('boolean', '', True)
disabled_property = Calculation(calc_value, disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'), Params(ParamValue('disabled'),
@ -695,7 +738,7 @@ def test_dyndescription_disable_suffix_root():
'default': ParamValue(None)})) 'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od1 = OptionDescription('root', 'root', [boolean, val, dod]) od1 = OptionDescription('root', 'root', [boolean, val, dod])
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
@ -706,7 +749,7 @@ def test_dyndescription_disable_suffix_root():
# assert not list_sessions() # assert not list_sessions()
def test_dyndescription_disable_suffix_root_2(): def test_dyndescription_disable_identifier_root_2():
boolean = BoolOption('boolean', '', False) boolean = BoolOption('boolean', '', False)
disabled_property = Calculation(calc_value, disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'), Params(ParamValue('disabled'),
@ -715,7 +758,7 @@ def test_dyndescription_disable_suffix_root_2():
'default': ParamValue(None)})) 'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od1 = OptionDescription('root', 'root', [boolean, val, dod]) od1 = OptionDescription('root', 'root', [boolean, val, dod])
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
@ -726,7 +769,7 @@ def test_dyndescription_disable_suffix_root_2():
# assert not list_sessions() # assert not list_sessions()
def test_dyndescription_disable_suffix(): def test_dyndescription_disable_identifier():
boolean = BoolOption('boolean', '', True) boolean = BoolOption('boolean', '', True)
disabled_property = Calculation(calc_value, disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'), Params(ParamValue('disabled'),
@ -735,7 +778,7 @@ def test_dyndescription_disable_suffix():
'default': ParamValue(None)})) 'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od = OptionDescription('root', 'root', [boolean, val, dod]) od = OptionDescription('root', 'root', [boolean, val, dod])
od1 = OptionDescription('root', 'root', [od]) od1 = OptionDescription('root', 'root', [od])
cfg = Config(od1) cfg = Config(od1)
@ -755,7 +798,7 @@ def test_requires_dyndescription():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,)) st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean]) od2 = OptionDescription('od', '', [od1, boolean])
cfg = Config(od2) cfg = Config(od2)
@ -811,7 +854,7 @@ def test_requires_dyndescription_boolean():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,)) st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean1, boolean]) od2 = OptionDescription('od', '', [od, boolean1, boolean])
cfg = Config(od2) cfg = Config(od2)
@ -844,7 +887,7 @@ def test_requires_dyndescription_in_dyn():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,)) st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [boolean, st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -870,8 +913,8 @@ def test_requires_dyndescription_in_dyn():
# assert not list_sessions() # assert not list_sessions()
def calc_value_not_same(param, condition, expected, default, suffix): def calc_value_not_same(param, condition, expected, default, identifier):
if suffix == 'val1': if identifier == 'val1':
index = 0 index = 0
else: else:
index = 1 index = 1
@ -885,10 +928,10 @@ def test_requires_dyndescription_in_dyn_not_same():
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None), 'default': ParamValue(None),
'suffix': ParamSuffix()})) 'identifier': ParamIdentifier()}))
st = StrOption('st', '', properties=(disabled_property,)) st = StrOption('st', '', properties=(disabled_property,))
dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) dod1 = DynOptionDescription('dod1', '', [boolean], identifiers=Calculation(return_list))
dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) dod2 = DynOptionDescription('dod2', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod1, dod2]) od = OptionDescription('od', '', [dod1, dod2])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -922,7 +965,7 @@ def test_requires_dyndescription2():
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list), properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list), properties=(disabled_property,))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean]) od2 = OptionDescription('od', '', [od1, boolean])
cfg = Config(od2) cfg = Config(od2)
@ -967,7 +1010,7 @@ def test_requires_dyndescription2():
def test_validator_dyndescription(): def test_validator_dyndescription():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', validators=[Calculation(return_true, Params((ParamSelfOption(), ParamValue('yes'))))], default='val') st = StrOption('st', '', validators=[Calculation(return_true, Params((ParamSelfOption(), ParamValue('yes'))))], default='val')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -981,7 +1024,7 @@ def test_validator_dyndescription():
def test_makedict_dyndescription_context(): def test_makedict_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -993,7 +1036,7 @@ def test_makedict_dyndescription_context():
#def test_find_dyndescription_context(): #def test_find_dyndescription_context():
# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) # val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
# st = StrOption('st', '') # st = StrOption('st', '')
# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) # dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
# od = OptionDescription('od', '', [dod, val1]) # od = OptionDescription('od', '', [dod, val1])
# od2 = OptionDescription('od', '', [od]) # od2 = OptionDescription('od', '', [od])
# cfg = Config(od2) # cfg = Config(od2)
@ -1015,7 +1058,7 @@ def test_makedict_dyndescription_context():
def test_information_dyndescription_context(): def test_information_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', informations={'testst': 'val2'}) st = StrOption('st', '', informations={'testst': 'val2'})
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list), informations={'testod': 'val1'}) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list), informations={'testod': 'val1'})
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -1049,7 +1092,7 @@ def test_all_dyndescription():
dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1, dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1,
boo, intr, floa, uni, port, broad, boo, intr, floa, uni, port, broad,
domain, email, url, username, domain, email, url, username,
filename], suffixes=Calculation(return_list)) filename], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert cfg.option('dodval1.st').value.get() is None assert cfg.option('dodval1.st').value.get() is None
@ -1128,7 +1171,7 @@ def test_leadership_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1188,7 +1231,7 @@ def test_leadership_dyndescription_force_store_value_leader():
st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1)))) st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1))))
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) val1 = StrOption('val1', '', multi=True, default=['val1', 'val2'])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [val1, st]) od = OptionDescription('od', '', [val1, st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1221,7 +1264,7 @@ def test_leadership_dyndescription_force_store_value():
st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1)))) st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1))))
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) val1 = StrOption('val1', '', multi=True, default=['val1', 'val2'])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [val1, st]) od = OptionDescription('od', '', [val1, st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1253,7 +1296,7 @@ def test_leadership_default_multi_dyndescription1():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1280,7 +1323,7 @@ def test_leadership_dyndescription_param():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1339,7 +1382,7 @@ def test_leadership_default_multi_dyndescription2():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1421,7 +1464,7 @@ def test_leadership_dyndescription_param_leader():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1433,7 +1476,7 @@ def test_leadership_default_multi_dyndescription3():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -1461,7 +1504,7 @@ def test_leadership_dyndescription_param_follower():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2)))) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list, Params(ParamOption(val2))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1473,7 +1516,7 @@ def test_leadership_default_multi_dyndescription_sub():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1498,7 +1541,7 @@ def test_leadership_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti) st2 = StrOption('st2', "", multi=submulti)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) std = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [std]) od1 = OptionDescription('od', '', [std])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -1531,7 +1574,7 @@ def test_leadership_callback_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st1 = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [st1]) od1 = OptionDescription('od', '', [st1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -1593,7 +1636,7 @@ def test_leadership_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1610,7 +1653,7 @@ def test_leadership_callback_nomulti_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) stt = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1, v11]) od2 = OptionDescription('od', '', [od1, v11])
cfg = Config(od2) cfg = Config(od2)
@ -1626,7 +1669,7 @@ def test_leadership_callback_samegroup_dyndescription():
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
stm = Leadership('st1', '', [st1, st2, st3]) stm = Leadership('st1', '', [st1, st2, st3])
stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) stt = DynOptionDescription('st', '', [stm], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -1655,7 +1698,7 @@ def test_leadership_callback_samegroup_dyndescription():
def test_invalid_conflict_dyndescription(): def test_invalid_conflict_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
dodinvalid = StrOption('dodinvalid', '') dodinvalid = StrOption('dodinvalid', '')
dod, dodinvalid dod, dodinvalid
with pytest.raises(ConflictError): with pytest.raises(ConflictError):
@ -1668,7 +1711,7 @@ def test_leadership_default_multi_dyndescription4():
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
od1 = OptionDescription('od1', '', [stm]) od1 = OptionDescription('od1', '', [stm])
st = DynOptionDescription('st', '', [od1], suffixes=Calculation(return_list)) st = DynOptionDescription('st', '', [od1], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -1698,8 +1741,8 @@ def test_leadership_default_multi_dyndescription4():
def test_subdynod_dyndescription_root(): def test_subdynod_dyndescription_root():
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b']))))
dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list))
st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a']))))
# FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
od1 = OptionDescription('od', '', [dod, st3]) #, st4]) od1 = OptionDescription('od', '', [dod, st3]) #, st4])
@ -1764,8 +1807,8 @@ def test_subdynod_dyndescription_root():
def test_subdynod_dyndescription(): def test_subdynod_dyndescription():
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b']))))
dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a']))))
od = OptionDescription('od', '', [od1, st3]) #, st4]) od = OptionDescription('od', '', [od1, st3]) #, st4])
@ -1830,8 +1873,8 @@ def test_subdynod_dyndescription():
def test_subdynod_dyndescription_2(): def test_subdynod_dyndescription_2():
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
st1 = StrOption('st1', '', default=['a', 'b'], multi=True) st1 = StrOption('st1', '', default=['a', 'b'], multi=True)
dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamOption(st1))))
dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [dod1, st1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a']))))
od = OptionDescription('od', '', [od1, st3]) #, st4]) od = OptionDescription('od', '', [od1, st3]) #, st4])
@ -1868,8 +1911,8 @@ def test_subdynod_dyndescription_leadership():
st1 = StrOption('st1', '', multi=True) st1 = StrOption('st1', '', multi=True)
st2 = StrOption('st2', '', multi=True) st2 = StrOption('st2', '', multi=True)
stm = Leadership('stm', '', [st1, st2]) stm = Leadership('stm', '', [st1, st2])
dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod1 = DynOptionDescription('dod1', '', [stm], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b']))))
dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, ['val1', 'a']))), multi=True) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, ['val1', 'a']))), multi=True)
# FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
@ -1916,7 +1959,7 @@ def test_dyndescription_symlink():
st = StrOption('st', '') st = StrOption('st', '')
st2 = SymLinkOption('st2', st) st2 = SymLinkOption('st2', st)
# with pytest.raises(ConfigError): # with pytest.raises(ConfigError):
dod = DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st, st2], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
cfg = Config(od) cfg = Config(od)
assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval1.st2': None, 'dodval2.st': None, 'dodval2.st2': None} assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval1.st2': None, 'dodval2.st': None, 'dodval2.st2': None}
@ -1927,10 +1970,10 @@ def test_dyndescription_symlink():
def test_dyndescription_symlink_not_same(): def test_dyndescription_symlink_not_same():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
st2 = SymLinkOption('st2', st) st2 = SymLinkOption('st2', st)
# with pytest.raises(ConfigError): # with pytest.raises(ConfigError):
dod2 = DynOptionDescription('sdod', '', [st2], suffixes=Calculation(return_list)) dod2 = DynOptionDescription('sdod', '', [st2], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod, dod2]) od = OptionDescription('od', '', [dod, dod2])
cfg = Config(od) cfg = Config(od)
assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'sdodval1.st2': [None, None], 'sdodval2.st2': [None, None]} assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'sdodval1.st2': [None, None], 'sdodval2.st2': [None, None]}
@ -1942,7 +1985,7 @@ def test_dyndescription_symlink_not_same():
def test_dyndescription_symlink_outside(): def test_dyndescription_symlink_outside():
st = StrOption('st', '') st = StrOption('st', '')
# with pytest.raises(ConfigError): # with pytest.raises(ConfigError):
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
st2 = SymLinkOption('st2', st) st2 = SymLinkOption('st2', st)
od = OptionDescription('od', '', [dod, st2]) od = OptionDescription('od', '', [dod, st2])
cfg = Config(od) cfg = Config(od)
@ -1956,7 +1999,7 @@ def test_dyndescription_symlink_inside():
st = StrOption('st', '') st = StrOption('st', '')
st2 = SymLinkOption('st2', st) st2 = SymLinkOption('st2', st)
# with pytest.raises(ConfigError): # with pytest.raises(ConfigError):
dod = DynOptionDescription('dod', '', [st2], suffixes=Calculation(return_list)) dod = DynOptionDescription('dod', '', [st2], identifiers=Calculation(return_list))
od = OptionDescription('od', '', [dod, st]) od = OptionDescription('od', '', [dod, st])
cfg = Config(od) cfg = Config(od)
assert parse_od_get(cfg.value.get()) == {'dodval1.st2': None, 'dodval2.st2': None, 'st': None} assert parse_od_get(cfg.value.get()) == {'dodval1.st2': None, 'dodval2.st2': None, 'st': None}
@ -1975,7 +2018,7 @@ def test_nocallback_dyndescription():
def test_invalid_samevalue_dyndescription(): def test_invalid_samevalue_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_same_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_same_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -1985,7 +2028,7 @@ def test_invalid_samevalue_dyndescription():
def test_invalid_name_dyndescription(): def test_invalid_name_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_wrong_list)) dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_wrong_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -1997,7 +2040,7 @@ def test_leadership_dyndescription_convert():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) st = ConvertDynOptionDescription('st', '', [stm], identifiers=Calculation(return_list_dot))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od1 = OptionDescription('od', '', [od]) od1 = OptionDescription('od', '', [od])
cfg = Config(od1) cfg = Config(od1)
@ -2057,7 +2100,7 @@ def test_leadership_callback_samegroup_dyndescription_convert():
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
stm = Leadership('st1', '', [st1, st2, st3]) stm = Leadership('st1', '', [st1, st2, st3])
stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) stt = ConvertDynOptionDescription('st', '', [stm], identifiers=Calculation(return_list_dot))
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
cfg = Config(od2) cfg = Config(od2)
@ -2088,7 +2131,7 @@ def test_dyn_with_leader_hidden_in_config():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',)) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',))
dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list))
od1 = OptionDescription('root', '', [dyn]) od1 = OptionDescription('root', '', [dyn])
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
@ -2110,7 +2153,7 @@ def test_dyn_with_leader_hidden_in_config2():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list))
od1 = OptionDescription('root', '', [dyn]) od1 = OptionDescription('root', '', [dyn])
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
@ -2135,7 +2178,7 @@ def test_dyn_leadership_requires():
'index': ParamIndex()})) 'index': ParamIndex()}))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,)) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list))
od1 = OptionDescription('toto', '', [dyn]) od1 = OptionDescription('toto', '', [dyn])
cfg = Config(od1) cfg = Config(od1)
cfg.property.read_write() cfg.property.read_write()
@ -2175,7 +2218,7 @@ def test_dyn_leadership_mandatory():
hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname')
choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A")
leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))}))
dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", identifiers=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"}))
od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn])
cfg = Config(od1) cfg = Config(od1)
assert cfg.value.mandatory() == [] assert cfg.value.mandatory() == []
@ -2184,8 +2227,8 @@ def test_dyn_leadership_mandatory():
def test_dyn_symlink(): def test_dyn_symlink():
remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True)
remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamIdentifier())))
dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) dyn_remote = DynOptionDescription("remote_", "Account for ", identifiers=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip])
name = SymLinkOption("name", opt=remote_ip) name = SymLinkOption("name", opt=remote_ip)
od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name])
cfg = Config(od1) cfg = Config(od1)
@ -2198,8 +2241,8 @@ def test_dyn_symlink():
def test_dyn_callback_with_not_dyn(): def test_dyn_callback_with_not_dyn():
remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True)
remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamIdentifier())))
dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) dyn_remote = DynOptionDescription("remote_", "Account for ", identifiers=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip])
names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True) names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True)
od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names])
cfg = Config(od1) cfg = Config(od1)
@ -2217,7 +2260,7 @@ def test_dyn_link_subdyn():
password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',))
user = OptionDescription(name="user", doc="user", children=[name, password2]) user = OptionDescription(name="user", doc="user", children=[name, password2])
sub = OptionDescription(name="sub", doc="sub", children=[user]) sub = OptionDescription(name="sub", doc="sub", children=[user])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub])
socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2279,7 +2322,7 @@ def test_dyn_link_subdyn_2():
name = StrOption(name="name", doc="name", properties=('mandatory',)) name = StrOption(name="name", doc="name", properties=('mandatory',))
user = OptionDescription(name="user", doc="user", children=[name, password2]) user = OptionDescription(name="user", doc="user", children=[name, password2])
sub = OptionDescription(name="sub", doc="sub", children=[user]) sub = OptionDescription(name="sub", doc="sub", children=[user])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub])
socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2342,10 +2385,10 @@ def test_dyn_link_subdyn_twice():
login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',))
password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',))
database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2])
databases = OptionDescription(name="databases", doc="database", children=[password, user_database]) databases = OptionDescription(name="databases", doc="database", children=[password, user_database])
schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"]) schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"])
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases])
socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2517,11 +2560,11 @@ def test_dyn_link_subdyn_tree():
login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',))
password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',))
user_names = StrOption(name="users", doc="users", multi=True, default=["user1"]) user_names = StrOption(name="users", doc="users", multi=True, default=["user1"])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2])
database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"]) database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"])
databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database]) databases = DynOptionDescription(name="db_", doc="database", identifiers=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database])
schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"])
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases])
socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2595,9 +2638,9 @@ def test_dyn_link_subdyn_same_variable():
login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',))
password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',))
schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2])
databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) databases = DynOptionDescription(name="db_", doc="database", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database])
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases])
socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2696,9 +2739,9 @@ def test_dyn_link_subdyn_disabled():
'default': ParamValue(None)})) 'default': ParamValue(None)}))
password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,)) password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,))
schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"])
user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) user_database = DynOptionDescription(name="user_database_", doc="user database", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2])
databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) databases = DynOptionDescription(name="db_", doc="database", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database])
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases])
socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root) cfg = Config(root)
@ -2757,8 +2800,8 @@ def test_option_dynoption_display_name():
password = StrOption(name="password", doc="password") password = StrOption(name="password", doc="password")
schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"])
user_database = OptionDescription(name="user_database", doc="user database", children=[password]) user_database = OptionDescription(name="user_database", doc="user database", children=[password])
databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[user_database]) databases = DynOptionDescription(name="db_", doc="database", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[user_database])
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases])
socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names])
root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle])
cfg = Config(root, display_name=display_name) cfg = Config(root, display_name=display_name)
@ -2768,7 +2811,7 @@ def test_option_dynoption_display_name():
def test_option_dynoption_param_information(): def test_option_dynoption_param_information():
info1 = StrOption("info1", '', Calculation(calc_value, Params(ParamSelfInformation('key'))), informations={'key': 'value'}) info1 = StrOption("info1", '', Calculation(calc_value, Params(ParamSelfInformation('key'))), informations={'key': 'value'})
info2 = StrOption("info2", '', Calculation(calc_value, Params(ParamInformation('key', option=info1)))) info2 = StrOption("info2", '', Calculation(calc_value, Params(ParamInformation('key', option=info1))))
schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params(ParamValue(['1', '2']))), children=[info1, info2]) schema = DynOptionDescription(name="schema_", doc="schema_", identifiers=Calculation(calc_value, Params(ParamValue(['1', '2']))), children=[info1, info2])
root = OptionDescription(name="baseoption", doc="baseoption", children=[schema]) root = OptionDescription(name="baseoption", doc="baseoption", children=[schema])
cfg = Config(root, display_name=display_name) cfg = Config(root, display_name=display_name)
assert parse_od_get(cfg.value.get()) == {'schema_1.info1': 'value', 'schema_1.info2': 'value', 'schema_2.info1': 'value', 'schema_2.info2': 'value'} assert parse_od_get(cfg.value.get()) == {'schema_1.info1': 'value', 'schema_1.info2': 'value', 'schema_2.info1': 'value', 'schema_2.info2': 'value'}
@ -2777,10 +2820,10 @@ def test_option_dynoption_param_information():
def test_callback_list_dyndescription_information(): def test_callback_list_dyndescription_information():
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamInformation('suffix')))) dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamInformation('identifier'))))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od], informations={'suffix': ['ival1', 'ival2']}) od2 = OptionDescription('od', '', [od], informations={'identifier': ['ival1', 'ival2']})
cfg = Config(od2) cfg = Config(od2)
owner = cfg.owner.get() owner = cfg.owner.get()
assert cfg.option('od.dodival1.st').value.get() == ['ival1', 'val2'] assert cfg.option('od.dodival1.st').value.get() == ['ival1', 'val2']
@ -2792,16 +2835,16 @@ def test_callback_list_dyndescription_information():
assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2']
assert cfg.option('od.dodival1.st').owner.get() == owner assert cfg.option('od.dodival1.st').owner.get() == owner
assert cfg.option('od.dodival2.st').owner.isdefault() assert cfg.option('od.dodival2.st').owner.isdefault()
cfg.information.set('suffix', ['ival3']) cfg.information.set('identifier', ['ival3'])
assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2'] assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2']
# assert not list_sessions() # assert not list_sessions()
def test_callback_list_dyndescription_information_not_list(): def test_callback_list_dyndescription_information_not_list():
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=["sval1", Calculation(return_dynval, Params(ParamInformation('suffix')))]) dod = DynOptionDescription('dod', '', [st], identifiers=["sval1", Calculation(return_dynval, Params(ParamInformation('identifier')))])
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od], informations={'suffix': 'ival2'}) od2 = OptionDescription('od', '', [od], informations={'identifier': 'ival2'})
cfg = Config(od2) cfg = Config(od2)
owner = cfg.owner.get() owner = cfg.owner.get()
assert cfg.option('od.dodsval1.st').value.get() == ['sval1', 'val2'] assert cfg.option('od.dodsval1.st').value.get() == ['sval1', 'val2']
@ -2813,6 +2856,6 @@ def test_callback_list_dyndescription_information_not_list():
assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2']
assert cfg.option('od.dodsval1.st').owner.get() == owner assert cfg.option('od.dodsval1.st').owner.get() == owner
assert cfg.option('od.dodival2.st').owner.isdefault() assert cfg.option('od.dodival2.st').owner.isdefault()
cfg.information.set('suffix', 'ival3') cfg.information.set('identifier', 'ival3')
assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2'] assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2']
# assert not list_sessions() # assert not list_sessions()

View file

@ -681,7 +681,7 @@ def test_mandatory_od_disabled():
# assert not list_sessions() # assert not list_sessions()
def return_list(val=None, suffix=None): def return_list(val=None, identifier=None):
if val: if val:
return val return val
else: else:
@ -690,7 +690,7 @@ def return_list(val=None, suffix=None):
#def test_mandatory_dyndescription(): #def test_mandatory_dyndescription():
# st = StrOption('st', '', properties=('mandatory',)) # st = StrOption('st', '', properties=('mandatory',))
# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) # dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list))
# od = OptionDescription('od', '', [dod]) # od = OptionDescription('od', '', [dod])
# od2 = OptionDescription('od', '', [od]) # od2 = OptionDescription('od', '', [od])
# cfg = Config(od2) # cfg = Config(od2)
@ -701,7 +701,7 @@ def return_list(val=None, suffix=None):
#def test_mandatory_dyndescription_context(): #def test_mandatory_dyndescription_context():
# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) # val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
# st = StrOption('st', '', properties=('mandatory',)) # st = StrOption('st', '', properties=('mandatory',))
# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1)))) # dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(val1))))
# od = OptionDescription('od', '', [dod, val1]) # od = OptionDescription('od', '', [dod, val1])
# od2 = OptionDescription('od', '', [od]) # od2 = OptionDescription('od', '', [od])
# cfg = Config(od2) # cfg = Config(od2)

View file

@ -20,7 +20,7 @@ def a_func():
return None return None
def display_name(*args): def display_name(*args, with_quote=False):
return 'display_name' return 'display_name'

View file

@ -945,7 +945,7 @@ def test_consistency_leader_and_followers_leader_mandatory_transitive():
try: try:
cfg.option('val1.val2', 0).value.get() cfg.option('val1.val2', 0).value.get()
except PropertiesOptionError as error: except PropertiesOptionError as error:
assert str(error) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'val2', _('property'), '"disabled"')) assert str(error) == str(_('cannot access to {0} {1} because has {2} {3}').format('option', '"val2"', _('property'), '"disabled"'))
else: else:
raise Exception('must raises') raise Exception('must raises')
assert list(cfg.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []
@ -1502,6 +1502,22 @@ def test_leadership_callback_description(config_type):
# assert not list_sessions() # assert not list_sessions()
def test_leadership_callback_outside(config_type):
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='val2')
stm = Leadership('st1', '', [st1, st2])
st3 = StrOption('st3', "", Calculation(return_value, Params(ParamOption(st2))), multi=True)
st = OptionDescription('st', '', [stm, st3])
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
owner = cfg.owner.get()
cfg.option('od.st.st1.st1').value.set(['yes'])
assert parse_od_get(cfg.value.get()) == {'od.st.st1.st1': [{'od.st.st1.st1': 'yes', 'od.st.st1.st2': 'val2'}], 'od.st.st3': ['val2']}
## assert not list_sessions()
def test_callback_raise(): def test_callback_raise():
opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise)) opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise))
opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror)) opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror))

View file

@ -933,7 +933,7 @@ def test_set_modified_value():
# #
# #
def test_pprint(): def test_pprint():
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}") msg_error = _("cannot access to {0} {1} because has {2} {3}")
msg_is_not = _('the value of "{0}" is not {1}') msg_is_not = _('the value of "{0}" is not {1}')
msg_is = _('the value of "{0}" is {1}') msg_is = _('the value of "{0}" is {1}')
properties = _('properties') properties = _('properties')
@ -988,7 +988,7 @@ def test_pprint():
list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '"1"'), msg_is.format('string2', '"string"')], add_quote=False) + ')' list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '"1"'), msg_is.format('string2', '"string"')], add_quote=False) + ')'
list_hidden = '"hidden" (' + msg_is_not.format('Test int option', display_list([2, 3, 4], separator='or', add_quote=True)) + ')' list_hidden = '"hidden" (' + msg_is_not.format('Test int option', display_list([2, 3, 4], separator='or', add_quote=True)) + ')'
assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden], add_quote=False))) assert str(err) == _(msg_error.format('option', '"Test string option"', properties, display_list([list_disabled, list_hidden], add_quote=False)))
del err del err
err = None err = None
@ -997,7 +997,7 @@ def test_pprint():
except PropertiesOptionError as error: except PropertiesOptionError as error:
err = error err = error
assert str(err) == msg_error.format('optiondescription', 'options', prop, '"hidden" (' + msg_is.format('Test int option', '"1"') + ')') assert str(err) == msg_error.format('optiondescription', '"options"', prop, '"hidden" (' + msg_is.format('Test int option', '"1"') + ')')
#err = None #err = None
#try: #try:
@ -1018,7 +1018,7 @@ def test_pprint():
except Exception as error: except Exception as error:
err = error err = error
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden'], add_quote=True)) assert str(err) == msg_error.format('option', '"string"', properties, display_list(['disabled', 'hidden'], add_quote=True))
del err del err
err = None err = None
@ -1027,13 +1027,13 @@ def test_pprint():
except Exception as error: except Exception as error:
err = error err = error
assert str(err) == msg_error.format('option', 'string3', prop, '"hidden"') assert str(err) == msg_error.format('option', '"string3"', prop, '"hidden"')
del err del err
# assert not list_sessions() # assert not list_sessions()
def test_pprint_not_todict(): def test_pprint_not_todict():
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}") msg_error = _("cannot access to {0} {1} because has {2} {3}")
msg_is_not = _('the value of "{0}" is not {1}') msg_is_not = _('the value of "{0}" is not {1}')
msg_is = _('the value of "{0}" is {1}') msg_is = _('the value of "{0}" is {1}')
properties = _('properties') properties = _('properties')
@ -1088,7 +1088,7 @@ def test_pprint_not_todict():
list_disabled = '"disabled"' list_disabled = '"disabled"'
list_hidden = '"hidden"' list_hidden = '"hidden"'
assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden], add_quote=False))) assert str(err) == _(msg_error.format('option', '"Test string option"', properties, display_list([list_disabled, list_hidden], add_quote=False)))
del err del err
err = None err = None
@ -1097,7 +1097,7 @@ def test_pprint_not_todict():
except PropertiesOptionError as error: except PropertiesOptionError as error:
err = error err = error
assert str(err) == msg_error.format('optiondescription', 'options', prop, '"hidden"') assert str(err) == msg_error.format('optiondescription', '"options"', prop, '"hidden"')
err = None err = None
try: try:
@ -1105,7 +1105,7 @@ def test_pprint_not_todict():
except Exception as error: except Exception as error:
err = error err = error
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden'], add_quote=True)) assert str(err) == msg_error.format('option', '"string"', properties, display_list(['disabled', 'hidden'], add_quote=True))
del err del err
err = None err = None
@ -1114,7 +1114,7 @@ def test_pprint_not_todict():
except Exception as error: except Exception as error:
err = error err = error
assert str(err) == msg_error.format('option', 'string3', prop, '"hidden"') assert str(err) == msg_error.format('option', '"string3"', prop, '"hidden"')
del err del err
# assert not list_sessions() # assert not list_sessions()

View file

@ -196,10 +196,10 @@ def test_requires_same_action(config_type):
submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')' submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
if config_type == 'tiramisu': if config_type == 'tiramisu':
submsg = '"new" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')' submsg = '"new" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
submsg = '"disabled" (' + str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'activate_service_web', _('property'), submsg)) + ')' submsg = '"disabled" (' + str(_('cannot access to {0} {1} because has {2} {3}').format('option', '"activate_service_web"', _('property'), submsg)) + ')'
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} {1} because has {2} {3}').format('option', '"ip_address_service_web"', _('property'), submsg))
#access to cache #access to cache
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) assert str(err) == str(_('cannot access to {0} {1} because has {2} {3}').format('option', '"ip_address_service_web"', _('property'), submsg))
else: else:
# FIXME # FIXME
assert str(err) == 'error' assert str(err) == 'error'
@ -593,7 +593,7 @@ def test_requires_transitive_hidden_disabled_multiple(config_type):
cfg.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
except ConfigError as err: except ConfigError as err:
req = err req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"'))) error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option {0} because required option {1} has {2} {3}').format('ip_address_service_web', '"activate_service_web"', _('property'), '"disabled"')))
else: else:
cfg.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
# #
@ -609,7 +609,7 @@ def test_requires_transitive_hidden_disabled_multiple(config_type):
cfg.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except ConfigError as err: except ConfigError as err:
req = err req = err
error_msg = str(_('unable to carry out a calculation for "{}", {}').format('ip_address_service_web', _('cannot access to {0} "{1}" because has {2} {3}').format('option', 'activate_service_web', _('property'), display_list(['disabled'], add_quote=True)))) error_msg = str(_('unable to carry out a calculation for {}, {}').format('"ip_address_service_web"', _('cannot access to {0} {1} because has {2} {3}').format('option', '"activate_service_web"', _('property'), display_list(['disabled'], add_quote=True))))
assert req, "ip_address_service_web should raise ConfigError" assert req, "ip_address_service_web should raise ConfigError"
assert str(req) == error_msg assert str(req) == error_msg
del req del req
@ -621,14 +621,14 @@ def test_requires_transitive_hidden_disabled_multiple(config_type):
cfg = get_config(cfg_ori, config_type) cfg = get_config(cfg_ori, config_type)
except ConfigError as err: except ConfigError as err:
req = err req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and'))))) error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option {1} has {2} {3}').format('ip_address_service_web', '"activate_service_web"', _('properties'), '"disabled" {} "hidden"'.format(_('and')))))
else: else:
cfg = get_config(cfg_ori, config_type) cfg = get_config(cfg_ori, config_type)
try: try:
cfg.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except ConfigError as err: except ConfigError as err:
req = err req = err
error_msg = str(_('unable to carry out a calculation for "{}", {}').format('ip_address_service_web', _('cannot access to {0} "{1}" because has {2} {3}').format('option', 'activate_service_web', _('properties'), display_list(['hidden', 'disabled'], add_quote=True)))) error_msg = str(_('unable to carry out a calculation for {}, {}').format('"ip_address_service_web"', _('cannot access to {0} {1} because has {2} {3}').format('option', '"activate_service_web"', _('properties'), display_list(['hidden', 'disabled'], add_quote=True))))
assert req, "ip_address_service_web should raise ConfigError" assert req, "ip_address_service_web should raise ConfigError"
assert str(req) == error_msg assert str(req) == error_msg
del req del req

View file

@ -18,7 +18,7 @@ from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
valid_network_netmask, valid_in_network, valid_broadcast, \ valid_network_netmask, valid_in_network, valid_broadcast, \
valid_not_equal, function_waiting_for_dict valid_not_equal, function_waiting_for_dict
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \ from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
ParamValue, ParamIndex, ParamSuffix, ParamInformation, ParamSelfInformation ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
from .option import * from .option import *
from .error import ConfigError from .error import ConfigError
from .api import Config, MetaConfig, GroupConfig, MixConfig from .api import Config, MetaConfig, GroupConfig, MixConfig
@ -33,7 +33,7 @@ allfuncs = ['Calculation',
'ParamSelfOption', 'ParamSelfOption',
'ParamValue', 'ParamValue',
'ParamIndex', 'ParamIndex',
'ParamSuffix', 'ParamIdentifier',
'ParamInformation', 'ParamInformation',
'ParamSelfInformation', 'ParamSelfInformation',
'MetaConfig', 'MetaConfig',

View file

@ -74,7 +74,7 @@ class PropertiesOptionError(AttributeError):
self._opt_type = 'optiondescription' self._opt_type = 'optiondescription'
else: else:
self._opt_type = 'option' self._opt_type = 'option'
self._name = subconfig.option.impl_get_display_name(subconfig) self._name = subconfig.option.impl_get_display_name(subconfig, with_quote=True)
self._orig_opt = None self._orig_opt = None
self._subconfig = subconfig self._subconfig = subconfig
self.proptype = proptype self.proptype = proptype
@ -104,18 +104,18 @@ class PropertiesOptionError(AttributeError):
prop_msg = _('properties') prop_msg = _('properties')
if properties == ['frozen']: if properties == ['frozen']:
if self._orig_opt: if self._orig_opt:
msg = 'cannot modify the {0} "{1}" because "{2}" has {3} {4}' msg = 'cannot modify the {0} {1} because "{2}" has {3} {4}'
else: else:
msg = 'cannot modify the {0} "{1}" because has {2} {3}' msg = 'cannot modify the {0} {1} because has {2} {3}'
else: else:
if self._orig_opt: if self._orig_opt:
msg = 'cannot access to {0} "{1}" because "{2}" has {3} {4}' msg = 'cannot access to {0} {1} because "{2}" has {3} {4}'
else: else:
msg = 'cannot access to {0} "{1}" because has {2} {3}' msg = 'cannot access to {0} {1} because has {2} {3}'
if self._orig_opt: if self._orig_opt:
# FIXME _orig_opt ? # FIXME _orig_opt ?
self.msg = _(msg).format(self._opt_type, self.msg = _(msg).format(self._opt_type,
self._orig_opt.impl_get_display_name(subconfig), self._orig_opt.impl_get_display_name(subconfig, with_quote=True),
self._name, self._name,
prop_msg, prop_msg,
properties_msg) properties_msg)

View file

@ -580,8 +580,8 @@ msgstr ""
"une liste ({})" "une liste ({})"
#: tiramisu/option/dynoptiondescription.py:92 #: tiramisu/option/dynoptiondescription.py:92
msgid "invalid suffix \"{}\" for option \"{}\"" msgid "invalid identifier \"{}\" for option \"{}\""
msgstr "suffixe \"{}\" invalide pour l'option \"{}\"" msgstr "identifiant \"{}\" invalide pour l'option \"{}\""
#: tiramisu/option/dynoptiondescription.py:101 #: tiramisu/option/dynoptiondescription.py:101
msgid "DynOptionDescription callback return a list with multiple value \"{}\"" msgid "DynOptionDescription callback return a list with multiple value \"{}\""

View file

@ -405,11 +405,11 @@ msgid "some characters are uppercase"
msgstr "" msgstr ""
#: tiramisu/option/dynoptiondescription.py:65 #: tiramisu/option/dynoptiondescription.py:65
msgid "suffixes in dynoptiondescription has to be a calculation" msgid "identifiers in dynoptiondescription has to be a calculation"
msgstr "" msgstr ""
#: tiramisu/option/dynoptiondescription.py:109 #: tiramisu/option/dynoptiondescription.py:109
msgid "invalid suffix \"{}\" for option \"{}\"" msgid "invalid identifier \"{}\" for option \"{}\""
msgstr "" msgstr ""
#: tiramisu/option/emailoption.py:34 #: tiramisu/option/emailoption.py:34
@ -702,7 +702,7 @@ msgid "set owner \"{0}\" is forbidden"
msgstr "" msgstr ""
#: tiramisu/value.py:636 #: tiramisu/value.py:636
msgid "index {index} is greater than the length {length} for option \"{option_bag.option.impl_get_display_name()}\"" msgid "index {index} is greater than the length {length} for option {option_bag.option.impl_get_display_name(with_quote=True)}"
msgstr "" msgstr ""
#: tiramisu/value.py:695 #: tiramisu/value.py:695

View file

@ -58,7 +58,7 @@ class Base:
'_has_dependency', '_has_dependency',
'_dependencies', '_dependencies',
'_dependencies_information', '_dependencies_information',
'_suffixes_dependencies', '_identifiers_dependencies',
'__weakref__' '__weakref__'
) )
@ -130,21 +130,21 @@ class Base:
return set(context_od._dependencies) | ret # pylint: disable=protected-access return set(context_od._dependencies) | ret # pylint: disable=protected-access
return ret return ret
def _get_suffixes_dependencies(self) -> Set[str]: def _get_identifiers_dependencies(self) -> Set[str]:
return getattr(self, '_suffixes_dependencies', STATIC_TUPLE) return getattr(self, '_identifiers_dependencies', STATIC_TUPLE)
def _add_dependency(self, def _add_dependency(self,
option, option,
is_suffix: bool=False, is_identifier: bool=False,
) -> None: ) -> None:
woption = weakref.ref(option) woption = weakref.ref(option)
options = self.get_dependencies(None) options = self.get_dependencies(None)
options.add(woption) options.add(woption)
self._dependencies = tuple(options) # pylint: disable=attribute-defined-outside-init self._dependencies = tuple(options) # pylint: disable=attribute-defined-outside-init
if is_suffix: if is_identifier:
options = list(self._get_suffixes_dependencies()) options = list(self._get_identifiers_dependencies())
options.append(woption) options.append(woption)
self._suffixes_dependencies = tuple(options) # pylint: disable=attribute-defined-outside-init self._identifiers_dependencies = tuple(options) # pylint: disable=attribute-defined-outside-init
def impl_is_optiondescription(self) -> bool: def impl_is_optiondescription(self) -> bool:
"""option is an option description """option is an option description
@ -233,7 +233,7 @@ class Base:
if default is not undefined: if default is not undefined:
return default return default
# pylint: disable=no-member # pylint: disable=no-member
raise ValueError(_(f'information\'s item for "{self.impl_get_display_name(subconfig)}" ' raise ValueError(_(f'information\'s item for {self.impl_get_display_name(subconfig, with_quote=True)} '
f'not found: "{key}"')) f'not found: "{key}"'))
def _set_information(self, def _set_information(self,
@ -298,22 +298,29 @@ class BaseOption(Base):
try: try:
return self._path return self._path
except AttributeError as err: except AttributeError as err:
raise AttributeError(_(f'"{self.impl_get_display_name(None)}" not part of any Config')) \ raise AttributeError(_(f'{self.impl_get_display_name(None, with_quote=True)} not part of any Config')) \
from err from err
def impl_get_display_name(self, def impl_get_display_name(self,
subconfig: "SubConfig", subconfig: "SubConfig",
*,
with_quote: bool=False,
) -> str: ) -> str:
"""get display name """get display name
""" """
if hasattr(self, '_display_name_function'): if hasattr(self, '_display_name_function'):
return self._display_name_function(self, subconfig) return self._display_name_function(self,
subconfig,
with_quote=with_quote,
)
name = self._get_information(subconfig, 'doc', None) name = self._get_information(subconfig, 'doc', None)
if name is None or name == '': if name is None or name == '':
if subconfig and subconfig.path: if subconfig and subconfig.path:
name = subconfig.path.rsplit('.', 1)[-1] name = subconfig.path.rsplit('.', 1)[-1]
else: else:
name = self._name name = self._name
if with_quote:
return f'"{name}"'
return name return name
def reset_cache(self, def reset_cache(self,
@ -341,29 +348,29 @@ class BaseOption(Base):
def value_dependencies(self, def value_dependencies(self,
value: Any, value: Any,
is_suffix: bool=False, is_identifier: bool=False,
) -> Any: ) -> Any:
"""parse dependancies to add dependencies """parse dependancies to add dependencies
""" """
if isinstance(value, list): if isinstance(value, list):
for val in value: for val in value:
if isinstance(value, list): if isinstance(value, list):
self.value_dependencies(val, is_suffix) self.value_dependencies(val, is_identifier)
elif isinstance(value, Calculation): elif isinstance(value, Calculation):
self.value_dependency(val, is_suffix) self.value_dependency(val, is_identifier)
elif isinstance(value, Calculation): elif isinstance(value, Calculation):
self.value_dependency(value, is_suffix) self.value_dependency(value, is_identifier)
def value_dependency(self, def value_dependency(self,
value: Any, value: Any,
is_suffix: bool=False, is_identifier: bool=False,
) -> Any: ) -> Any:
"""parse dependancy to add dependencies """parse dependancy to add dependencies
""" """
for param in chain(value.params.args, value.params.kwargs.values()): for param in chain(value.params.args, value.params.kwargs.values()):
if isinstance(param, ParamOption): if isinstance(param, ParamOption):
# pylint: disable=protected-access # pylint: disable=protected-access
param.option._add_dependency(self, is_suffix=is_suffix) param.option._add_dependency(self, is_identifier=is_identifier)
self._has_dependency = True self._has_dependency = True
elif isinstance(param, ParamInformation): elif isinstance(param, ParamInformation):
dest = self dest = self

View file

@ -39,7 +39,7 @@ NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$')
class DynOptionDescription(OptionDescription): class DynOptionDescription(OptionDescription):
"""dyn option description """dyn option description
""" """
__slots__ = ('_suffixes', __slots__ = ('_identifiers',
'_subdyns', '_subdyns',
) )
@ -47,7 +47,7 @@ class DynOptionDescription(OptionDescription):
name: str, name: str,
doc: str, doc: str,
children: List[BaseOption], children: List[BaseOption],
suffixes: Calculation, identifiers: Calculation,
**kwargs, **kwargs,
) -> None: ) -> None:
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
@ -60,29 +60,22 @@ class DynOptionDescription(OptionDescription):
wself = weakref.ref(self) wself = weakref.ref(self)
for child in children: for child in children:
child._setsubdyn(wself) child._setsubdyn(wself)
# add suffixes # add identifiers
self.value_dependencies(suffixes, is_suffix=True) self.value_dependencies(identifiers, is_identifier=True)
# if __debug__ and not isinstance(suffixes, Calculation): self._identifiers = identifiers
# raise ConfigError(_('suffixes in dynoptiondescription has to be a calculation'))
# for param in chain(suffixes.params.args, suffixes.params.kwargs.values()):
# if isinstance(param, ParamOption):
# param.option._add_dependency(self,
# is_suffix=True,
# )
self._suffixes = suffixes
def convert_suffix_to_path(self, def convert_identifier_to_path(self,
suffix: Any, identifier: Any,
) -> str: ) -> str:
"""convert suffix to use it to a path """convert identifier to use it to a path
""" """
if suffix is None: if identifier is None:
return None return None
if not isinstance(suffix, str): if not isinstance(identifier, str):
suffix = str(suffix) identifier = str(identifier)
if '.' in suffix: if '.' in identifier:
suffix = suffix.replace('.', '_') identifier = identifier.replace('.', '_')
return suffix return identifier
def impl_is_dynoptiondescription(self) -> bool: def impl_is_dynoptiondescription(self) -> bool:
return True return True
@ -92,34 +85,34 @@ class DynOptionDescription(OptionDescription):
) -> bool: ) -> bool:
return option == self return option == self
def impl_getname(self, suffix=None) -> str: def impl_getname(self, identifier=None) -> str:
"""get name """get name
""" """
name = super().impl_getname() name = super().impl_getname()
if suffix is None: if identifier is None:
return name return name
path_suffix = self.convert_suffix_to_path(suffix) path_identifier = self.convert_identifier_to_path(identifier)
return name + path_suffix return name + path_identifier
def get_suffixes(self, def get_identifiers(self,
parent: 'SubConfig', parent: 'SubConfig',
*, *,
uncalculated: bool=False, uncalculated: bool=False,
) -> List[str]: ) -> List[str]:
"""get dynamic suffixes """get dynamic identifiers
""" """
subconfig = parent.get_child(self, subconfig = parent.get_child(self,
None, None,
False, False,
properties=None, properties=None,
) )
suffixes = self._suffixes identifiers = self._identifiers
if isinstance(suffixes, list): if isinstance(identifiers, list):
suffixes = suffixes.copy() identifiers = identifiers.copy()
if uncalculated: if uncalculated:
return suffixes return identifiers
values = get_calculated_value(subconfig, values = get_calculated_value(subconfig,
suffixes, identifiers,
validate_properties=False, validate_properties=False,
)[0] )[0]
if values is None: if values is None:
@ -127,19 +120,19 @@ class DynOptionDescription(OptionDescription):
values_ = [] values_ = []
if __debug__: if __debug__:
if not isinstance(values, list): if not isinstance(values, list):
raise ValueError(_('DynOptionDescription suffixes for ' raise ValueError(_('DynOptionDescription identifiers for '
f'option "{self.impl_get_display_name(subconfig)}", is not ' f'option {self.impl_get_display_name(subconfig, with_quote=True)}, is not '
f'a list ({values})')) f'a list ({values})'))
for val in values: for val in values:
cval = self.convert_suffix_to_path(val) cval = self.convert_identifier_to_path(val)
if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None:
if __debug__ and cval is not None: if __debug__ and cval is not None:
raise ValueError(_('invalid suffix "{}" for option "{}"' raise ValueError(_('invalid identifier "{}" for option {}'
'').format(cval, '').format(cval,
self.impl_get_display_name(subconfig))) self.impl_get_display_name(subconfig, with_quote=True)))
else: else:
values_.append(val) values_.append(val)
if __debug__ and len(values_) > len(set(values_)): if __debug__ and len(values_) > len(set(values_)):
raise ValueError(_(f'DynOptionDescription "{self._name}" suffixes return a list with ' raise ValueError(_(f'DynOptionDescription "{self._name}" identifiers return a list with '
f'same values "{values_}"''')) f'same values "{values_}"'''))
return values_ return values_

View file

@ -47,6 +47,8 @@ class Leadership(OptionDescription):
children: List[BaseOption], children: List[BaseOption],
**kwargs, **kwargs,
) -> None: ) -> None:
if 'group_type' in kwargs:
raise LeadershipError(_('cannot set "group_type" attribute for a Leadership'))
super().__init__(name, super().__init__(name,
doc, doc,
children, children,
@ -81,17 +83,17 @@ class Leadership(OptionDescription):
) -> None: ) -> None:
if child.impl_is_symlinkoption(): if child.impl_is_symlinkoption():
if not index: if not index:
raise ValueError(_('leadership "{0}" shall not have ' raise ValueError(_('leadership {0} shall not have '
"a symlinkoption").format(self.impl_get_display_name(None))) "a symlinkoption").format(self.impl_get_display_name(None, with_quote=True)))
return return
if not isinstance(child, Option): if not isinstance(child, Option):
raise ValueError(_('leadership "{0}" shall not have ' raise ValueError(_('leadership {0} shall not have '
'a subgroup').format(self.impl_get_display_name(None))) 'a subgroup').format(self.impl_get_display_name(None, with_quote=True)))
if not child.impl_is_multi(): if not child.impl_is_multi():
raise ValueError(_('only multi option allowed in leadership "{0}" but option ' raise ValueError(_('only multi option allowed in leadership {0} but option '
'"{1}" is not a multi' '{1} is not a multi'
'').format(self.impl_get_display_name(None), '').format(self.impl_get_display_name(None, with_quote=True),
child.impl_get_display_name(None))) child.impl_get_display_name(None, with_quote=True)))
def _check_default_value(self, child: BaseOption): def _check_default_value(self, child: BaseOption):
if child.impl_is_symlinkoption(): if child.impl_is_symlinkoption():
@ -110,8 +112,8 @@ class Leadership(OptionDescription):
calculation = isinstance(default, Calculation) calculation = isinstance(default, Calculation)
if not calculation: if not calculation:
raise ValueError(_('not allowed default value for follower option ' raise ValueError(_('not allowed default value for follower option '
f'"{child.impl_get_display_name(None)}" in leadership ' f'{child.impl_get_display_name(None, with_quote=True)} in leadership '
f'"{self.impl_get_display_name(None)}"')) f'{self.impl_get_display_name(None, with_quote=True)}'))
def _setsubdyn(self, def _setsubdyn(self,
subdyn, subdyn,

View file

@ -127,19 +127,19 @@ class Option(BaseOption):
str_err = str(err) str_err = str(err)
if not str_err: if not str_err:
raise ValueError(_('invalid default_multi value "{0}" ' raise ValueError(_('invalid default_multi value "{0}" '
'for option "{1}"').format(str(value), 'for option {1}').format(str(value),
self.impl_get_display_name(None)) self.impl_get_display_name(None, with_quote=True))
) from err ) from err
raise ValueError(_(f'invalid default_multi value "{value}" for option ' raise ValueError(_(f'invalid default_multi value "{value}" for option '
f'"{self.impl_get_display_name(None)}", {str_err}') f'{self.impl_get_display_name(None, with_quote=True)}, {str_err}')
) from err ) from err
if _multi is submulti: if _multi is submulti:
if not isinstance(default_multi, Calculation): if not isinstance(default_multi, Calculation):
if not isinstance(default_multi, list): if not isinstance(default_multi, list):
raise ValueError(_('invalid default_multi value "{0}" ' raise ValueError(_('invalid default_multi value "{0}" '
'for option "{1}", must be a list for a submulti' 'for option {1}, must be a list for a submulti'
'').format(str(default_multi), '').format(str(default_multi),
self.impl_get_display_name(None))) self.impl_get_display_name(None, with_quote=True)))
for value in default_multi: for value in default_multi:
test_multi_value(value) test_multi_value(value)
else: else:
@ -274,14 +274,14 @@ class Option(BaseOption):
if _index is not None and subconfig.index == _index: if _index is not None and subconfig.index == _index:
lsubconfig = subconfig lsubconfig = subconfig
else: else:
suffix = subconfig.suffixes identifier = subconfig.identifiers
if suffix is not None: if identifier is not None:
suffix = suffix[-1] identifier = identifier[-1]
lsubconfig = subconfig.parent.get_child(subconfig.option, lsubconfig = subconfig.parent.get_child(subconfig.option,
_index, _index,
False, False,
properties=subconfig.properties, properties=subconfig.properties,
suffix=suffix, identifier=identifier,
name=subconfig.path.rsplit('.', 1)[-1], name=subconfig.path.rsplit('.', 1)[-1],
check_index=False, check_index=False,
) )
@ -308,9 +308,7 @@ class Option(BaseOption):
if _value is None: if _value is None:
return return
if isinstance(_value, list): if isinstance(_value, list):
raise ValueError(_('which must not be a list').format(_value, raise ValueError(_('which must not be a list'))
self.impl_get_display_name(subconfig)),
)
if isinstance(_value, Calculation) and not subconfig: if isinstance(_value, Calculation) and not subconfig:
return return
# option validation # option validation

View file

@ -220,7 +220,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
config_bag: ConfigBag, config_bag: ConfigBag,
parent: 'SubConfig', parent: 'SubConfig',
*, *,
with_suffix: bool=False, with_identifier: bool=False,
allow_dynoption: bool=False, allow_dynoption: bool=False,
) -> Union[BaseOption]: ) -> Union[BaseOption]:
"""get a child """get a child
@ -235,32 +235,24 @@ class OptionDescriptionWalk(CacheOptionDescription):
for child in self._children[1]: # pylint: disable=no-member for child in self._children[1]: # pylint: disable=no-member
if not child.impl_is_dynoptiondescription(): if not child.impl_is_dynoptiondescription():
continue continue
for suffix in child.get_suffixes(parent): for identifier in child.get_identifiers(parent):
if name != child.impl_getname(suffix): if name != child.impl_getname(identifier):
continue continue
if not with_suffix: if not with_identifier:
return child return child
return suffix, child return identifier, child
if self.impl_get_group_type() == groups.root: # pylint: disable=no-member if self.impl_get_group_type() == groups.root: # pylint: disable=no-member
raise AttributeError(_(f'unknown option "{name}" ' raise AttributeError(_(f'unknown option "{name}" '
'in root optiondescription' 'in root optiondescription'
)) ))
raise AttributeError(_(f'unknown option "{name}" ' raise AttributeError(_(f'unknown option "{name}" '
f'in optiondescription "{self.impl_get_display_name(parent)}"' f'in optiondescription {self.impl_get_display_name(parent, with_quote=True)}'
)) ))
def get_children(self) -> List[BaseOption]: def get_children(self) -> List[BaseOption]:
"""get children """get children
""" """
return self._children[1] return self._children[1]
# for child in self._children[1]:
# if config_bag is not undefined and child.impl_is_dynoptiondescription():
# yield from self.get_suffixed_children([],
# config_bag,
# child,
# )
# else:
# yield child
def get_children_recursively(self, def get_children_recursively(self,
bytype: Optional[BaseOption], bytype: Optional[BaseOption],
@ -268,7 +260,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
config_bag: ConfigBag, config_bag: ConfigBag,
self_opt: BaseOption=None, self_opt: BaseOption=None,
*, *,
option_suffixes: Optional[list]=None option_identifiers: Optional[list]=None
) -> Iterator[Union[BaseOption]]: ) -> Iterator[Union[BaseOption]]:
"""get children recursively """get children recursively
""" """
@ -299,6 +291,7 @@ class OptionDescription(OptionDescriptionWalk):
*, *,
properties=None, properties=None,
informations: Optional[Dict]=None, informations: Optional[Dict]=None,
group_type: Optional[groups.GroupType]=groups.default,
) -> None: ) -> None:
""" """
:param children: a list of options (including optiondescriptions) :param children: a list of options (including optiondescriptions)
@ -339,7 +332,8 @@ class OptionDescription(OptionDescriptionWalk):
old = child old = child
self._children = children_ self._children = children_
# the group_type is useful for filtering OptionDescriptions in a config # the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default self._group_type = None
self.impl_set_group_type(group_type)
def _setsubdyn(self, def _setsubdyn(self,
subdyn, subdyn,
@ -373,7 +367,7 @@ class OptionDescription(OptionDescriptionWalk):
that lives in `setting.groups` that lives in `setting.groups`
""" """
if __debug__: if __debug__:
if self._group_type != groups.default: if self._group_type is not None and self._group_type != groups.default:
raise ValueError(_('cannot change group_type if already set ' raise ValueError(_('cannot change group_type if already set '
'(old {0}, new {1})').format(self._group_type, '(old {0}, new {1})').format(self._group_type,
group_type)) group_type))
@ -388,22 +382,6 @@ class OptionDescription(OptionDescriptionWalk):
"""get the group type of option description """get the group type of option description
""" """
return self._group_type return self._group_type
#
# def to_dynoption(self,
# rootpath: str,
# suffixes: Optional[list],
# #ori_dyn,
# ) -> Union[SubDynOptionDescription]:
# """get syn dyn option description
# """
# if self.impl_is_dynoptiondescription():
# obj = SynDynOptionDescription
# else:
# obj = SubDynOptionDescription
# return obj(self,
# rootpath,
# suffixes,
# )
def impl_is_dynsymlinkoption(self) -> bool: def impl_is_dynsymlinkoption(self) -> bool:
"""option is not a dyn symlink option """option is not a dyn symlink option

View file

@ -151,7 +151,7 @@ class Requires(object):
form, form,
current_action, current_action,
): ):
for requires in childapi.properties(uncalculated=True): for requires in childapi.property.get(uncalculated=True):
if not isinstance(requires, str): if not isinstance(requires, str):
option = requires.params.kwargs['condition'].option option = requires.params.kwargs['condition'].option
expected = [requires.params.kwargs['expected'].value] expected = [requires.params.kwargs['expected'].value]
@ -206,7 +206,7 @@ class Requires(object):
values = self.tiramisu_web.get_enum(require_option, values = self.tiramisu_web.get_enum(require_option,
require_option.ismulti(), require_option.ismulti(),
option_path, option_path,
require_option.properties()) require_option.property.get())
for value in values: for value in values:
if value not in expected: if value not in expected:
self.requires.setdefault(path, self.requires.setdefault(path,
@ -333,7 +333,7 @@ class TiramisuDict:
def get_list(self, root, subchildapi): def get_list(self, root, subchildapi):
#ret = [] #ret = []
for childapi in subchildapi.list('all'): for childapi in subchildapi.list():
childname = childapi.name() childname = childapi.name()
if root is None: if root is None:
path = childname path = childname
@ -381,7 +381,7 @@ class TiramisuDict:
try: try:
if subchildapi is None: if subchildapi is None:
if root is None: if root is None:
subchildapi = self.config.unrestraint.option subchildapi = self.config.unrestraint
else: else:
subchildapi = self.config.unrestraint.option(root) subchildapi = self.config.unrestraint.option(root)
isleadership = False isleadership = False
@ -395,7 +395,7 @@ class TiramisuDict:
if not childapi.isoptiondescription() and childapi.isfollower(): if not childapi.isoptiondescription() and childapi.isfollower():
props_no_requires = set() props_no_requires = set()
else: else:
props_no_requires = set(childapi.properties()) props_no_requires = set(childapi.property.get())
if form is not None: if form is not None:
self.requires.add(path, self.requires.add(path,
childapi, childapi,
@ -452,13 +452,13 @@ class TiramisuDict:
else: else:
web_type = childapi.get().__class__.__name__.lower()[:-6] web_type = childapi.get().__class__.__name__.lower()[:-6]
web_type = CONVERT_WEB_TYPE.get(web_type, web_type) web_type = CONVERT_WEB_TYPE.get(web_type, web_type)
value = childapi.default() value = childapi.value.default()
if value == []: if value == []:
value = None value = None
is_multi = childapi.ismulti() is_multi = childapi.ismulti()
if is_multi: if is_multi:
defaultmulti = childapi.defaultmulti() defaultmulti = childapi.value.defaultmulti()
if defaultmulti == []: if defaultmulti == []:
defaultmulti = None defaultmulti = None
else: else:
@ -756,9 +756,10 @@ class TiramisuDict:
except PropertiesOptionError as err: except PropertiesOptionError as err:
config_bag = self.config._config_bag config_bag = self.config._config_bag
settings = config_bag.context.get_settings() settings = config_bag.context.get_settings()
if settings._calc_raises_properties(config_bag.properties, if settings._calc_raises_properties(childapi._subconfig,
config_bag.permissives, set(err.proptype),
set(err.proptype)): not_unrestraint=True,
):
obj['hidden'] = True obj['hidden'] = True
obj['display'] = False obj['display'] = False
value = childapi.value.get() value = childapi.value.get()

View file

@ -186,7 +186,7 @@ class Values:
# calculated value is a new value, so reset cache # calculated value is a new value, so reset cache
subconfig.config_bag.context.reset_cache(subconfig) subconfig.config_bag.context.reset_cache(subconfig)
# and manage force_store_value # and manage force_store_value
self._set_force_value_suffix(subconfig, self._set_force_value_identifier(subconfig,
value, value,
) )
@ -246,6 +246,14 @@ class Values:
ori_value, ori_value,
owner, owner,
) )
if 'force_store_value' in setting_properties and subconfig.option.impl_is_leader():
leader = subconfig.option.impl_get_leadership()
parent = subconfig.parent
parent._length = len(value)
leader.follower_force_store_value(value,
parent,
owners.forced,
)
validator = 'validator' in setting_properties and \ validator = 'validator' in setting_properties and \
'demoting_error_warning' not in setting_properties 'demoting_error_warning' not in setting_properties
if validator and not has_calculation: if validator and not has_calculation:
@ -257,14 +265,6 @@ class Values:
elif 'validator' in setting_properties and has_calculation: elif 'validator' in setting_properties and has_calculation:
cache = subconfig.config_bag.context.get_values_cache() cache = subconfig.config_bag.context.get_values_cache()
cache.delcache(subconfig.path) cache.delcache(subconfig.path)
if 'force_store_value' in setting_properties and subconfig.option.impl_is_leader():
leader = subconfig.option.impl_get_leadership()
parent = subconfig.parent
parent._length = len(value)
leader.follower_force_store_value(value,
parent,
owners.forced,
)
def setvalue_validation(self, def setvalue_validation(self,
subconfig: "SubConfig", subconfig: "SubConfig",
@ -306,7 +306,7 @@ class Values:
value, value,
owner, owner,
) )
self._set_force_value_suffix(subconfig, self._set_force_value_identifier(subconfig,
value, value,
) )
@ -320,11 +320,11 @@ class Values:
""" """
self._values.setdefault(path, {})[index] = [value, owner] self._values.setdefault(path, {})[index] = [value, owner]
def _set_force_value_suffix(self, def _set_force_value_identifier(self,
subconfig: 'SubConfig', subconfig: 'SubConfig',
suffix_values, identifier_values,
) -> None: ) -> None:
""" force store value for an option for suffixes """ force store value for an option for identifiers
""" """
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
if 'force_store_value' not in subconfig.config_bag.properties: if 'force_store_value' not in subconfig.config_bag.properties:
@ -332,7 +332,7 @@ class Values:
config_bag = subconfig.config_bag config_bag = subconfig.config_bag
context = config_bag.context context = config_bag.context
for woption in subconfig.option._get_suffixes_dependencies(): # pylint: disable=protected-access for woption in subconfig.option._get_identifiers_dependencies(): # pylint: disable=protected-access
options = subconfig.get_common_child(woption(), options = subconfig.get_common_child(woption(),
true_path=subconfig.path, true_path=subconfig.path,
validate_properties=False, validate_properties=False,
@ -341,12 +341,12 @@ class Values:
options = [options] options = [options]
for option in options: for option in options:
parent = option.parent parent = option.parent
for suffix in suffix_values: for identifier in identifier_values:
name = option.option.impl_getname(suffix) name = option.option.impl_getname(identifier)
opt_subconfig = parent.get_child(option.option, opt_subconfig = parent.get_child(option.option,
None, None,
False, False,
suffix=suffix, identifier=identifier,
name=name, name=name,
) )
@ -630,7 +630,7 @@ class Values:
length = len(current_value) length = len(current_value)
if index >= length: if index >= length:
raise IndexError(_('index {index} is greater than the length {length} ' raise IndexError(_('index {index} is greater than the length {length} '
'for option "{subconfig.option.impl_get_display_name()}"')) 'for option {subconfig.option.impl_get_display_name(with_quote=True)}'))
current_value.pop(index) current_value.pop(index)
leadership_subconfig = subconfig.parent leadership_subconfig = subconfig.parent
leadership_subconfig.option.pop(subconfig, leadership_subconfig.option.pop(subconfig,