diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index 0ee09c536..3c1b445e0 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -154,6 +154,8 @@ class Annotator(Walk): # pylint: disable=R0903 variable.type = calculated_variable.type if variable.params is None and calculated_variable.params is not None: variable.params = calculated_variable.params + if variable.type == 'choice' and variable.choices is None: + variable.choices = calculated_variable.choices # copy multi attribut if variable.multi is None: calculated_path = calculated_variable.path diff --git a/src/rougail/convert.py b/src/rougail/convert.py index 207af6085..eecece0e0 100644 --- a/src/rougail/convert.py +++ b/src/rougail/convert.py @@ -657,9 +657,10 @@ class ParserVariable: if comment: obj["description"] = comment if extra_attrs: - raise Exception( + raise DictConsistencyError( f'"{path}" is not a valid variable, there are additional ' - f'attributes: "{", ".join(extra_attrs)}"' + f'attributes: "{", ".join(extra_attrs)}"', + 65, [filename] ) self.parse_parameters( path, diff --git a/tests/dictionaries/00_6choice_link/makedict/after.json b/tests/dictionaries/00_6choice_link/makedict/after.json new file mode 100644 index 000000000..7ea9435a0 --- /dev/null +++ b/tests/dictionaries/00_6choice_link/makedict/after.json @@ -0,0 +1,10 @@ +{ + "rougail.var1": { + "owner": "default", + "value": null + }, + "rougail.var2": { + "owner": "default", + "value": null + } +} diff --git a/tests/dictionaries/00_6choice_link/makedict/base.json b/tests/dictionaries/00_6choice_link/makedict/base.json new file mode 100644 index 000000000..559aec2a4 --- /dev/null +++ b/tests/dictionaries/00_6choice_link/makedict/base.json @@ -0,0 +1,4 @@ +{ + "rougail.var1": null, + "rougail.var2": null +} diff --git a/tests/dictionaries/00_6choice_link/makedict/before.json b/tests/dictionaries/00_6choice_link/makedict/before.json new file mode 100644 index 000000000..7ea9435a0 --- /dev/null +++ b/tests/dictionaries/00_6choice_link/makedict/before.json @@ -0,0 +1,10 @@ +{ + "rougail.var1": { + "owner": "default", + "value": null + }, + "rougail.var2": { + "owner": "default", + "value": null + } +} diff --git a/tests/dictionaries/00_6choice_link/makedict/mandatory.json b/tests/dictionaries/00_6choice_link/makedict/mandatory.json new file mode 100644 index 000000000..8c67ac5f8 --- /dev/null +++ b/tests/dictionaries/00_6choice_link/makedict/mandatory.json @@ -0,0 +1 @@ +["rougail.var1", "rougail.var2"] \ No newline at end of file diff --git a/tests/dictionaries/00_6choice_link/tiramisu/base.py b/tests/dictionaries/00_6choice_link/tiramisu/base.py new file mode 100644 index 000000000..576b19de4 --- /dev/null +++ b/tests/dictionaries/00_6choice_link/tiramisu/base.py @@ -0,0 +1,16 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_2 = ChoiceOption(name="var1", doc="the first variable", values=("a", "b", "c"), properties=frozenset({"basic", "mandatory"}), informations={'type': 'choice'}) +option_3 = ChoiceOption(name="var2", doc="the second variable", values=("a", "b", "c"), default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"basic"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/00_6choice_link/tiramisu/no_namespace.py b/tests/dictionaries/00_6choice_link/tiramisu/no_namespace.py new file mode 100644 index 000000000..222ec60af --- /dev/null +++ b/tests/dictionaries/00_6choice_link/tiramisu/no_namespace.py @@ -0,0 +1,11 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = ChoiceOption(name="var1", doc="the first variable", values=("a", "b", "c"), properties=frozenset({"basic", "mandatory"}), informations={'type': 'choice'}) +option_2 = ChoiceOption(name="var2", doc="the second variable", values=("a", "b", "c"), default=Calculation(func['calc_value'], Params((ParamOption(option_1)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2]) diff --git a/tests/dictionaries/00_6choice_variable_link/makedict/after.json b/tests/dictionaries/00_6choice_variable_link/makedict/after.json new file mode 100644 index 000000000..d6d18ff9f --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/makedict/after.json @@ -0,0 +1,18 @@ +{ + "rougail.var1": { + "owner": "default", + "value": [ + "a", + "b", + "c" + ] + }, + "rougail.var2": { + "owner": "default", + "value": "a" + }, + "rougail.var3": { + "owner": "default", + "value": "a" + } +} diff --git a/tests/dictionaries/00_6choice_variable_link/makedict/base.json b/tests/dictionaries/00_6choice_variable_link/makedict/base.json new file mode 100644 index 000000000..cebf666bd --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/makedict/base.json @@ -0,0 +1,9 @@ +{ + "rougail.var1": [ + "a", + "b", + "c" + ], + "rougail.var2": "a", + "rougail.var3": "a" +} diff --git a/tests/dictionaries/00_6choice_variable_link/makedict/before.json b/tests/dictionaries/00_6choice_variable_link/makedict/before.json new file mode 100644 index 000000000..d6d18ff9f --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/makedict/before.json @@ -0,0 +1,18 @@ +{ + "rougail.var1": { + "owner": "default", + "value": [ + "a", + "b", + "c" + ] + }, + "rougail.var2": { + "owner": "default", + "value": "a" + }, + "rougail.var3": { + "owner": "default", + "value": "a" + } +} diff --git a/tests/dictionaries/00_6choice_variable_link/makedict/mandatory.json b/tests/dictionaries/00_6choice_variable_link/makedict/mandatory.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/makedict/mandatory.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/dictionaries/00_6choice_variable_link/tiramisu/base.py b/tests/dictionaries/00_6choice_variable_link/tiramisu/base.py new file mode 100644 index 000000000..0f5f43b47 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/tiramisu/base.py @@ -0,0 +1,17 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_2 = StrOption(name="var1", doc="a second variable", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_3 = ChoiceOption(name="var2", doc="a first variable", values=Calculation(func['calc_value'], Params((ParamOption(option_2)))), default="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_4 = ChoiceOption(name="var3", doc="a third variable", values=Calculation(func['calc_value'], Params((ParamOption(option_2)))), default=Calculation(func['calc_value'], Params((ParamOption(option_3)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3, option_4], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/00_6choice_variable_link/tiramisu/no_namespace.py b/tests/dictionaries/00_6choice_variable_link/tiramisu/no_namespace.py new file mode 100644 index 000000000..110c35cd5 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link/tiramisu/no_namespace.py @@ -0,0 +1,12 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = StrOption(name="var1", doc="a second variable", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_2 = ChoiceOption(name="var2", doc="a first variable", values=Calculation(func['calc_value'], Params((ParamOption(option_1)))), default="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_3 = ChoiceOption(name="var3", doc="a third variable", values=Calculation(func['calc_value'], Params((ParamOption(option_1)))), default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, option_3]) diff --git a/tests/dictionaries/00_6choice_variable_link2/tiramisu/base.py b/tests/dictionaries/00_6choice_variable_link2/tiramisu/base.py new file mode 100644 index 000000000..0c4777ecd --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/tiramisu/base.py @@ -0,0 +1,18 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +try: + groups.namespace +except: + groups.addgroup('namespace') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_2 = StrOption(name="var1", doc="a second variable", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_3 = ChoiceOption(name="var2", doc="a first variable", values=Calculation(func['calc_value'], Params((ParamOption(option_2)))), default="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_5 = ChoiceOption(name="var3", doc="a third variable", values=Calculation(func['calc_value'], Params((ParamOption(option_2)))), default=Calculation(func['calc_value'], Params((ParamOption(option_3)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +optiondescription_4 = OptionDescription(name="family", doc="family", children=[option_5], properties=frozenset({"standard"})) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3, optiondescription_4], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/00_6choice_variable_link2/tiramisu/no_namespace.py b/tests/dictionaries/00_6choice_variable_link2/tiramisu/no_namespace.py new file mode 100644 index 000000000..e82f547f7 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/tiramisu/no_namespace.py @@ -0,0 +1,13 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from re import compile as re_compile +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription +load_functions('../rougail-tests/funcs/test.py') +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = StrOption(name="var1", doc="a second variable", multi=True, default=["a", "b", "c"], default_multi="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'string'}) +option_2 = ChoiceOption(name="var2", doc="a first variable", values=Calculation(func['calc_value'], Params((ParamOption(option_1)))), default="a", properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +option_4 = ChoiceOption(name="var3", doc="a third variable", values=Calculation(func['calc_value'], Params((ParamOption(option_1)))), default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'choice'}) +optiondescription_3 = OptionDescription(name="family", doc="family", children=[option_4], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, optiondescription_3]) diff --git a/tests/dictionaries/00_6secret_param/makedict/after.json b/tests/dictionaries/00_6secret_param/makedict/after.json index ecb67a4b6..057aa53b1 100644 --- a/tests/dictionaries/00_6secret_param/makedict/after.json +++ b/tests/dictionaries/00_6secret_param/makedict/after.json @@ -6,5 +6,9 @@ "rougail.secret2": { "owner": "default", "value": "value" + }, + "rougail.secret3": { + "owner": "default", + "value": "value" } } diff --git a/tests/dictionaries/00_6secret_param/makedict/base.json b/tests/dictionaries/00_6secret_param/makedict/base.json index 1ae37c88a..6a958c0a3 100644 --- a/tests/dictionaries/00_6secret_param/makedict/base.json +++ b/tests/dictionaries/00_6secret_param/makedict/base.json @@ -1,4 +1,5 @@ { "rougail.secret1": null, - "rougail.secret2": "value" + "rougail.secret2": "value", + "rougail.secret3": "value" } diff --git a/tests/dictionaries/00_6secret_param/makedict/before.json b/tests/dictionaries/00_6secret_param/makedict/before.json index ecb67a4b6..057aa53b1 100644 --- a/tests/dictionaries/00_6secret_param/makedict/before.json +++ b/tests/dictionaries/00_6secret_param/makedict/before.json @@ -6,5 +6,9 @@ "rougail.secret2": { "owner": "default", "value": "value" + }, + "rougail.secret3": { + "owner": "default", + "value": "value" } } diff --git a/tests/dictionaries/00_6secret_param/tiramisu/base.py b/tests/dictionaries/00_6secret_param/tiramisu/base.py index b816ff617..9b5e88d5b 100644 --- a/tests/dictionaries/00_6secret_param/tiramisu/base.py +++ b/tests/dictionaries/00_6secret_param/tiramisu/base.py @@ -12,5 +12,6 @@ ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") option_2 = PasswordOption(name="secret1", doc="the first variable", min_len=10, properties=frozenset({"basic", "mandatory"}), informations={'type': 'secret'}) option_3 = PasswordOption(name="secret2", doc="the second variable", default="value", max_len=10, forbidden_char=['$', '^'], properties=frozenset({"mandatory", "standard"}), informations={'type': 'secret'}) -optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"basic"})) +option_4 = PasswordOption(name="secret3", doc="the third variable", default="value", max_len=10, forbidden_char=['$'], properties=frozenset({"mandatory", "standard"}), informations={'type': 'secret'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3, option_4], properties=frozenset({"basic"})) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/00_6secret_param/tiramisu/no_namespace.py b/tests/dictionaries/00_6secret_param/tiramisu/no_namespace.py index 09a1d2956..551203fa7 100644 --- a/tests/dictionaries/00_6secret_param/tiramisu/no_namespace.py +++ b/tests/dictionaries/00_6secret_param/tiramisu/no_namespace.py @@ -8,4 +8,5 @@ ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") option_1 = PasswordOption(name="secret1", doc="the first variable", min_len=10, properties=frozenset({"basic", "mandatory"}), informations={'type': 'secret'}) option_2 = PasswordOption(name="secret2", doc="the second variable", default="value", max_len=10, forbidden_char=['$', '^'], properties=frozenset({"mandatory", "standard"}), informations={'type': 'secret'}) -option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2]) +option_3 = PasswordOption(name="secret3", doc="the third variable", default="value", max_len=10, forbidden_char=['$'], properties=frozenset({"mandatory", "standard"}), informations={'type': 'secret'}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, option_3]) diff --git a/tests/errors/20_test_unknown_variable_disabled/errno_88 b/tests/errors/20_test_unknown_variable_disabled/errno_88 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/20_test_unknown_variable_disabled/rougail/00-rougail.yml b/tests/errors/20_test_unknown_variable_disabled/rougail/00-rougail.yml new file mode 100644 index 000000000..cf025fb44 --- /dev/null +++ b/tests/errors/20_test_unknown_variable_disabled/rougail/00-rougail.yml @@ -0,0 +1,8 @@ +--- +version: 1.1 + +variable: + description: a variable + disabled: + variable: _.unknown_variable + when: false diff --git a/tests/test_1_flattener.py b/tests/test_1_flattener.py index 7527461df..0c485b777 100644 --- a/tests/test_1_flattener.py +++ b/tests/test_1_flattener.py @@ -16,6 +16,7 @@ logger = logging.getLogger() logger.setLevel(logging.INFO) dico_dirs = Path('../rougail-tests/structures') +errors_dirs = Path('tests/errors') rougail_test_dirs = Path('tests/dictionaries') @@ -35,10 +36,11 @@ def get_rougail_tests_dir(original_dir): for test in dico_dirs.iterdir(): if test.is_dir(): - if rougail_test_dirs / 'test' / 'tiramisu': - test_ok.add(test.name) - elif test != '__pycache__': - test_raise.add(test.name) + test_ok.add(test.name) + +for test in errors_dirs.iterdir(): + if test.is_dir(): + test_raise.add(test.name) excludes = set([ '80family_several', @@ -124,7 +126,7 @@ def save(test_dir, eolobj, multi=False, namespace=False, error=False): tiramisu_dir = dirname(tiramisu_file) if not error: if not isdir(tiramisu_dir): - raise Exception(f'please creates {tiramisu_dir}') + makedirs(tiramisu_dir) if not isfile(tiramisu_file) or debug: copyfile(tiramisu_tmp, tiramisu_file) with open(tiramisu_tmp, 'r') as fh: @@ -168,30 +170,11 @@ def test_dictionary_namespace(test_dir): return save(test_dir_, eolobj, namespace=True) assert getcwd() == ORI_DIR -# -# -#def test_dictionary_multi(test_dir): -# if not test_multi: -# print('MULTI!') -# return -# assert getcwd() == ORI_DIR -# test_dir_ = join(dico_dirs, test_dir) -# rougailconfig = RougailConfig.copy() -# rougailconfig['main_namespace'] = 'Rougail' -# if (dico_dirs / test_dir / 'force_no_namespace').is_file(): -# return -# eolobj = load_rougail_object(test_dir_, rougailconfig, multi=True) -# if not eolobj: -# return -# eolobj.add_path_prefix('1') -# eolobj.add_path_prefix('2') -# save(test_dir_, eolobj, multi=True) -# assert getcwd() == ORI_DIR def test_error_dictionary(test_dir_error): assert getcwd() == ORI_DIR - test_dir_ = join(dico_dirs, test_dir_error) + test_dir_ = join(errors_dirs, test_dir_error) errno = [] rougailconfig = RougailConfig.copy() rougailconfig['main_namespace'] = 'Rougail'