From 246ac2579102eaf3d6775d0b1581112c8a4456bd Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 3 Oct 2020 21:43:50 +0200 Subject: [PATCH 1/7] refactor valid_enum --- src/rougail/annotator.py | 151 +++++++++--------- src/rougail/data/rougail.dtd | 2 +- src/rougail/tiramisureflector.py | 13 +- .../10load_frozenifin_multiparam/00-base.xml | 4 +- .../10load_frozenifin_noexist/00-base.xml | 4 +- .../10valid_enum_accent/00-base.xml | 5 +- .../10valid_enum_base/00-base.xml | 4 +- .../10valid_enum_base_redefine/00-base.xml | 8 +- .../10valid_enum_base_redefine/01-base.xml | 3 +- .../10valid_enum_eosfunc/00-base.xml | 25 --- .../10valid_enum_eosfunc/makedict/base.json | 1 - .../10valid_enum_eosfunc/tiramisu/base.py | 11 -- .../10valid_enum_leader/00-base.xml | 4 +- .../10valid_enum_mandatory/00-base.xml | 4 +- .../10valid_enum_multi/00-base.xml | 4 +- .../10valid_enum_none/00-base.xml | 4 +- .../10valid_enum_number/00-base.xml | 4 +- .../10valid_enum_numberdefault/00-base.xml | 4 +- .../10valid_enum_python/00-base.xml | 32 ---- .../10valid_enum_python/makedict/base.json | 1 - .../10valid_enum_python/tiramisu/base.py | 14 -- .../10valid_enum_value/00-base.xml | 4 +- .../00-base.xml | 40 ----- .../makedict/base.json | 1 - .../tiramisu/base.py | 25 --- .../dictionaries/40ifin_validenum/00-base.xml | 39 ----- .../40ifin_validenum/makedict/base.json | 1 - .../40ifin_validenum/tiramisu/base.py | 14 -- .../51redefine_validenum/00-base.xml | 23 --- .../51redefine_validenum/01-redefine.xml | 23 --- .../51redefine_validenum/makedict/base.json | 1 - .../51redefine_validenum/tiramisu/base.py | 11 -- .../80empty_typeeole_python/00_base.xml | 21 --- .../80empty_validenum/00-base.xml | 22 --- .../80unknown_validenum/00-base.xml | 22 --- .../80validenum_ouinon/00-base.xml | 22 --- .../80validenum_python_not_list/00-base.xml | 32 ---- .../80validenum_python_unknown/00-base.xml | 32 ---- .../00-base.xml | 32 ---- tests/eosfunc/test.py | 2 +- 40 files changed, 129 insertions(+), 540 deletions(-) delete mode 100644 tests/dictionaries/10valid_enum_eosfunc/00-base.xml delete mode 100644 tests/dictionaries/10valid_enum_eosfunc/makedict/base.json delete mode 100644 tests/dictionaries/10valid_enum_eosfunc/tiramisu/base.py delete mode 100644 tests/dictionaries/10valid_enum_python/00-base.xml delete mode 100644 tests/dictionaries/10valid_enum_python/makedict/base.json delete mode 100644 tests/dictionaries/10valid_enum_python/tiramisu/base.py delete mode 100644 tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/00-base.xml delete mode 100644 tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/makedict/base.json delete mode 100644 tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py delete mode 100644 tests/dictionaries/40ifin_validenum/00-base.xml delete mode 100644 tests/dictionaries/40ifin_validenum/makedict/base.json delete mode 100644 tests/dictionaries/40ifin_validenum/tiramisu/base.py delete mode 100644 tests/dictionaries/51redefine_validenum/00-base.xml delete mode 100644 tests/dictionaries/51redefine_validenum/01-redefine.xml delete mode 100644 tests/dictionaries/51redefine_validenum/makedict/base.json delete mode 100644 tests/dictionaries/51redefine_validenum/tiramisu/base.py delete mode 100644 tests/dictionaries/80empty_typeeole_python/00_base.xml delete mode 100644 tests/dictionaries/80empty_validenum/00-base.xml delete mode 100644 tests/dictionaries/80unknown_validenum/00-base.xml delete mode 100644 tests/dictionaries/80validenum_ouinon/00-base.xml delete mode 100644 tests/dictionaries/80validenum_python_not_list/00-base.xml delete mode 100644 tests/dictionaries/80validenum_python_unknown/00-base.xml delete mode 100644 tests/dictionaries/80validenum_python_unknownvalue/00-base.xml diff --git a/src/rougail/annotator.py b/src/rougail/annotator.py index 5e527dbd..53085c5d 100644 --- a/src/rougail/annotator.py +++ b/src/rougail/annotator.py @@ -56,9 +56,6 @@ KEY_TYPE = {'variable': 'symlink', 'URLOption': 'web_address', 'FilenameOption': 'filename'} -TYPE_PARAM_CHECK = ('string', 'python', 'variable') -TYPE_PARAM_CONDITION = ('string', 'python', 'number', 'variable') -TYPE_PARAM_FILL = ('string', 'number', 'variable') CONVERSION = {'number': int} FREEZE_AUTOFREEZE_VARIABLE = 'module_instancie' @@ -476,9 +473,11 @@ class VariableAnnotator: check.name = 'valid_enum' check.target = path check.namespace = namespace - param = self.objectspace.param() - param.text = str(FORCE_CHOICE[variable.type]) - check.param = [param] + check.param = [] + for value in FORCE_CHOICE[variable.type]: + param = self.objectspace.param() + param.text = value + check.param.append(param) if not hasattr(self.objectspace.space, 'constraints'): self.objectspace.space.constraints = self.objectspace.constraints() self.objectspace.space.constraints.namespace = namespace @@ -627,8 +626,6 @@ class ConstraintAnnotator: if hasattr(check, 'param'): param_option_indexes = [] for idx, param in enumerate(check.param): - if param.type not in TYPE_PARAM_CHECK: - raise DictConsistencyError(_('cannot use {} type as a param in check for {}').format(param.type, check.target)) if param.type == 'variable' and not self.objectspace.paths.path_is_defined(param.text): if param.optional is True: param_option_indexes.append(idx) @@ -661,55 +658,50 @@ class ConstraintAnnotator: remove_indexes = [] for idx, check in enumerate(self.objectspace.space.constraints.check): if check.name == 'valid_enum': - if len(check.param) != 1: - raise DictConsistencyError(_(f'cannot set more than one param for valid_enum for variable {check.target}')) - param = check.param[0] if check.target in self.valid_enums: raise DictConsistencyError(_(f'valid_enum already set for {check.target}')) - if param.type not in ['string', 'python', 'number']: - raise DictConsistencyError(_(f'unknown type {param.type} for param in valid_enum for {check.target}')) + if not hasattr(check, 'param'): + raise DictConsistencyError(_(f'param is mandatory for a valid_enum of variable {check.target}')) variable = self.objectspace.paths.get_variable_obj(check.target) - values = self.load_params_in_validenum(param, - variable.name, - variable.type, - ) - self.valid_enums[check.target] = {'type': param.type, - 'values': values} + values = self.load_params_in_valid_enum(check.param, + variable.name, + variable.type, + ) self._set_valid_enum(variable, values, variable.type, + check.target ) remove_indexes.append(idx) remove_indexes.sort(reverse=True) for idx in remove_indexes: del self.objectspace.space.constraints.check[idx] - def load_params_in_validenum(self, - param, - variable_name, - variable_type, - ): - if not hasattr(param, 'text') and (param.type == 'python' or param.type == 'number'): - raise DictConsistencyError(_(f"All '{param.type}' variables shall be set in order to calculate valid_enum for variable {variable_name}")) - if variable_type == 'string' and param.type == 'number': - raise DictConsistencyError(_(f'Unconsistency valid_enum type ({param.type}), for variable {variable_name}')) - if param.type == 'python': - try: - values = eval(param.text, {'eosfunc': self.eosfunc, '__builtins__': {'range': range, 'str': str}}) - except NameError: - raise DictConsistencyError(_('The function {} is unknown').format(param.text)) - else: - try: - values = literal_eval(param.text) - except ValueError: - raise DictConsistencyError(_(f'Cannot load {param.text} in valid_enum')) - if not isinstance(values, list): - raise DictConsistencyError(_('Function {} shall return a list').format(param.text)) - for value in values: - if variable_type == 'string' and not isinstance(value, str): - raise DictConsistencyError(_(f'Cannot load "{param.text}", "{value}" is not a string')) - if variable_type == 'number' and not isinstance(value, int): - raise DictConsistencyError(_(f'Cannot load "{param.text}", "{value}" is not a number')) + def load_params_in_valid_enum(self, + params, + variable_name, + variable_type, + ): + has_variable = None + values = [] + for param in params: + if param.type == 'variable': + if has_variable is not None: + raise DictConsistencyError(_(f'only one "variable" parameter is allowed for valid_enum of variable {variable_name}')) + has_variable = True + variable = self.objectspace.paths.get_variable_obj(param.text) + if not variable.multi: + raise DictConsistencyError(_(f'only multi "variable" parameter is allowed for valid_enum of variable {variable_name}')) + values = param.text + else: + if has_variable: + raise DictConsistencyError(_(f'only one "variable" parameter is allowed for valid_enum of variable {variable_name}')) + if not hasattr(param, 'text'): + if param.type == 'number': + raise DictConsistencyError(_(f'value is mandatory for valid_enum of variable {variable_name}')) + values.append(None) + else: + values.append(param.text) return values def check_change_warning(self): @@ -736,9 +728,6 @@ class ConstraintAnnotator: def check_params_target(self): for condition in self.objectspace.space.constraints.condition: - for param in condition.param: - if param.type not in TYPE_PARAM_CONDITION: - raise DictConsistencyError(_(f'cannot use {param.type} type as a param in a condition')) if not hasattr(condition, 'target'): raise DictConsistencyError(_('target is mandatory in condition')) for target in condition.target: @@ -919,40 +908,52 @@ class ConstraintAnnotator: variable.property.append(prop) del self.objectspace.space.constraints.condition - def _set_valid_enum(self, variable, values, type_): + def _set_valid_enum(self, variable, values, type_, target): # value for choice's variable is mandatory variable.mandatory = True # build choice variable.choice = [] - choices = [] - for value in values: + if isinstance(values, str): choice = self.objectspace.choice() - try: - choice.name = CONVERSION.get(type_, str)(value) - except: - raise DictConsistencyError(_(f'unable to change type of a valid_enum entry "{value}" is not a valid "{type_}" for "{variable.name}"')) - if choice.name == '': - choice.name = None - choices.append(choice.name) - choice.type = type_ + choice.type = 'calculation' + choice.name = values variable.choice.append(choice) + else: + self.valid_enums[target] = {'type': type_, + 'values': values, + } + choices = [] + for value in values: + choice = self.objectspace.choice() + try: + if value is not None: + choice.name = CONVERSION.get(type_, str)(value) + else: + choice.name = value + except: + raise DictConsistencyError(_(f'unable to change type of a valid_enum entry "{value}" is not a valid "{type_}" for "{variable.name}"')) + if choice.name == '': + choice.name = None + choices.append(choice.name) + choice.type = type_ + variable.choice.append(choice) + # check value or set first choice value has default value + if hasattr(variable, 'value'): + for value in variable.value: + value.type = type_ + try: + cvalue = CONVERSION.get(type_, str)(value.name) + except: + raise DictConsistencyError(_(f'unable to change type of value "{value}" is not a valid "{type_}" for "{variable.name}"')) + if cvalue not in choices: + raise DictConsistencyError(_('value "{}" of variable "{}" is not in list of all expected values ({})').format(value.name, variable.name, choices)) + else: + new_value = self.objectspace.value() + new_value.name = choices[0] + new_value.type = type_ + variable.value = [new_value] if not variable.choice: raise DictConsistencyError(_('empty valid enum is not allowed for variable {}').format(variable.name)) - # check value or set first choice value has default value - if hasattr(variable, 'value'): - for value in variable.value: - value.type = type_ - try: - cvalue = CONVERSION.get(type_, str)(value.name) - except: - raise DictConsistencyError(_(f'unable to change type of value "{value}" is not a valid "{type_}" for "{variable.name}"')) - if cvalue not in choices: - raise DictConsistencyError(_('value "{}" of variable "{}" is not in list of all expected values ({})').format(value.name, variable.name, choices)) - else: - new_value = self.objectspace.value() - new_value.name = values[0] - new_value.type = type_ - variable.value = [new_value] variable.type = 'choice' def convert_check(self): @@ -1030,8 +1031,6 @@ class ConstraintAnnotator: if hasattr(fill, 'param'): param_to_delete = [] for fill_idx, param in enumerate(fill.param): - if param.type not in TYPE_PARAM_FILL: - raise DictConsistencyError(_(f'cannot use {param.type} type as a param in a fill/auto')) if param.type != 'string' and not hasattr(param, 'text'): raise DictConsistencyError(_(f"All '{param.type}' variables shall have a value in order to calculate {fill.target}")) if param.type == 'variable': diff --git a/src/rougail/data/rougail.dtd b/src/rougail/data/rougail.dtd index 1b819ca1..aaf950c6 100644 --- a/src/rougail/data/rougail.dtd +++ b/src/rougail/data/rougail.dtd @@ -141,7 +141,7 @@ - + diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index dde73e9e..69fc93f9 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -252,7 +252,7 @@ class Common: if not self.attrib[key]: continue value = "frozenset({" + self.attrib[key] + "})" - elif key in ['default', 'multi', 'suffixes', 'validators']: + elif key in ['default', 'multi', 'suffixes', 'validators', 'values']: value = self.attrib[key] elif isinstance(value, str) and key != 'opt' and not value.startswith('['): value = "'" + value.replace("'", "\\\'") + "'" @@ -368,9 +368,16 @@ class Variable(Common): elif tag == 'check': self.attrib['validators'].append(self.calculation_value(child, ['ParamSelfOption()'])) elif tag == 'choice': - choices.append(child.name) + if child.type == 'calculation': + value = self.storage.get(child.name).get() + choices = f"Calculation(func.calc_value, Params((ParamOption({value}))))" + else: + choices.append(child.name) if choices: - self.attrib['values'] = tuple(choices) + if isinstance(choices, list): + self.attrib['values'] = str(tuple(choices)) + else: + self.attrib['values'] = choices if self.attrib['default'] == []: del self.attrib['default'] elif not self.attrib['multi'] and isinstance(self.attrib['default'], list): diff --git a/tests/dictionaries/10load_frozenifin_multiparam/00-base.xml b/tests/dictionaries/10load_frozenifin_multiparam/00-base.xml index 528ec015..900d5e65 100644 --- a/tests/dictionaries/10load_frozenifin_multiparam/00-base.xml +++ b/tests/dictionaries/10load_frozenifin_multiparam/00-base.xml @@ -20,7 +20,9 @@ - ['tous', 'authentifié', 'aucun'] + tous + authentifié + aucun tous diff --git a/tests/dictionaries/10load_frozenifin_noexist/00-base.xml b/tests/dictionaries/10load_frozenifin_noexist/00-base.xml index 60c371d3..d9bbe323 100644 --- a/tests/dictionaries/10load_frozenifin_noexist/00-base.xml +++ b/tests/dictionaries/10load_frozenifin_noexist/00-base.xml @@ -19,7 +19,9 @@ - ['tous', 'authentifié', 'aucun'] + tous + authentifié + aucun oui diff --git a/tests/dictionaries/10valid_enum_accent/00-base.xml b/tests/dictionaries/10valid_enum_accent/00-base.xml index 50c46110..12720be4 100644 --- a/tests/dictionaries/10valid_enum_accent/00-base.xml +++ b/tests/dictionaries/10valid_enum_accent/00-base.xml @@ -19,7 +19,10 @@ - ['a', 'b', 'c', 'é'] + a + b + c + é diff --git a/tests/dictionaries/10valid_enum_base/00-base.xml b/tests/dictionaries/10valid_enum_base/00-base.xml index 1f8887d4..9c8d133e 100644 --- a/tests/dictionaries/10valid_enum_base/00-base.xml +++ b/tests/dictionaries/10valid_enum_base/00-base.xml @@ -19,7 +19,9 @@ - ['a','b','c'] + a + b + c diff --git a/tests/dictionaries/10valid_enum_base_redefine/00-base.xml b/tests/dictionaries/10valid_enum_base_redefine/00-base.xml index c2b95bc6..0b6101aa 100644 --- a/tests/dictionaries/10valid_enum_base_redefine/00-base.xml +++ b/tests/dictionaries/10valid_enum_base_redefine/00-base.xml @@ -22,10 +22,14 @@ - ['a','b','c'] + a + b + c - ['a','b','c'] + a + b + c diff --git a/tests/dictionaries/10valid_enum_base_redefine/01-base.xml b/tests/dictionaries/10valid_enum_base_redefine/01-base.xml index 290a5a4a..87b45ceb 100644 --- a/tests/dictionaries/10valid_enum_base_redefine/01-base.xml +++ b/tests/dictionaries/10valid_enum_base_redefine/01-base.xml @@ -14,7 +14,8 @@ - ['a','c'] + a + c diff --git a/tests/dictionaries/10valid_enum_eosfunc/00-base.xml b/tests/dictionaries/10valid_enum_eosfunc/00-base.xml deleted file mode 100644 index e21f4c8f..00000000 --- a/tests/dictionaries/10valid_enum_eosfunc/00-base.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - non - - - - - - - - eosfunc.list_files('/notexists', default=['oui', 'non']) - - - - - - - diff --git a/tests/dictionaries/10valid_enum_eosfunc/makedict/base.json b/tests/dictionaries/10valid_enum_eosfunc/makedict/base.json deleted file mode 100644 index 797595b0..00000000 --- a/tests/dictionaries/10valid_enum_eosfunc/makedict/base.json +++ /dev/null @@ -1 +0,0 @@ -{"rougail.general.mode_conteneur_actif": "non"} diff --git a/tests/dictionaries/10valid_enum_eosfunc/tiramisu/base.py b/tests/dictionaries/10valid_enum_eosfunc/tiramisu/base.py deleted file mode 100644 index 637aec54..00000000 --- a/tests/dictionaries/10valid_enum_eosfunc/tiramisu/base.py +++ /dev/null @@ -1,11 +0,0 @@ -try: - from tiramisu3 import * -except: - from tiramisu import * -from rougail.tiramisu import ConvertDynOptionDescription -import imp -func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') -option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3]) -option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) -option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/10valid_enum_leader/00-base.xml b/tests/dictionaries/10valid_enum_leader/00-base.xml index 85b61810..27161903 100644 --- a/tests/dictionaries/10valid_enum_leader/00-base.xml +++ b/tests/dictionaries/10valid_enum_leader/00-base.xml @@ -17,7 +17,9 @@ - ['a','b','c'] + a + b + c follower1 diff --git a/tests/dictionaries/10valid_enum_mandatory/00-base.xml b/tests/dictionaries/10valid_enum_mandatory/00-base.xml index 5d96fd76..4d104156 100644 --- a/tests/dictionaries/10valid_enum_mandatory/00-base.xml +++ b/tests/dictionaries/10valid_enum_mandatory/00-base.xml @@ -15,7 +15,9 @@ - ['a','b','c'] + a + b + c diff --git a/tests/dictionaries/10valid_enum_multi/00-base.xml b/tests/dictionaries/10valid_enum_multi/00-base.xml index 3a596722..6ea4bfa1 100644 --- a/tests/dictionaries/10valid_enum_multi/00-base.xml +++ b/tests/dictionaries/10valid_enum_multi/00-base.xml @@ -15,7 +15,9 @@ - ['a','b','c'] + a + b + c diff --git a/tests/dictionaries/10valid_enum_none/00-base.xml b/tests/dictionaries/10valid_enum_none/00-base.xml index fcff2f28..f03d3e1a 100644 --- a/tests/dictionaries/10valid_enum_none/00-base.xml +++ b/tests/dictionaries/10valid_enum_none/00-base.xml @@ -19,7 +19,9 @@ - ['a','b',''] + a + b + diff --git a/tests/dictionaries/10valid_enum_number/00-base.xml b/tests/dictionaries/10valid_enum_number/00-base.xml index 650ef928..2ab66988 100644 --- a/tests/dictionaries/10valid_enum_number/00-base.xml +++ b/tests/dictionaries/10valid_enum_number/00-base.xml @@ -17,7 +17,9 @@ - [1, 2, 3] + 1 + 2 + 3 diff --git a/tests/dictionaries/10valid_enum_numberdefault/00-base.xml b/tests/dictionaries/10valid_enum_numberdefault/00-base.xml index 6f04bfd3..531b177f 100644 --- a/tests/dictionaries/10valid_enum_numberdefault/00-base.xml +++ b/tests/dictionaries/10valid_enum_numberdefault/00-base.xml @@ -19,7 +19,9 @@ - [1, 2, 3] + 1 + 2 + 3 diff --git a/tests/dictionaries/10valid_enum_python/00-base.xml b/tests/dictionaries/10valid_enum_python/00-base.xml deleted file mode 100644 index 022efc1e..00000000 --- a/tests/dictionaries/10valid_enum_python/00-base.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - non - - - - - test - - - - - - - - eosfunc.calc_multi_val(['test']) - - - - - bla bla bla - - - - diff --git a/tests/dictionaries/10valid_enum_python/makedict/base.json b/tests/dictionaries/10valid_enum_python/makedict/base.json deleted file mode 100644 index 7fdca9ef..00000000 --- a/tests/dictionaries/10valid_enum_python/makedict/base.json +++ /dev/null @@ -1 +0,0 @@ -{"rougail.general.mode_conteneur_actif": "non", "rougail.enumfam.enumvar": "test"} diff --git a/tests/dictionaries/10valid_enum_python/tiramisu/base.py b/tests/dictionaries/10valid_enum_python/tiramisu/base.py deleted file mode 100644 index 78f0f8a3..00000000 --- a/tests/dictionaries/10valid_enum_python/tiramisu/base.py +++ /dev/null @@ -1,14 +0,0 @@ -try: - from tiramisu3 import * -except: - from tiramisu import * -from rougail.tiramisu import ConvertDynOptionDescription -import imp -func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') -option_3 = ChoiceOption(properties=frozenset({'expert', 'mandatory'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'expert'}), children=[option_3]) -option_5 = ChoiceOption(properties=frozenset({'expert', 'mandatory'}), name='enumvar', doc='multi', multi=False, default='test', values=('test',)) -option_5.impl_set_information("help", "bla bla bla") -option_4 = OptionDescription(name='enumfam', doc='enumfam', properties=frozenset({'expert'}), children=[option_5]) -option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2, option_4]) -option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/10valid_enum_value/00-base.xml b/tests/dictionaries/10valid_enum_value/00-base.xml index 5b5ab9bd..1794b78e 100644 --- a/tests/dictionaries/10valid_enum_value/00-base.xml +++ b/tests/dictionaries/10valid_enum_value/00-base.xml @@ -14,7 +14,9 @@ - ['a','b','c'] + a + b + c diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/00-base.xml b/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/00-base.xml deleted file mode 100644 index 1db0a401..00000000 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/00-base.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - non - - - - - - - - - - ['non','statique'] - - - statique - afilllist - - - - - - - diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/makedict/base.json b/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/makedict/base.json deleted file mode 100644 index 1a2b116f..00000000 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/makedict/base.json +++ /dev/null @@ -1 +0,0 @@ -{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true} diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py b/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py deleted file mode 100644 index d0652baa..00000000 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py +++ /dev/null @@ -1,25 +0,0 @@ -try: - from tiramisu3 import * -except: - from tiramisu import * -from rougail.tiramisu import ConvertDynOptionDescription -import imp -func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') -option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('non', 'statique')) -option_4 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5]) -option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) -option_10 = StrOption(name='group', doc='group', multi=False, default='root') -option_11 = StrOption(name='mode', doc='mode', multi=False, default='0644') -option_12 = StrOption(name='name', doc='name', multi=False, default='/tmp/file') -option_13 = StrOption(name='owner', doc='owner', multi=False, default='root') -option_14 = StrOption(name='source', doc='source', multi=False, default='file') -option_15 = BoolOption(name='templating', doc='templating', multi=False, default=True) -option_16 = BoolOption(properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('statique'), 'reverse_condition': ParamValue(True)}))}), name='activate', doc='activate', multi=False, default=True) -option_9 = OptionDescription(name='file', doc='file', children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) -option_8 = OptionDescription(name='files', doc='files', children=[option_9]) -option_7 = OptionDescription(name='test', doc='test', children=[option_8]) -option_7.impl_set_information("manage", True) -option_6 = OptionDescription(name='services', doc='services', properties=frozenset({'hidden'}), children=[option_7]) -option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6]) diff --git a/tests/dictionaries/40ifin_validenum/00-base.xml b/tests/dictionaries/40ifin_validenum/00-base.xml deleted file mode 100644 index e6c5e809..00000000 --- a/tests/dictionaries/40ifin_validenum/00-base.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - non - - - - - - - - - ['a','b','c'] - - - d - mode_conteneur_actif - - - d - mode_conteneur_actif2 - - - - - - - diff --git a/tests/dictionaries/40ifin_validenum/makedict/base.json b/tests/dictionaries/40ifin_validenum/makedict/base.json deleted file mode 100644 index 6b1c9cf7..00000000 --- a/tests/dictionaries/40ifin_validenum/makedict/base.json +++ /dev/null @@ -1 +0,0 @@ -{"rougail.general.mode_conteneur_actif": "non", "rougail.general2.mode_conteneur_actif3": "a"} diff --git a/tests/dictionaries/40ifin_validenum/tiramisu/base.py b/tests/dictionaries/40ifin_validenum/tiramisu/base.py deleted file mode 100644 index ea11621c..00000000 --- a/tests/dictionaries/40ifin_validenum/tiramisu/base.py +++ /dev/null @@ -1,14 +0,0 @@ -try: - from tiramisu3 import * -except: - from tiramisu import * -from rougail.tiramisu import ConvertDynOptionDescription -import imp -func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') -option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3]) -option_5 = ChoiceOption(properties=frozenset({'disabled', 'mandatory', 'normal'}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif3', doc='No change', multi=False, default='a', values=('a', 'b', 'c')) -option_4 = OptionDescription(name='general2', doc='general2', properties=frozenset({'hidden', 'normal'}), children=[option_5, option_6]) -option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2, option_4]) -option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/51redefine_validenum/00-base.xml b/tests/dictionaries/51redefine_validenum/00-base.xml deleted file mode 100644 index 50543923..00000000 --- a/tests/dictionaries/51redefine_validenum/00-base.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - ['a','b','c'] - - - - - - - diff --git a/tests/dictionaries/51redefine_validenum/01-redefine.xml b/tests/dictionaries/51redefine_validenum/01-redefine.xml deleted file mode 100644 index 1506aa0f..00000000 --- a/tests/dictionaries/51redefine_validenum/01-redefine.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - ['a','b'] - - - - - - - diff --git a/tests/dictionaries/51redefine_validenum/makedict/base.json b/tests/dictionaries/51redefine_validenum/makedict/base.json deleted file mode 100644 index ef30ef31..00000000 --- a/tests/dictionaries/51redefine_validenum/makedict/base.json +++ /dev/null @@ -1 +0,0 @@ -{"rougail.general.mode_conteneur_actif": "a"} diff --git a/tests/dictionaries/51redefine_validenum/tiramisu/base.py b/tests/dictionaries/51redefine_validenum/tiramisu/base.py deleted file mode 100644 index 9d9bf3c8..00000000 --- a/tests/dictionaries/51redefine_validenum/tiramisu/base.py +++ /dev/null @@ -1,11 +0,0 @@ -try: - from tiramisu3 import * -except: - from tiramisu import * -from rougail.tiramisu import ConvertDynOptionDescription -import imp -func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') -option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif', doc='Redefine description', multi=False, default='a', values=('a', 'b')) -option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3]) -option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) -option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/80empty_typeeole_python/00_base.xml b/tests/dictionaries/80empty_typeeole_python/00_base.xml deleted file mode 100644 index 58cce127..00000000 --- a/tests/dictionaries/80empty_typeeole_python/00_base.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - 3127 - - - - - - - - - - - diff --git a/tests/dictionaries/80empty_validenum/00-base.xml b/tests/dictionaries/80empty_validenum/00-base.xml deleted file mode 100644 index 8c83e1bd..00000000 --- a/tests/dictionaries/80empty_validenum/00-base.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - [] - - - - - - - diff --git a/tests/dictionaries/80unknown_validenum/00-base.xml b/tests/dictionaries/80unknown_validenum/00-base.xml deleted file mode 100644 index a2e08a4e..00000000 --- a/tests/dictionaries/80unknown_validenum/00-base.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - ['oui', 'non'] - - - - - - - diff --git a/tests/dictionaries/80validenum_ouinon/00-base.xml b/tests/dictionaries/80validenum_ouinon/00-base.xml deleted file mode 100644 index 76013a1d..00000000 --- a/tests/dictionaries/80validenum_ouinon/00-base.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - ['maybe'] - - - - - - - diff --git a/tests/dictionaries/80validenum_python_not_list/00-base.xml b/tests/dictionaries/80validenum_python_not_list/00-base.xml deleted file mode 100644 index 80775496..00000000 --- a/tests/dictionaries/80validenum_python_not_list/00-base.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - non - - - - - c - - - - - - - - eosfunc.valid_lower('toto') - - - - - bla bla bla - - - - diff --git a/tests/dictionaries/80validenum_python_unknown/00-base.xml b/tests/dictionaries/80validenum_python_unknown/00-base.xml deleted file mode 100644 index e02fa0e3..00000000 --- a/tests/dictionaries/80validenum_python_unknown/00-base.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - non - - - - - c - - - - - - - - toto - - - - - bla bla bla - - - - diff --git a/tests/dictionaries/80validenum_python_unknownvalue/00-base.xml b/tests/dictionaries/80validenum_python_unknownvalue/00-base.xml deleted file mode 100644 index 4a4e102a..00000000 --- a/tests/dictionaries/80validenum_python_unknownvalue/00-base.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - non - - - - - c - - - - - - - - eosfunc.calc_multi_val(['pouet']) - - - - - bla bla bla - - - - diff --git a/tests/eosfunc/test.py b/tests/eosfunc/test.py index a0cb0f5a..887c9a8d 100644 --- a/tests/eosfunc/test.py +++ b/tests/eosfunc/test.py @@ -58,4 +58,4 @@ def device_type(*args, **kwargs): def calc_list(*args, **kwargs): - return [] + return list(args) From 5eba872969bd2422773987b2119f79b7ddb3092b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 3 Oct 2020 22:10:32 +0200 Subject: [PATCH 2/7] add OptionInformation support --- src/rougail/tiramisureflector.py | 2 ++ tests/dictionaries/01auto_base/makedict/base.json | 2 +- tests/dictionaries/01fill_autofreeze/makedict/base.json | 2 +- tests/dictionaries/01fill_autosave/makedict/base.json | 2 +- tests/dictionaries/01fill_base/makedict/base.json | 2 +- tests/dictionaries/01fill_baseaccent/makedict/base.json | 2 +- tests/dictionaries/01fill_mandatory/00-base.xml | 2 +- tests/dictionaries/01fill_mandatory/makedict/base.json | 2 +- tests/dictionaries/01fill_mandatory/tiramisu/base.py | 2 +- tests/dictionaries/01fill_number/makedict/base.json | 2 +- tests/dictionaries/01fill_optional/makedict/base.json | 2 +- tests/dictionaries/10autosave_hidden/makedict/base.json | 2 +- .../10autosave_hidden_frozenifin/makedict/base.json | 2 +- tests/dictionaries/10load_frozenifin_auto/makedict/base.json | 2 +- tests/dictionaries/20family_dynamic_calc/makedict/base.json | 2 +- tests/dictionaries/20family_dynamic_number/makedict/base.json | 2 +- .../30mandatory_withoutvaluecalc/makedict/base.json | 2 +- .../dictionaries/30mandatory_withvaluecalc/makedict/base.json | 2 +- tests/dictionaries/60action_external/makedict/base.json | 2 +- tests/eosfunc/test.py | 3 ++- tests/test_2_makedict.py | 1 + 21 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index 69fc93f9..9693f508 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -422,6 +422,8 @@ class Variable(Common): if hasattr(param, 'suffix'): value['suffix'] = param.suffix return self.build_param(value) + elif param.type == 'information': + return f'ParamInformation("{param.text}")' raise LoaderError(_('unknown param type {}').format(param.type)) def populate_value(self, diff --git a/tests/dictionaries/01auto_base/makedict/base.json b/tests/dictionaries/01auto_base/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01auto_base/makedict/base.json +++ b/tests/dictionaries/01auto_base/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_autofreeze/makedict/base.json b/tests/dictionaries/01fill_autofreeze/makedict/base.json index 47b2052a..2dac1070 100644 --- a/tests/dictionaries/01fill_autofreeze/makedict/base.json +++ b/tests/dictionaries/01fill_autofreeze/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non", "rougail.general.module_instancie": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non", "rougail.general.module_instancie": "non"} diff --git a/tests/dictionaries/01fill_autosave/makedict/base.json b/tests/dictionaries/01fill_autosave/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01fill_autosave/makedict/base.json +++ b/tests/dictionaries/01fill_autosave/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_base/makedict/base.json b/tests/dictionaries/01fill_base/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01fill_base/makedict/base.json +++ b/tests/dictionaries/01fill_base/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_baseaccent/makedict/base.json b/tests/dictionaries/01fill_baseaccent/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01fill_baseaccent/makedict/base.json +++ b/tests/dictionaries/01fill_baseaccent/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_mandatory/00-base.xml b/tests/dictionaries/01fill_mandatory/00-base.xml index 36dac3d8..e6c39d4d 100644 --- a/tests/dictionaries/01fill_mandatory/00-base.xml +++ b/tests/dictionaries/01fill_mandatory/00-base.xml @@ -5,7 +5,7 @@ - + non diff --git a/tests/dictionaries/01fill_mandatory/makedict/base.json b/tests/dictionaries/01fill_mandatory/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01fill_mandatory/makedict/base.json +++ b/tests/dictionaries/01fill_mandatory/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_mandatory/tiramisu/base.py b/tests/dictionaries/01fill_mandatory/tiramisu/base.py index 97c28412..e4b5e843 100644 --- a/tests/dictionaries/01fill_mandatory/tiramisu/base.py +++ b/tests/dictionaries/01fill_mandatory/tiramisu/base.py @@ -6,7 +6,7 @@ from rougail.tiramisu import ConvertDynOptionDescription import imp func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py') option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non')) -option_3 = DomainnameOption(type='domainname', allow_ip=False, properties=frozenset({'expert', 'mandatory'}), name='mode_conteneur_actif', doc='No change', multi=False, default=Calculation(func.calc_val, Params((ParamOption(option_4, notraisepropertyerror=False, todict=False)), kwargs={}))) +option_3 = ChoiceOption(properties=frozenset({'expert', 'mandatory'}), name='mode_conteneur_actif', doc='No change', multi=False, default=Calculation(func.calc_val, Params((ParamOption(option_4, notraisepropertyerror=False, todict=False)), kwargs={})), values=('oui', 'non')) option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4]) option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2]) option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1]) diff --git a/tests/dictionaries/01fill_number/makedict/base.json b/tests/dictionaries/01fill_number/makedict/base.json index 86ba9458..87a5f7d7 100644 --- a/tests/dictionaries/01fill_number/makedict/base.json +++ b/tests/dictionaries/01fill_number/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": 3, "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/01fill_optional/makedict/base.json b/tests/dictionaries/01fill_optional/makedict/base.json index 86ba9458..b58d6e7c 100644 --- a/tests/dictionaries/01fill_optional/makedict/base.json +++ b/tests/dictionaries/01fill_optional/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif1": "non"} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif1": "non"} diff --git a/tests/dictionaries/10autosave_hidden/makedict/base.json b/tests/dictionaries/10autosave_hidden/makedict/base.json index 6f9b1c86..2a8f28f8 100644 --- a/tests/dictionaries/10autosave_hidden/makedict/base.json +++ b/tests/dictionaries/10autosave_hidden/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": "non", "rougail.general.autosavevar": null} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.autosavevar": "oui"} diff --git a/tests/dictionaries/10autosave_hidden_frozenifin/makedict/base.json b/tests/dictionaries/10autosave_hidden_frozenifin/makedict/base.json index 6f9b1c86..2a8f28f8 100644 --- a/tests/dictionaries/10autosave_hidden_frozenifin/makedict/base.json +++ b/tests/dictionaries/10autosave_hidden_frozenifin/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": "non", "rougail.general.autosavevar": null} +{"rougail.general.mode_conteneur_actif": "non", "rougail.general.autosavevar": "oui"} diff --git a/tests/dictionaries/10load_frozenifin_auto/makedict/base.json b/tests/dictionaries/10load_frozenifin_auto/makedict/base.json index 67a2eb8a..25db64a2 100644 --- a/tests/dictionaries/10load_frozenifin_auto/makedict/base.json +++ b/tests/dictionaries/10load_frozenifin_auto/makedict/base.json @@ -1 +1 @@ -{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": null, "rougail.general.mode_conteneur_actif2": "non"} +{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non"} diff --git a/tests/dictionaries/20family_dynamic_calc/makedict/base.json b/tests/dictionaries/20family_dynamic_calc/makedict/base.json index 82b6fff8..c26e3740 100644 --- a/tests/dictionaries/20family_dynamic_calc/makedict/base.json +++ b/tests/dictionaries/20family_dynamic_calc/makedict/base.json @@ -1 +1 @@ -{"rougail.general.varname": ["val1", "val2"], "rougail.dynval1.vardynval1": "val", "rougail.dynval2.vardynval2": "val", "rougail.new.newvar": null} +{"rougail.general.varname": ["val1", "val2"], "rougail.dynval1.vardynval1": "val", "rougail.dynval2.vardynval2": "val", "rougail.new.newvar": "val"} diff --git a/tests/dictionaries/20family_dynamic_number/makedict/base.json b/tests/dictionaries/20family_dynamic_number/makedict/base.json index 87a929d7..ceae633c 100644 --- a/tests/dictionaries/20family_dynamic_number/makedict/base.json +++ b/tests/dictionaries/20family_dynamic_number/makedict/base.json @@ -1 +1 @@ -{"rougail.general.varname": [1, 2], "rougail.dyn1.vardyn1": "val", "rougail.dyn2.vardyn2": "val", "rougail.new.newvar": null} +{"rougail.general.varname": [1, 2], "rougail.dyn1.vardyn1": "val", "rougail.dyn2.vardyn2": "val", "rougail.new.newvar": "val"} diff --git a/tests/dictionaries/30mandatory_withoutvaluecalc/makedict/base.json b/tests/dictionaries/30mandatory_withoutvaluecalc/makedict/base.json index dc0cf526..5f62f349 100644 --- a/tests/dictionaries/30mandatory_withoutvaluecalc/makedict/base.json +++ b/tests/dictionaries/30mandatory_withoutvaluecalc/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null} +{"rougail.general.mode_conteneur_actif": "value"} diff --git a/tests/dictionaries/30mandatory_withvaluecalc/makedict/base.json b/tests/dictionaries/30mandatory_withvaluecalc/makedict/base.json index dc0cf526..5f62f349 100644 --- a/tests/dictionaries/30mandatory_withvaluecalc/makedict/base.json +++ b/tests/dictionaries/30mandatory_withvaluecalc/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": null} +{"rougail.general.mode_conteneur_actif": "value"} diff --git a/tests/dictionaries/60action_external/makedict/base.json b/tests/dictionaries/60action_external/makedict/base.json index c2f531b4..0b1ab7e2 100644 --- a/tests/dictionaries/60action_external/makedict/base.json +++ b/tests/dictionaries/60action_external/makedict/base.json @@ -1 +1 @@ -{"rougail.general.mode_conteneur_actif": "non", "extra.test.delay": 0, "extra.test.calc_url": null} +{"rougail.general.mode_conteneur_actif": "non", "extra.test.delay": 0, "extra.test.calc_url": "http://localhost/"} diff --git a/tests/eosfunc/test.py b/tests/eosfunc/test.py index 887c9a8d..d258ac45 100644 --- a/tests/eosfunc/test.py +++ b/tests/eosfunc/test.py @@ -1,7 +1,8 @@ from tiramisu import valid_not_equal, valid_ip_netmask, calc_value def calc_val(*args, **kwargs): - pass + if len(args) > 0: + return args[0] def concat(*args, **kwargs): diff --git a/tests/test_2_makedict.py b/tests/test_2_makedict.py index 5657d98e..ba438859 100644 --- a/tests/test_2_makedict.py +++ b/tests/test_2_makedict.py @@ -45,6 +45,7 @@ async def launch_flattener(test_dir): config = await Config(mod.option_0) await config.property.read_only() await config.property.pop('mandatory') + await config.information.set('info', 'value') config_dict = await config.value.dict() if config_dict: if not isdir(makedict_dir): From 101dfefaa92e4255f566ac104deb180562792d6d Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 4 Oct 2020 15:11:44 +0200 Subject: [PATCH 3/7] dynamic variable and calculation --- doc/auto.rst | 23 ++ doc/fill.rst | 277 ++++++++++++++++++ doc/variable.rst | 13 + src/rougail/annotator.py | 22 +- src/rougail/data/rougail.dtd | 2 +- src/rougail/path.py | 4 + src/rougail/tiramisureflector.py | 4 +- tests/dictionaries/01fill_base/00-base.xml | 4 +- .../01fill_number/tiramisu/base.py | 12 - .../01fill_optional/tiramisu/base.py | 2 +- .../10autosave_hidden/tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../10leadership_append/tiramisu/base.py | 2 +- .../10leadership_auto/tiramisu/base.py | 2 +- .../10leadership_autoleader/tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../10leadership_multi/tiramisu/base.py | 2 +- .../10load_leadership/tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../20family_dynamic_calc/00-base.xml | 25 -- .../20family_dynamic_calc/makedict/base.json | 1 - .../20family_dynamic_calc/tiramisu/base.py | 15 - .../30mandatory_withoutvaluecalc/00-base.xml | 23 -- .../tiramisu/base.py | 11 - .../30mandatory_withvalue/makedict/base.json | 1 - .../30mandatory_withvaluecalc/00-base.xml | 21 -- .../tiramisu/base.py | 11 - .../40ifin_leadershipauto/tiramisu/base.py | 2 +- .../60action_external/tiramisu/base.py | 2 +- 34 files changed, 352 insertions(+), 151 deletions(-) create mode 100644 doc/auto.rst create mode 100644 doc/fill.rst create mode 100644 doc/variable.rst delete mode 100644 tests/dictionaries/01fill_number/tiramisu/base.py delete mode 100644 tests/dictionaries/20family_dynamic_calc/00-base.xml delete mode 100644 tests/dictionaries/20family_dynamic_calc/makedict/base.json delete mode 100644 tests/dictionaries/20family_dynamic_calc/tiramisu/base.py delete mode 100644 tests/dictionaries/30mandatory_withoutvaluecalc/00-base.xml delete mode 100644 tests/dictionaries/30mandatory_withoutvaluecalc/tiramisu/base.py delete mode 100644 tests/dictionaries/30mandatory_withvalue/makedict/base.json delete mode 100644 tests/dictionaries/30mandatory_withvaluecalc/00-base.xml delete mode 100644 tests/dictionaries/30mandatory_withvaluecalc/tiramisu/base.py diff --git a/doc/auto.rst b/doc/auto.rst new file mode 100644 index 00000000..322719f9 --- /dev/null +++ b/doc/auto.rst @@ -0,0 +1,23 @@ +Valeur automatiquement modifiée +=============================== + +Une variable avec valeur automatiquement modifiée est une variable dont la valeur sera considéré comme modifié quand le serveur sera déployé. + +Voici un variable a valeur automatiquement modifiée : + + + +Dans ce cas la valeur est fixée à la valeur actuelle. +Par exemple, si la valeur de cette variable est issue d'un calcul, la valeur ne sera plus recalculée. + +Valeur en lecture seule automatique +=================================== + +Une variable avec valeur en lecture seule automatique est une variable dont la valeur ne sera plus modifiable par l'utilisateur quand le serveur sera déployé. + +Voici un variable à valeur en lecture seule automatique : + + + +Dans ce cas la valeur est fixée à la valeur actuelle et elle ne sera plus modifiable par l'utilisateur. +Par exemple, si la valeur de cette variable est issue d'un calcul, la valeur ne sera plus recalculée. diff --git a/doc/fill.rst b/doc/fill.rst new file mode 100644 index 00000000..cdbf96f9 --- /dev/null +++ b/doc/fill.rst @@ -0,0 +1,277 @@ +Les variables calculées +======================= + +Une variable calculée est une variable donc sa valeur est le résultat d'une fonction python. + +Variable avec une valeur par défaut calculée +-------------------------------------------- + +Créons une variable de type "oui/non" donc la valeur est retournée par la fonction "return_no" : + + + + + + + + + + +Puis créons la fonction "return_no" : + + def return_no(): + return 'non' + +Dans ce cas, la valeur par défaut est la valeur retournée par la fonction (ici "non"), elle sera calculée tant que l'utilisateur n'a pas de spécifié une valeur à cette variable. + +Si l'utilisateur à définit une valeur par défaut à "my_calculated_variable" : + + + oui + + +Cette valeur par défaut sera complètement ignorée. + +Variable avec une valeur calculée +--------------------------------- + +En ajoutant le paramètre "hidden" à "True" dans la variable précédente, l'utilisateur n'aura plus la possibilité de modifié la valeur. La valeur de la variable sera donc systématiquement calculée : + +