diff --git a/tests/auto/test_auto.py b/tests/auto/test_auto.py index 206233c..585becf 100644 --- a/tests/auto/test_auto.py +++ b/tests/auto/test_auto.py @@ -13,9 +13,8 @@ import pytest # submulti, undefined, owners, Params, ParamOption, Calculation from tiramisu import Config, DynOptionDescription, OptionDescription, Leadership, \ 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 -from tiramisu.i18n import _ from tiramisu.option.baseoption import BaseOption from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, LeadershipError from tiramisu.setting import ALLOWED_LEADER_PROPERTIES @@ -86,6 +85,9 @@ def build_variables(*, base_name += 'dynamic_' if 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', '', multi=multi, @@ -211,10 +213,10 @@ def build_variables(*, ) ) if dynoptiondescription: - default = Calculation(calc_value, Params(ParamSuffix())) + default = Calculation(calc_value, Params(ParamIdentifier())) if param_multi: default = [default] - variables.append(StrOption(base_name + 'calc_default_suffix', + variables.append(StrOption(base_name + 'calc_default_identifier', '', default, multi=multi, @@ -309,40 +311,43 @@ def build_root_variables(*, follower_params['multi'] = submulti else: follower_params['multi'] = True - suffix = '' + identifier = '' if dynamic: - suffix += '_dynamic' - lsuffix = suffix + identifier += '_dynamic' + lidentifier = identifier if hidden: - lsuffix += '_hidden' - variables.append(Leadership('leadership' + lsuffix, '', [StrOption('leader_multi_deps' + lsuffix, + lidentifier += '_hidden' + variables.append(Leadership('leadership' + lidentifier, '', [StrOption('leader_multi_deps' + lidentifier, '', default=['l1', 'l2'], multi=True, ), ] + build_variables(**follower_params, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), )) - suffixes = StrOption('suffixes_multi_deps' + lsuffix, '', ['d1', 'd2'], multi=True) - variables.append(suffixes) + identifiers = StrOption('identifiers_multi_deps' + lidentifier, '', ['d1', 'd2'], multi=True) + variables.append(identifiers) dynamic_name = 'dynamic_' if 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() for idx, t in enumerate(tree): - lsuffix = suffix + lidentifier = identifier variables.extend(parent_variables.pop(-1)) 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'): t = t[1:] properties = frozenset(['hidden']) else: properties = frozenset() 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: - variables = [OptionDescription('tree' + lsuffix, '', variables, properties=properties)] + variables = [OptionDescription('tree' + lidentifier, '', variables, properties=properties)] od = OptionDescription('root', 'root', variables, informations={'cfg_key': 'cfg_info'}) return od @@ -445,21 +450,22 @@ def _test_option(option, without_index=False): option.leadership() assert option.isdynamic() == ('dynamic' in name) if option.isdynamic(): - suffixes = [] + identifiers = [] for path in option.path().split('.'): if 'dynamicvar1' in path: - suffixes.append('var1') + identifiers.append('var1') if 'dynamicvar2' in path: - suffixes.append('var2') + identifiers.append('var2') if 'd1' in path: - suffixes.append('d1') + identifiers.append('d1') if 'd2' in path: - suffixes.append('d2') - assert option.suffixes() == suffixes + identifiers.append('d2') + assert option.identifiers() == identifiers 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}')) if '_deps' in name: assert option.has_dependency(False) + print(option.path()) assert option.dependencies() else: assert not option.has_dependency(False) @@ -467,11 +473,11 @@ def _test_option(option, without_index=False): if option.isoptiondescription(): assert option.type() == 'optiondescription' elif 'index' in name: - assert option.type() == _('integer') + assert option.type() == 'integer' elif 'choice' in name: - assert option.type() == _('choice') + assert option.type() == 'choice' else: - assert option.type() == _('string') + assert option.type() == 'string' # only option if option.isoptiondescription(): with pytest.raises(ConfigError): @@ -485,9 +491,9 @@ def _test_option(option, without_index=False): with pytest.raises(ConfigError): option.issymlinkoption() with pytest.raises(ConfigError): - option.default() + option.value.default() with pytest.raises(ConfigError): - option.defaultmulti() + option.value.defaultmulti() with pytest.raises(ConfigError): option.pattern() with pytest.raises(ConfigError): @@ -514,14 +520,14 @@ def _test_option(option, without_index=False): assert option.index() in [0, 1] else: assert option.index() is None - if option.type() == _('integer'): + if option.type() == 'integer': assert option.pattern() == '^[0-9]+$' else: assert not option.pattern() - default = option.default() + default = option.value.default(uncalculated=True) if 'calc_default' in name: 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'] elif 'leader_multi' in name: assert default == ['l1', 'l2'] @@ -530,9 +536,9 @@ def _test_option(option, without_index=False): else: assert default is None if option.issubmulti(): - assert option.defaultmulti() == [] + assert option.value.defaultmulti() == [] elif option.ismulti(): - assert option.defaultmulti() is None + assert option.value.defaultmulti() is None def _test_information(cfg, option, without_index=False): @@ -764,8 +770,8 @@ def _get_value(name, option, unrestraint): value = 'value' if 'multi' in name: value = [value] - elif 'calc_default_suffix' in name: - value = option.suffixes()[-1] + elif 'calc_default_identifier' in name: + value = option.identifiers()[-1] if 'multi' in name: value = [value] elif 'calc_default_index' in name: @@ -776,7 +782,7 @@ def _get_value(name, option, unrestraint): value = 'val' if 'multi' in name: value = [value] - elif 'suffixes_multi' in name: + elif 'identifiers_multi' in name: value = ['d1', 'd2'] elif 'leader_multi_deps' in name: value = ['l1', 'l2'] @@ -816,11 +822,11 @@ def _test_value_normal(name, cfg, option, unrestraint, without_index): with pytest.raises(ConfigError): option.value.list() else: - if option.type() == _('string'): + if option.type() == 'string': new_value = 'new_value' new_value2 = 'new_value1' new_value3 = 'new_value2' - elif option.type() == _('integer'): + elif option.type() == 'integer': new_value = 10 new_value2 = 11 new_value3 = 12 @@ -904,7 +910,8 @@ def _test_property(cfg, option, unrestraint=False, without_index=False): if not unrestraint: properties_only_raises.append('hidden') properties_apply_requires.append('hidden') - properties_uncalculated.append('hidden') + if 'self_hidden' in option.name(): + properties_uncalculated.append('hidden') if name and 'mandatory' in name: properties.append('mandatory') properties_apply_requires.append('mandatory') diff --git a/tests/dict/data/unicode1.dict b/tests/dict/data/unicode1.dict index 3235915..e69de29 100644 --- a/tests/dict/data/unicode1.dict +++ b/tests/dict/data/unicode1.dict @@ -1,3 +0,0 @@ -{ - "options.unicode": null -} \ No newline at end of file diff --git a/tests/dict/test_json.py b/tests/dict/test_json.py index 288d105..8e9e535 100644 --- a/tests/dict/test_json.py +++ b/tests/dict/test_json.py @@ -32,6 +32,9 @@ def list_data(ext='.py'): for filename in filenames: # 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 'leadership' in filename: +# print('FIXME') +# continue ret.append(filename) return ret @@ -58,7 +61,7 @@ def load_config(filename, form.extend(mod.get_form(add_extra_od)) config.property.read_write() 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: values = loads(dumps(config.option(root).dict(remotable=remote, clearable=clearable, form=form))) return values @@ -380,11 +383,12 @@ def test_updates(filename_mod): if dico_ori is None: if clearable == 'minimum' and remote == 'minimum': 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: - 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: - suboption = config.option + suboption = config else: suboption = config.option(root) if with_model: diff --git a/tests/test_dereference.py b/tests/test_dereference.py index 258a14b..4095fb1 100644 --- a/tests/test_dereference.py +++ b/tests/test_dereference.py @@ -201,7 +201,7 @@ def test_deref_symlink(): def test_deref_dyn(): a = StrOption('a', '', ['val1', 'val2'], multi=True) 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]) cfg = Config(o) w = weakref.ref(a) diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index bf8440c..f3beec5 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -11,45 +11,47 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ OptionDescription, DynOptionDescription, submulti, Leadership, \ Config, \ - Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, ParamSelfInformation, ParamInformation, \ + Params, ParamOption, ParamValue, ParamIdentifier, ParamSelfOption, ParamDynOption, ParamIndex, ParamSelfInformation, ParamInformation, \ Calculation, calc_value 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""" doc = kls._get_information(subconfig, "doc", None) 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}" class ConvertDynOptionDescription(DynOptionDescription): - def convert_suffix_to_path(self, suffix): + def convert_identifier_to_path(self, identifier): # 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']: return raise ValueError('no value') -def return_dynval(value='val', suffix=None): +def return_dynval(value='val', identifier=None): return value -def return_list2(suffix): - return [str(suffix), 'val2'] +def return_list2(identifier): + return [str(identifier), 'val2'] -def return_list(val=None, suffix=None): +def return_list(val=None, identifier=None): if val: return val return ['val1', 'val2'] -def return_list_dot(val=None, suffix=None): +def return_list_dot(val=None, identifier=None): return ['val.1', 'val.2'] @@ -71,7 +73,7 @@ def return_str(*args, **kwargs): def test_build_dyndescription(): st1 = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) 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() -def test_dyndescription_suffixes(): +def test_dyndescription_identifiers(): st1 = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None} - assert cfg.option('dodval1').suffixes() == ['val1'] - assert cfg.option('dodval1.st').suffixes() == ['val1'] - assert cfg.option('dodval1').suffixes(only_self=True) == ['val1', 'val2'] + assert cfg.option('dodval1').identifiers() == ['val1'] + assert cfg.option('dodval1.st').identifiers() == ['val1'] + assert cfg.option('dodval1').identifiers(only_self=True) == ['val1', 'val2'] 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() def test_build_dyndescription_with_int(): - int1 = IntOption('int', '', default=Calculation(calc_value, Params(ParamSuffix()))) - dod = DynOptionDescription('dod', '', [int1], suffixes=Calculation(return_list, Params(ParamValue([1, 2])))) + int1 = IntOption('int', '', default=Calculation(calc_value, Params(ParamIdentifier()))) + dod = DynOptionDescription('dod', '', [int1], identifiers=Calculation(return_list, Params(ParamValue([1, 2])))) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) 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(): - st1 = StrOption('st', '', default=Calculation(calc_value, Params(ParamSuffix()))) - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list_dot)) + st1 = StrOption('st', '', default=Calculation(calc_value, Params(ParamIdentifier()))) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list_dot)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) 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(): st1 = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_raise)) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_raise)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ConfigError): @@ -126,7 +144,7 @@ def test_build_dyndescription_raise(): def test_build_dyndescription_not_list(): st1 = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_str)) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_str)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) with pytest.raises(ValueError): @@ -136,7 +154,7 @@ def test_build_dyndescription_not_list(): def test_subpath_dyndescription(): st1 = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -146,7 +164,7 @@ def test_subpath_dyndescription(): def test_list_dyndescription(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -157,7 +175,7 @@ def test_list_dyndescription(): def test_unknown_dyndescription(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -174,7 +192,7 @@ def test_unknown_dyndescription(): def test_getdoc_dyndescription(): 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -193,7 +211,7 @@ def test_getdoc_dyndescription(): def test_dyndescription_path(): 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -207,7 +225,7 @@ def test_dyndescription_path(): def test_mod_dyndescription(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -234,7 +252,7 @@ def test_mod_dyndescription(): def test_del_dyndescription(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -250,7 +268,7 @@ def test_del_dyndescription(): def test_multi_dyndescription(): 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -278,7 +296,7 @@ def test_multi_dyndescription(): def test_prop_dyndescription(): 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -301,7 +319,7 @@ def test_prop_dyndescription(): def test_prop_dyndescription_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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -312,8 +330,8 @@ def test_prop_dyndescription_force_store_value(): def test_prop_dyndescription_force_store_value_calculation_prefix(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) + st = StrOption('st', '', Calculation(return_list, Params(ParamIdentifier())) , properties=('force_store_value',)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamOption(lst)))) od = OptionDescription('od', '', [dod, lst]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -333,7 +351,7 @@ def test_prop_dyndescription_force_store_value_calculation_prefix(): def test_callback_dyndescription(): 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -358,7 +376,7 @@ def test_callback_dyndescription(): def test_callback_dyndescription_outside_wrong_param(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) 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)))) od = OptionDescription('od', '', [dod, out]) od2 = OptionDescription('od', '', [od, lst]) @@ -371,7 +389,7 @@ def test_callback_dyndescription_outside_wrong_param(): def test_callback_dyndescription_outside1(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) 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'])))) od = OptionDescription('od', '', [dod, out]) od2 = OptionDescription('od', '', [od, lst]) @@ -392,7 +410,7 @@ def test_callback_dyndescription_outside2(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) out = StrOption('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]) od2 = OptionDescription('od', '', [od, lst]) cfg = Config(od2) @@ -402,9 +420,34 @@ def test_callback_dyndescription_outside2(): # 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(): - st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -423,7 +466,7 @@ def test_callback_list_dyndescription(): def test_mandatory_dyndescription(): 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -449,7 +492,7 @@ def test_mandatory_dyndescription(): def test_build_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) cfg = Config(od1) 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(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -470,7 +513,7 @@ def test_subpath_dyndescription_context(): def test_list_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -484,7 +527,7 @@ def test_list_dyndescription_context(): def test_mod_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -509,7 +552,7 @@ def test_mod_dyndescription_context(): def test_del_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -526,7 +569,7 @@ def test_del_dyndescription_context(): def test_multi_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -555,7 +598,7 @@ def test_multi_dyndescription_context(): def test_prop_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -573,7 +616,7 @@ def test_prop_dyndescription_context(): def test_callback_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -598,7 +641,7 @@ def test_callback_dyndescription_context(): def test_mandatory_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -624,7 +667,7 @@ def test_mandatory_dyndescription_context(): def test_increase_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -643,7 +686,7 @@ def test_increase_dyndescription_context(): def test_decrease_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -680,13 +723,13 @@ def test_dyndescription_root(): 'expected': ParamValue(False), 'default': ParamValue(None)})) 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): cfg = Config(dod) # assert not list_sessions() -def test_dyndescription_disable_suffix_root(): +def test_dyndescription_disable_identifier_root(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), @@ -695,7 +738,7 @@ def test_dyndescription_disable_suffix_root(): 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) 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]) cfg = Config(od1) cfg.property.read_write() @@ -706,7 +749,7 @@ def test_dyndescription_disable_suffix_root(): # assert not list_sessions() -def test_dyndescription_disable_suffix_root_2(): +def test_dyndescription_disable_identifier_root_2(): boolean = BoolOption('boolean', '', False) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), @@ -715,7 +758,7 @@ def test_dyndescription_disable_suffix_root_2(): 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) 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]) cfg = Config(od1) cfg.property.read_write() @@ -726,7 +769,7 @@ def test_dyndescription_disable_suffix_root_2(): # assert not list_sessions() -def test_dyndescription_disable_suffix(): +def test_dyndescription_disable_identifier(): boolean = BoolOption('boolean', '', True) disabled_property = Calculation(calc_value, Params(ParamValue('disabled'), @@ -735,7 +778,7 @@ def test_dyndescription_disable_suffix(): 'default': ParamValue(None)})) val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True) 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]) od1 = OptionDescription('root', 'root', [od]) cfg = Config(od1) @@ -755,7 +798,7 @@ def test_requires_dyndescription(): 'expected': ParamValue(False), 'default': ParamValue(None)})) 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]) od2 = OptionDescription('od', '', [od1, boolean]) cfg = Config(od2) @@ -811,7 +854,7 @@ def test_requires_dyndescription_boolean(): 'expected': ParamValue(False), 'default': ParamValue(None)})) 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]) od2 = OptionDescription('od', '', [od, boolean1, boolean]) cfg = Config(od2) @@ -844,7 +887,7 @@ def test_requires_dyndescription_in_dyn(): 'expected': ParamValue(False), 'default': ParamValue(None)})) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -870,8 +913,8 @@ def test_requires_dyndescription_in_dyn(): # assert not list_sessions() -def calc_value_not_same(param, condition, expected, default, suffix): - if suffix == 'val1': +def calc_value_not_same(param, condition, expected, default, identifier): + if identifier == 'val1': index = 0 else: index = 1 @@ -885,10 +928,10 @@ def test_requires_dyndescription_in_dyn_not_same(): kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), 'default': ParamValue(None), - 'suffix': ParamSuffix()})) + 'identifier': ParamIdentifier()})) st = StrOption('st', '', properties=(disabled_property,)) - dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) - dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) + dod1 = DynOptionDescription('dod1', '', [boolean], identifiers=Calculation(return_list)) + dod2 = DynOptionDescription('dod2', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod1, dod2]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -922,7 +965,7 @@ def test_requires_dyndescription2(): kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), 'expected': ParamValue(False), '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]) od2 = OptionDescription('od', '', [od1, boolean]) cfg = Config(od2) @@ -967,7 +1010,7 @@ def test_requires_dyndescription2(): def test_validator_dyndescription(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -981,7 +1024,7 @@ def test_validator_dyndescription(): def test_makedict_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -993,7 +1036,7 @@ def test_makedict_dyndescription_context(): #def test_find_dyndescription_context(): # val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) # st = StrOption('st', '') -# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) +# dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) # od = OptionDescription('od', '', [dod, val1]) # od2 = OptionDescription('od', '', [od]) # cfg = Config(od2) @@ -1015,7 +1058,7 @@ def test_makedict_dyndescription_context(): def test_information_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -1049,7 +1092,7 @@ def test_all_dyndescription(): dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1, boo, intr, floa, uni, port, broad, domain, email, url, username, - filename], suffixes=Calculation(return_list)) + filename], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) cfg = Config(od1) assert cfg.option('dodval1.st').value.get() is None @@ -1128,7 +1171,7 @@ def test_leadership_dyndescription(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True) 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]) od1 = OptionDescription('od', '', [od]) 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)))) stm = Leadership('st1', '', [st1, st2]) 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]) od1 = OptionDescription('od', '', [od]) 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)))) stm = Leadership('st1', '', [st1, st2]) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1253,7 +1296,7 @@ def test_leadership_default_multi_dyndescription1(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True, default_multi='no') 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1280,7 +1323,7 @@ def test_leadership_dyndescription_param(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1339,7 +1382,7 @@ def test_leadership_default_multi_dyndescription2(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True, default_multi='no') 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1421,7 +1464,7 @@ def test_leadership_dyndescription_param_leader(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1433,7 +1476,7 @@ def test_leadership_default_multi_dyndescription3(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True, default_multi='no') 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]) od2 = OptionDescription('od', '', [od]) cfg = Config(od2) @@ -1461,7 +1504,7 @@ def test_leadership_dyndescription_param_follower(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1473,7 +1516,7 @@ def test_leadership_default_multi_dyndescription_sub(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True, default_multi='no') 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1498,7 +1541,7 @@ def test_leadership_submulti_dyndescription(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=submulti) 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -1531,7 +1574,7 @@ def test_leadership_callback_dyndescription(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -1593,7 +1636,7 @@ def test_leadership_callback_value_dyndescription(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1610,7 +1653,7 @@ def test_leadership_callback_nomulti_dyndescription(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) 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]) od2 = OptionDescription('od', '', [od1, v11]) cfg = Config(od2) @@ -1626,7 +1669,7 @@ def test_leadership_callback_samegroup_dyndescription(): st2 = StrOption('st2', "", multi=True) st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) 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]) od2 = OptionDescription('od', '', [od1]) cfg = Config(od2) @@ -1655,7 +1698,7 @@ def test_leadership_callback_samegroup_dyndescription(): def test_invalid_conflict_dyndescription(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) dodinvalid = StrOption('dodinvalid', '') dod, dodinvalid with pytest.raises(ConflictError): @@ -1668,7 +1711,7 @@ def test_leadership_default_multi_dyndescription4(): st2 = StrOption('st2', "", multi=True, default_multi='no') stm = Leadership('st1', '', [st1, st2]) od1 = OptionDescription('od1', '', [stm]) - st = DynOptionDescription('st', '', [od1], suffixes=Calculation(return_list)) + st = DynOptionDescription('st', '', [od1], identifiers=Calculation(return_list)) od = OptionDescription('od', '', [st]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -1698,8 +1741,8 @@ def test_leadership_default_multi_dyndescription4(): def test_subdynod_dyndescription_root(): st2 = StrOption('st2', '') - dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) - dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) + dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b'])))) + dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list)) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) od1 = OptionDescription('od', '', [dod, st3]) #, st4]) @@ -1764,8 +1807,8 @@ def test_subdynod_dyndescription_root(): def test_subdynod_dyndescription(): st2 = StrOption('st2', '') - dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) - dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) + dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b'])))) + dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) od = OptionDescription('od', '', [od1, st3]) #, st4]) @@ -1830,8 +1873,8 @@ def test_subdynod_dyndescription(): def test_subdynod_dyndescription_2(): st2 = StrOption('st2', '') st1 = StrOption('st1', '', default=['a', 'b'], multi=True) - dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) - dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) + dod1 = DynOptionDescription('dod1', '', [st2], identifiers=Calculation(return_list, Params(ParamOption(st1)))) + dod = DynOptionDescription('dod', '', [dod1, st1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) od = OptionDescription('od', '', [od1, st3]) #, st4]) @@ -1868,8 +1911,8 @@ def test_subdynod_dyndescription_leadership(): st1 = StrOption('st1', '', multi=True) st2 = StrOption('st2', '', multi=True) stm = Leadership('stm', '', [st1, st2]) - dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) - dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) + dod1 = DynOptionDescription('dod1', '', [stm], identifiers=Calculation(return_list, Params(ParamValue(['a', 'b'])))) + dod = DynOptionDescription('dod', '', [dod1], identifiers=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) 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) @@ -1916,7 +1959,7 @@ def test_dyndescription_symlink(): st = StrOption('st', '') st2 = SymLinkOption('st2', st) # 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]) cfg = Config(od) 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(): st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) st2 = SymLinkOption('st2', st) # 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]) cfg = Config(od) 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(): st = StrOption('st', '') # with pytest.raises(ConfigError): - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list)) st2 = SymLinkOption('st2', st) od = OptionDescription('od', '', [dod, st2]) cfg = Config(od) @@ -1956,7 +1999,7 @@ def test_dyndescription_symlink_inside(): st = StrOption('st', '') st2 = SymLinkOption('st2', st) # 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]) cfg = Config(od) 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(): 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]) cfg = Config(od1) with pytest.raises(ValueError): @@ -1985,7 +2028,7 @@ def test_invalid_samevalue_dyndescription(): def test_invalid_name_dyndescription(): 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]) cfg = Config(od1) with pytest.raises(ValueError): @@ -1997,7 +2040,7 @@ def test_leadership_dyndescription_convert(): st1 = StrOption('st1', "", multi=True) st2 = StrOption('st2', "", multi=True) 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]) od1 = OptionDescription('od', '', [od]) cfg = Config(od1) @@ -2057,7 +2100,7 @@ def test_leadership_callback_samegroup_dyndescription_convert(): st2 = StrOption('st2', "", multi=True) st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) 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]) od2 = OptionDescription('od', '', [od1]) 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) 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',)) - dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list)) od1 = OptionDescription('root', '', [dyn]) cfg = Config(od1) 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) 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]) - dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list)) od1 = OptionDescription('root', '', [dyn]) cfg = Config(od1) cfg.property.read_write() @@ -2135,7 +2178,7 @@ def test_dyn_leadership_requires(): 'index': ParamIndex()})) 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]) - dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + dyn = DynOptionDescription('leader', '', [interface1], identifiers=Calculation(return_list)) od1 = OptionDescription('toto', '', [dyn]) cfg = Config(od1) cfg.property.read_write() @@ -2175,7 +2218,7 @@ def test_dyn_leadership_mandatory(): hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') 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)}))})) - 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]) cfg = Config(od1) assert cfg.value.mandatory() == [] @@ -2184,8 +2227,8 @@ def test_dyn_leadership_mandatory(): def test_dyn_symlink(): remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) - remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) - dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) + remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamIdentifier()))) + dyn_remote = DynOptionDescription("remote_", "Account for ", identifiers=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) name = SymLinkOption("name", opt=remote_ip) od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) cfg = Config(od1) @@ -2198,8 +2241,8 @@ def test_dyn_symlink(): def test_dyn_callback_with_not_dyn(): remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) - remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) - dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) + remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamIdentifier()))) + 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) od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) 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',)) user = OptionDescription(name="user", doc="user", children=[name, password2]) 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) cfg = Config(root) @@ -2279,7 +2322,7 @@ def test_dyn_link_subdyn_2(): name = StrOption(name="name", doc="name", properties=('mandatory',)) user = OptionDescription(name="user", doc="user", children=[name, password2]) 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) 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',)) 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"]) - 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]) 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) 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',)) 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_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"]) - 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 = 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) 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',)) 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"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=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]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + 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", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) + 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) cfg = Config(root) @@ -2696,9 +2739,9 @@ def test_dyn_link_subdyn_disabled(): 'default': ParamValue(None)})) 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"]) - user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=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]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + 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", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) + 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]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) cfg = Config(root) @@ -2757,8 +2800,8 @@ def test_option_dynoption_display_name(): password = StrOption(name="password", doc="password") schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) 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]) - schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + 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_", identifiers=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) cfg = Config(root, display_name=display_name) @@ -2768,7 +2811,7 @@ def test_option_dynoption_display_name(): def test_option_dynoption_param_information(): info1 = StrOption("info1", '', Calculation(calc_value, Params(ParamSelfInformation('key'))), informations={'key': 'value'}) 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]) 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'} @@ -2777,10 +2820,10 @@ def test_option_dynoption_param_information(): def test_callback_list_dyndescription_information(): - st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamInformation('suffix')))) + st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',)) + dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_list, Params(ParamInformation('identifier')))) od = OptionDescription('od', '', [dod]) - od2 = OptionDescription('od', '', [od], informations={'suffix': ['ival1', 'ival2']}) + od2 = OptionDescription('od', '', [od], informations={'identifier': ['ival1', 'ival2']}) cfg = Config(od2) owner = cfg.owner.get() 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.dodival1.st').owner.get() == owner 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 not list_sessions() def test_callback_list_dyndescription_information_not_list(): - st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) - dod = DynOptionDescription('dod', '', [st], suffixes=["sval1", Calculation(return_dynval, Params(ParamInformation('suffix')))]) + st = StrOption('st', '', Calculation(return_list2, Params(ParamIdentifier())), multi=True, properties=('notunique',)) + dod = DynOptionDescription('dod', '', [st], identifiers=["sval1", Calculation(return_dynval, Params(ParamInformation('identifier')))]) od = OptionDescription('od', '', [dod]) - od2 = OptionDescription('od', '', [od], informations={'suffix': 'ival2'}) + od2 = OptionDescription('od', '', [od], informations={'identifier': 'ival2'}) cfg = Config(od2) owner = cfg.owner.get() 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.dodsval1.st').owner.get() == owner 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 not list_sessions() diff --git a/tests/test_mandatory.py b/tests/test_mandatory.py index d993206..8c49ccd 100644 --- a/tests/test_mandatory.py +++ b/tests/test_mandatory.py @@ -681,7 +681,7 @@ def test_mandatory_od_disabled(): # assert not list_sessions() -def return_list(val=None, suffix=None): +def return_list(val=None, identifier=None): if val: return val else: @@ -690,7 +690,7 @@ def return_list(val=None, suffix=None): #def test_mandatory_dyndescription(): # 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]) # od2 = OptionDescription('od', '', [od]) # cfg = Config(od2) @@ -701,7 +701,7 @@ def return_list(val=None, suffix=None): #def test_mandatory_dyndescription_context(): # val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) # 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]) # od2 = OptionDescription('od', '', [od]) # cfg = Config(od2) diff --git a/tests/test_option.py b/tests/test_option.py index 6285bfe..36202f7 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -20,7 +20,7 @@ def a_func(): return None -def display_name(*args): +def display_name(*args, with_quote=False): return 'display_name' diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index 2d5b047..da37b60 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -945,7 +945,7 @@ def test_consistency_leader_and_followers_leader_mandatory_transitive(): try: cfg.option('val1.val2', 0).value.get() except PropertiesOptionError as error: - assert str(error) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'val2', _('property'), '"disabled"')) + assert str(error) == str(_('cannot access to {0} {1} because has {2} {3}').format('option', '"val2"', _('property'), '"disabled"')) else: raise Exception('must raises') assert list(cfg.value.mandatory()) == [] @@ -1502,6 +1502,22 @@ def test_leadership_callback_description(config_type): # 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(): opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise)) opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror)) diff --git a/tests/test_option_setting.py b/tests/test_option_setting.py index 490260f..9c42c1f 100644 --- a/tests/test_option_setting.py +++ b/tests/test_option_setting.py @@ -933,7 +933,7 @@ def test_set_modified_value(): # # 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 = _('the value of "{0}" is {1}') 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_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 err = None @@ -997,7 +997,7 @@ def test_pprint(): except PropertiesOptionError as 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 #try: @@ -1018,7 +1018,7 @@ def test_pprint(): except Exception as 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 err = None @@ -1027,13 +1027,13 @@ def test_pprint(): except Exception as 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 # assert not list_sessions() 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 = _('the value of "{0}" is {1}') properties = _('properties') @@ -1088,7 +1088,7 @@ def test_pprint_not_todict(): list_disabled = '"disabled"' 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 err = None @@ -1097,7 +1097,7 @@ def test_pprint_not_todict(): except PropertiesOptionError as 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 try: @@ -1105,7 +1105,7 @@ def test_pprint_not_todict(): except Exception as 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 err = None @@ -1114,7 +1114,7 @@ def test_pprint_not_todict(): except Exception as 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 # assert not list_sessions() diff --git a/tests/test_requires.py b/tests/test_requires.py index 25c738d..50ac319 100644 --- a/tests/test_requires.py +++ b/tests/test_requires.py @@ -196,10 +196,10 @@ def test_requires_same_action(config_type): submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')' if config_type == 'tiramisu': 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)) + ')' - assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_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)) #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: # FIXME assert str(err) == 'error' @@ -593,7 +593,7 @@ def test_requires_transitive_hidden_disabled_multiple(config_type): cfg.option('activate_service').value.set(False) except ConfigError as 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: 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() except ConfigError as 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 str(req) == error_msg del req @@ -621,14 +621,14 @@ def test_requires_transitive_hidden_disabled_multiple(config_type): cfg = get_config(cfg_ori, config_type) except ConfigError as 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: cfg = get_config(cfg_ori, config_type) try: cfg.option('ip_address_service_web').value.get() except ConfigError as 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 str(req) == error_msg del req diff --git a/tiramisu/__init__.py b/tiramisu/__init__.py index 3f682b2..1e0fec4 100644 --- a/tiramisu/__init__.py +++ b/tiramisu/__init__.py @@ -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_not_equal, function_waiting_for_dict from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \ - ParamValue, ParamIndex, ParamSuffix, ParamInformation, ParamSelfInformation + ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation from .option import * from .error import ConfigError from .api import Config, MetaConfig, GroupConfig, MixConfig @@ -33,7 +33,7 @@ allfuncs = ['Calculation', 'ParamSelfOption', 'ParamValue', 'ParamIndex', - 'ParamSuffix', + 'ParamIdentifier', 'ParamInformation', 'ParamSelfInformation', 'MetaConfig', diff --git a/tiramisu/error.py b/tiramisu/error.py index ad109b2..4fe6e2e 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -74,7 +74,7 @@ class PropertiesOptionError(AttributeError): self._opt_type = 'optiondescription' else: 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._subconfig = subconfig self.proptype = proptype @@ -104,18 +104,18 @@ class PropertiesOptionError(AttributeError): prop_msg = _('properties') if properties == ['frozen']: 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: - msg = 'cannot modify the {0} "{1}" because has {2} {3}' + msg = 'cannot modify the {0} {1} because has {2} {3}' else: 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: - msg = 'cannot access to {0} "{1}" because has {2} {3}' + msg = 'cannot access to {0} {1} because has {2} {3}' if self._orig_opt: # FIXME _orig_opt ? 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, prop_msg, properties_msg) diff --git a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po index 91316b2..9a8ccda 100644 --- a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po +++ b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po @@ -580,8 +580,8 @@ msgstr "" "une liste ({})" #: tiramisu/option/dynoptiondescription.py:92 -msgid "invalid suffix \"{}\" for option \"{}\"" -msgstr "suffixe \"{}\" invalide pour l'option \"{}\"" +msgid "invalid identifier \"{}\" for option \"{}\"" +msgstr "identifiant \"{}\" invalide pour l'option \"{}\"" #: tiramisu/option/dynoptiondescription.py:101 msgid "DynOptionDescription callback return a list with multiple value \"{}\"" diff --git a/tiramisu/locale/tiramisu.pot b/tiramisu/locale/tiramisu.pot index 0f35fbe..104398a 100644 --- a/tiramisu/locale/tiramisu.pot +++ b/tiramisu/locale/tiramisu.pot @@ -405,11 +405,11 @@ msgid "some characters are uppercase" msgstr "" #: tiramisu/option/dynoptiondescription.py:65 -msgid "suffixes in dynoptiondescription has to be a calculation" +msgid "identifiers in dynoptiondescription has to be a calculation" msgstr "" #: tiramisu/option/dynoptiondescription.py:109 -msgid "invalid suffix \"{}\" for option \"{}\"" +msgid "invalid identifier \"{}\" for option \"{}\"" msgstr "" #: tiramisu/option/emailoption.py:34 @@ -702,7 +702,7 @@ msgid "set owner \"{0}\" is forbidden" msgstr "" #: 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 "" #: tiramisu/value.py:695 diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 4f1dcf3..7396ec1 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -58,7 +58,7 @@ class Base: '_has_dependency', '_dependencies', '_dependencies_information', - '_suffixes_dependencies', + '_identifiers_dependencies', '__weakref__' ) @@ -130,21 +130,21 @@ class Base: return set(context_od._dependencies) | ret # pylint: disable=protected-access return ret - def _get_suffixes_dependencies(self) -> Set[str]: - return getattr(self, '_suffixes_dependencies', STATIC_TUPLE) + def _get_identifiers_dependencies(self) -> Set[str]: + return getattr(self, '_identifiers_dependencies', STATIC_TUPLE) def _add_dependency(self, option, - is_suffix: bool=False, + is_identifier: bool=False, ) -> None: woption = weakref.ref(option) options = self.get_dependencies(None) options.add(woption) self._dependencies = tuple(options) # pylint: disable=attribute-defined-outside-init - if is_suffix: - options = list(self._get_suffixes_dependencies()) + if is_identifier: + options = list(self._get_identifiers_dependencies()) 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: """option is an option description @@ -233,7 +233,7 @@ class Base: if default is not undefined: return default # 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}"')) def _set_information(self, @@ -298,22 +298,29 @@ class BaseOption(Base): try: return self._path 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 def impl_get_display_name(self, subconfig: "SubConfig", + *, + with_quote: bool=False, ) -> str: """get display name """ 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) if name is None or name == '': if subconfig and subconfig.path: name = subconfig.path.rsplit('.', 1)[-1] else: name = self._name + if with_quote: + return f'"{name}"' return name def reset_cache(self, @@ -341,29 +348,29 @@ class BaseOption(Base): def value_dependencies(self, value: Any, - is_suffix: bool=False, + is_identifier: bool=False, ) -> Any: """parse dependancies to add dependencies """ if isinstance(value, list): for val in value: if isinstance(value, list): - self.value_dependencies(val, is_suffix) + self.value_dependencies(val, is_identifier) elif isinstance(value, Calculation): - self.value_dependency(val, is_suffix) + self.value_dependency(val, is_identifier) elif isinstance(value, Calculation): - self.value_dependency(value, is_suffix) + self.value_dependency(value, is_identifier) def value_dependency(self, value: Any, - is_suffix: bool=False, + is_identifier: bool=False, ) -> Any: """parse dependancy to add dependencies """ for param in chain(value.params.args, value.params.kwargs.values()): if isinstance(param, ParamOption): # 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 elif isinstance(param, ParamInformation): dest = self diff --git a/tiramisu/option/dynoptiondescription.py b/tiramisu/option/dynoptiondescription.py index 12d6d8b..724f2f4 100644 --- a/tiramisu/option/dynoptiondescription.py +++ b/tiramisu/option/dynoptiondescription.py @@ -39,7 +39,7 @@ NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') class DynOptionDescription(OptionDescription): """dyn option description """ - __slots__ = ('_suffixes', + __slots__ = ('_identifiers', '_subdyns', ) @@ -47,7 +47,7 @@ class DynOptionDescription(OptionDescription): name: str, doc: str, children: List[BaseOption], - suffixes: Calculation, + identifiers: Calculation, **kwargs, ) -> None: # pylint: disable=too-many-arguments @@ -60,29 +60,22 @@ class DynOptionDescription(OptionDescription): wself = weakref.ref(self) for child in children: child._setsubdyn(wself) - # add suffixes - self.value_dependencies(suffixes, is_suffix=True) -# if __debug__ and not isinstance(suffixes, Calculation): -# 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 + # add identifiers + self.value_dependencies(identifiers, is_identifier=True) + self._identifiers = identifiers - def convert_suffix_to_path(self, - suffix: Any, + def convert_identifier_to_path(self, + identifier: Any, ) -> 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 - if not isinstance(suffix, str): - suffix = str(suffix) - if '.' in suffix: - suffix = suffix.replace('.', '_') - return suffix + if not isinstance(identifier, str): + identifier = str(identifier) + if '.' in identifier: + identifier = identifier.replace('.', '_') + return identifier def impl_is_dynoptiondescription(self) -> bool: return True @@ -92,34 +85,34 @@ class DynOptionDescription(OptionDescription): ) -> bool: return option == self - def impl_getname(self, suffix=None) -> str: + def impl_getname(self, identifier=None) -> str: """get name """ name = super().impl_getname() - if suffix is None: + if identifier is None: return name - path_suffix = self.convert_suffix_to_path(suffix) - return name + path_suffix + path_identifier = self.convert_identifier_to_path(identifier) + return name + path_identifier - def get_suffixes(self, + def get_identifiers(self, parent: 'SubConfig', *, uncalculated: bool=False, ) -> List[str]: - """get dynamic suffixes + """get dynamic identifiers """ subconfig = parent.get_child(self, None, False, properties=None, ) - suffixes = self._suffixes - if isinstance(suffixes, list): - suffixes = suffixes.copy() + identifiers = self._identifiers + if isinstance(identifiers, list): + identifiers = identifiers.copy() if uncalculated: - return suffixes + return identifiers values = get_calculated_value(subconfig, - suffixes, + identifiers, validate_properties=False, )[0] if values is None: @@ -127,19 +120,19 @@ class DynOptionDescription(OptionDescription): values_ = [] if __debug__: if not isinstance(values, list): - raise ValueError(_('DynOptionDescription suffixes for ' - f'option "{self.impl_get_display_name(subconfig)}", is not ' + raise ValueError(_('DynOptionDescription identifiers for ' + f'option {self.impl_get_display_name(subconfig, with_quote=True)}, is not ' f'a list ({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 __debug__ and cval is not None: - raise ValueError(_('invalid suffix "{}" for option "{}"' + raise ValueError(_('invalid identifier "{}" for option {}' '').format(cval, - self.impl_get_display_name(subconfig))) + self.impl_get_display_name(subconfig, with_quote=True))) else: values_.append(val) 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_}"''')) return values_ diff --git a/tiramisu/option/leadership.py b/tiramisu/option/leadership.py index 8398f3e..8ac73a3 100644 --- a/tiramisu/option/leadership.py +++ b/tiramisu/option/leadership.py @@ -47,6 +47,8 @@ class Leadership(OptionDescription): children: List[BaseOption], **kwargs, ) -> None: + if 'group_type' in kwargs: + raise LeadershipError(_('cannot set "group_type" attribute for a Leadership')) super().__init__(name, doc, children, @@ -81,17 +83,17 @@ class Leadership(OptionDescription): ) -> None: if child.impl_is_symlinkoption(): if not index: - raise ValueError(_('leadership "{0}" shall not have ' - "a symlinkoption").format(self.impl_get_display_name(None))) + raise ValueError(_('leadership {0} shall not have ' + "a symlinkoption").format(self.impl_get_display_name(None, with_quote=True))) return if not isinstance(child, Option): - raise ValueError(_('leadership "{0}" shall not have ' - 'a subgroup').format(self.impl_get_display_name(None))) + raise ValueError(_('leadership {0} shall not have ' + 'a subgroup').format(self.impl_get_display_name(None, with_quote=True))) if not child.impl_is_multi(): - raise ValueError(_('only multi option allowed in leadership "{0}" but option ' - '"{1}" is not a multi' - '').format(self.impl_get_display_name(None), - child.impl_get_display_name(None))) + raise ValueError(_('only multi option allowed in leadership {0} but option ' + '{1} is not a multi' + '').format(self.impl_get_display_name(None, with_quote=True), + child.impl_get_display_name(None, with_quote=True))) def _check_default_value(self, child: BaseOption): if child.impl_is_symlinkoption(): @@ -110,8 +112,8 @@ class Leadership(OptionDescription): calculation = isinstance(default, Calculation) if not calculation: raise ValueError(_('not allowed default value for follower option ' - f'"{child.impl_get_display_name(None)}" in leadership ' - f'"{self.impl_get_display_name(None)}"')) + f'{child.impl_get_display_name(None, with_quote=True)} in leadership ' + f'{self.impl_get_display_name(None, with_quote=True)}')) def _setsubdyn(self, subdyn, diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index bb42508..290c92f 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -127,19 +127,19 @@ class Option(BaseOption): str_err = str(err) if not str_err: raise ValueError(_('invalid default_multi value "{0}" ' - 'for option "{1}"').format(str(value), - self.impl_get_display_name(None)) + 'for option {1}').format(str(value), + self.impl_get_display_name(None, with_quote=True)) ) from err 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 if _multi is submulti: if not isinstance(default_multi, Calculation): if not isinstance(default_multi, list): 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), - self.impl_get_display_name(None))) + self.impl_get_display_name(None, with_quote=True))) for value in default_multi: test_multi_value(value) else: @@ -274,14 +274,14 @@ class Option(BaseOption): if _index is not None and subconfig.index == _index: lsubconfig = subconfig else: - suffix = subconfig.suffixes - if suffix is not None: - suffix = suffix[-1] + identifier = subconfig.identifiers + if identifier is not None: + identifier = identifier[-1] lsubconfig = subconfig.parent.get_child(subconfig.option, _index, False, properties=subconfig.properties, - suffix=suffix, + identifier=identifier, name=subconfig.path.rsplit('.', 1)[-1], check_index=False, ) @@ -308,9 +308,7 @@ class Option(BaseOption): if _value is None: return if isinstance(_value, list): - raise ValueError(_('which must not be a list').format(_value, - self.impl_get_display_name(subconfig)), - ) + raise ValueError(_('which must not be a list')) if isinstance(_value, Calculation) and not subconfig: return # option validation diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 01a7c39..9045da8 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -220,7 +220,7 @@ class OptionDescriptionWalk(CacheOptionDescription): config_bag: ConfigBag, parent: 'SubConfig', *, - with_suffix: bool=False, + with_identifier: bool=False, allow_dynoption: bool=False, ) -> Union[BaseOption]: """get a child @@ -235,32 +235,24 @@ class OptionDescriptionWalk(CacheOptionDescription): for child in self._children[1]: # pylint: disable=no-member if not child.impl_is_dynoptiondescription(): continue - for suffix in child.get_suffixes(parent): - if name != child.impl_getname(suffix): + for identifier in child.get_identifiers(parent): + if name != child.impl_getname(identifier): continue - if not with_suffix: + if not with_identifier: return child - return suffix, child + return identifier, child if self.impl_get_group_type() == groups.root: # pylint: disable=no-member raise AttributeError(_(f'unknown option "{name}" ' 'in root optiondescription' )) 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]: """get children """ 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, bytype: Optional[BaseOption], @@ -268,7 +260,7 @@ class OptionDescriptionWalk(CacheOptionDescription): config_bag: ConfigBag, self_opt: BaseOption=None, *, - option_suffixes: Optional[list]=None + option_identifiers: Optional[list]=None ) -> Iterator[Union[BaseOption]]: """get children recursively """ @@ -299,6 +291,7 @@ class OptionDescription(OptionDescriptionWalk): *, properties=None, informations: Optional[Dict]=None, + group_type: Optional[groups.GroupType]=groups.default, ) -> None: """ :param children: a list of options (including optiondescriptions) @@ -339,7 +332,8 @@ class OptionDescription(OptionDescriptionWalk): old = child self._children = children_ # 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, subdyn, @@ -373,7 +367,7 @@ class OptionDescription(OptionDescriptionWalk): that lives in `setting.groups` """ 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 ' '(old {0}, new {1})').format(self._group_type, group_type)) @@ -388,22 +382,6 @@ class OptionDescription(OptionDescriptionWalk): """get the group type of option description """ 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: """option is not a dyn symlink option diff --git a/tiramisu/todict.py b/tiramisu/todict.py index c044c27..dd9d2fe 100644 --- a/tiramisu/todict.py +++ b/tiramisu/todict.py @@ -151,7 +151,7 @@ class Requires(object): form, current_action, ): - for requires in childapi.properties(uncalculated=True): + for requires in childapi.property.get(uncalculated=True): if not isinstance(requires, str): option = requires.params.kwargs['condition'].option expected = [requires.params.kwargs['expected'].value] @@ -206,7 +206,7 @@ class Requires(object): values = self.tiramisu_web.get_enum(require_option, require_option.ismulti(), option_path, - require_option.properties()) + require_option.property.get()) for value in values: if value not in expected: self.requires.setdefault(path, @@ -333,7 +333,7 @@ class TiramisuDict: def get_list(self, root, subchildapi): #ret = [] - for childapi in subchildapi.list('all'): + for childapi in subchildapi.list(): childname = childapi.name() if root is None: path = childname @@ -381,7 +381,7 @@ class TiramisuDict: try: if subchildapi is None: if root is None: - subchildapi = self.config.unrestraint.option + subchildapi = self.config.unrestraint else: subchildapi = self.config.unrestraint.option(root) isleadership = False @@ -395,7 +395,7 @@ class TiramisuDict: if not childapi.isoptiondescription() and childapi.isfollower(): props_no_requires = set() else: - props_no_requires = set(childapi.properties()) + props_no_requires = set(childapi.property.get()) if form is not None: self.requires.add(path, childapi, @@ -452,13 +452,13 @@ class TiramisuDict: else: web_type = childapi.get().__class__.__name__.lower()[:-6] web_type = CONVERT_WEB_TYPE.get(web_type, web_type) - value = childapi.default() + value = childapi.value.default() if value == []: value = None is_multi = childapi.ismulti() if is_multi: - defaultmulti = childapi.defaultmulti() + defaultmulti = childapi.value.defaultmulti() if defaultmulti == []: defaultmulti = None else: @@ -756,9 +756,10 @@ class TiramisuDict: except PropertiesOptionError as err: config_bag = self.config._config_bag settings = config_bag.context.get_settings() - if settings._calc_raises_properties(config_bag.properties, - config_bag.permissives, - set(err.proptype)): + if settings._calc_raises_properties(childapi._subconfig, + set(err.proptype), + not_unrestraint=True, + ): obj['hidden'] = True obj['display'] = False value = childapi.value.get() diff --git a/tiramisu/value.py b/tiramisu/value.py index 0cc5cd0..6a956f5 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -186,7 +186,7 @@ class Values: # calculated value is a new value, so reset cache subconfig.config_bag.context.reset_cache(subconfig) # and manage force_store_value - self._set_force_value_suffix(subconfig, + self._set_force_value_identifier(subconfig, value, ) @@ -246,6 +246,14 @@ class Values: ori_value, 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 \ 'demoting_error_warning' not in setting_properties if validator and not has_calculation: @@ -257,14 +265,6 @@ class Values: elif 'validator' in setting_properties and has_calculation: cache = subconfig.config_bag.context.get_values_cache() 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, subconfig: "SubConfig", @@ -306,7 +306,7 @@ class Values: value, owner, ) - self._set_force_value_suffix(subconfig, + self._set_force_value_identifier(subconfig, value, ) @@ -320,11 +320,11 @@ class Values: """ self._values.setdefault(path, {})[index] = [value, owner] - def _set_force_value_suffix(self, + def _set_force_value_identifier(self, subconfig: 'SubConfig', - suffix_values, + identifier_values, ) -> None: - """ force store value for an option for suffixes + """ force store value for an option for identifiers """ # pylint: disable=too-many-locals if 'force_store_value' not in subconfig.config_bag.properties: @@ -332,7 +332,7 @@ class Values: config_bag = subconfig.config_bag 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(), true_path=subconfig.path, validate_properties=False, @@ -341,12 +341,12 @@ class Values: options = [options] for option in options: parent = option.parent - for suffix in suffix_values: - name = option.option.impl_getname(suffix) + for identifier in identifier_values: + name = option.option.impl_getname(identifier) opt_subconfig = parent.get_child(option.option, None, False, - suffix=suffix, + identifier=identifier, name=name, ) @@ -630,7 +630,7 @@ class Values: length = len(current_value) if index >= 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) leadership_subconfig = subconfig.parent leadership_subconfig.option.pop(subconfig,