diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 61dceb489..5a419f87a 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -47,6 +47,7 @@ class Annotator(Walk): # pylint: disable=R0903 self.objectspace = objectspace self.convert_value() self.valid_choices() + self.valid_regexp() def convert_value(self) -> None: """convert value""" @@ -114,7 +115,7 @@ class Annotator(Walk): # pylint: disable=R0903 if isinstance(variable.choices, Calculation): continue if variable.choices is None: - msg = f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice' + msg = _(f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice') raise DictConsistencyError(msg, 19, variable.xmlfiles) if not variable.mandatory and not variable.multi: self.add_choice_nil(variable) @@ -125,3 +126,11 @@ class Annotator(Walk): # pylint: disable=R0903 if choice is None: return variable.choices.append(None) + + def valid_regexp(self) -> None: + for variable in self.get_variables(): + if variable.type != "regexp": + continue + if variable.regexp is None: + msg = _(f'the variable "{variable.path}" is a "regexp" variable but don\'t have any regexp') + raise DictConsistencyError(msg, 66, variable.xmlfiles) diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index 3c1b445e0..9739fefef 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -156,6 +156,8 @@ class Annotator(Walk): # pylint: disable=R0903 variable.params = calculated_variable.params if variable.type == 'choice' and variable.choices is None: variable.choices = calculated_variable.choices + if variable.type == 'regexp' and variable.regexp is None: + variable.regexp = calculated_variable.regexp # copy multi attribut if variable.multi is None: calculated_path = calculated_variable.path diff --git a/tests/dictionaries/00_6choice_variable_link2/makedict/after.json b/tests/dictionaries/00_6choice_variable_link2/makedict/after.json new file mode 100644 index 000000000..7c66717d1 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/makedict/after.json @@ -0,0 +1,18 @@ +{ + "rougail.var1": { + "owner": "default", + "value": [ + "a", + "b", + "c" + ] + }, + "rougail.var2": { + "owner": "default", + "value": "a" + }, + "rougail.family.var3": { + "owner": "default", + "value": "a" + } +} diff --git a/tests/dictionaries/00_6choice_variable_link2/makedict/base.json b/tests/dictionaries/00_6choice_variable_link2/makedict/base.json new file mode 100644 index 000000000..17a8d1c94 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/makedict/base.json @@ -0,0 +1,9 @@ +{ + "rougail.var1": [ + "a", + "b", + "c" + ], + "rougail.var2": "a", + "rougail.family.var3": "a" +} diff --git a/tests/dictionaries/00_6choice_variable_link2/makedict/before.json b/tests/dictionaries/00_6choice_variable_link2/makedict/before.json new file mode 100644 index 000000000..7c66717d1 --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/makedict/before.json @@ -0,0 +1,18 @@ +{ + "rougail.var1": { + "owner": "default", + "value": [ + "a", + "b", + "c" + ] + }, + "rougail.var2": { + "owner": "default", + "value": "a" + }, + "rougail.family.var3": { + "owner": "default", + "value": "a" + } +} diff --git a/tests/dictionaries/00_6choice_variable_link2/makedict/mandatory.json b/tests/dictionaries/00_6choice_variable_link2/makedict/mandatory.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/tests/dictionaries/00_6choice_variable_link2/makedict/mandatory.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/dictionaries/00_6regexp_link/tiramisu/base.py b/tests/dictionaries/00_6regexp_link/tiramisu/base.py new file mode 100644 index 000000000..33db1163a --- /dev/null +++ b/tests/dictionaries/00_6regexp_link/tiramisu/base.py @@ -0,0 +1,26 @@ +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") +class Regexp_option_2(RegexpOption): + __slots__ = tuple() + _type = 'value' +Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$") + +class Regexp_option_3(RegexpOption): + __slots__ = tuple() + _type = 'value' +Regexp_option_3._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$") + +option_2 = Regexp_option_2(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')}) +option_3 = Regexp_option_3(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'}) +optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"standard"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) diff --git a/tests/dictionaries/00_6regexp_link/tiramisu/no_namespace.py b/tests/dictionaries/00_6regexp_link/tiramisu/no_namespace.py new file mode 100644 index 000000000..39181a6f3 --- /dev/null +++ b/tests/dictionaries/00_6regexp_link/tiramisu/no_namespace.py @@ -0,0 +1,21 @@ +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") +class Regexp_option_1(RegexpOption): + __slots__ = tuple() + _type = 'value' +Regexp_option_1._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$") + +class Regexp_option_2(RegexpOption): + __slots__ = tuple() + _type = 'value' +Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$") + +option_1 = Regexp_option_1(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')}) +option_2 = Regexp_option_2(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_1)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'}) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2]) diff --git a/tests/errors/20_test_regexp_without_regexp/errno_66 b/tests/errors/20_test_regexp_without_regexp/errno_66 new file mode 100644 index 000000000..e69de29bb diff --git a/tests/errors/20_test_regexp_without_regexp/rougail/00-rougail.yml b/tests/errors/20_test_regexp_without_regexp/rougail/00-rougail.yml new file mode 100644 index 000000000..de1fd94b1 --- /dev/null +++ b/tests/errors/20_test_regexp_without_regexp/rougail/00-rougail.yml @@ -0,0 +1,5 @@ +--- +version: '1.1' +var: + description: a first variable + type: regexp