From d3559a7cfc45d32217d32680d7d000b6991c1d3c Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 7 Aug 2024 18:01:06 +0200 Subject: [PATCH] pouet --- src/rougail/object_model.py | 20 ++--- src/rougail/tiramisureflector.py | 14 ++-- .../tiramisu/base.py | 22 +++++- .../tiramisu/multi.py | 53 +++++++++++-- .../tiramisu/no_namespace.py | 16 ++++ .../tiramisu/base.py | 33 ++++++-- .../tiramisu/multi.py | 75 ++++++++++++++++--- .../tiramisu/no_namespace.py | 27 +++++++ 8 files changed, 214 insertions(+), 46 deletions(-) create mode 100644 tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/no_namespace.py create mode 100644 tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/no_namespace.py diff --git a/src/rougail/object_model.py b/src/rougail/object_model.py index 8685dc5cf..7dbadfba6 100644 --- a/src/rougail/object_model.py +++ b/src/rougail/object_model.py @@ -398,7 +398,6 @@ class _VariableCalculation(Calculation): variable: StrictStr propertyerror: bool = True allow_none: bool = False - optional: bool = False def get_variable(self, objectspace, @@ -491,17 +490,11 @@ class VariableCalculation(_VariableCalculation): self, objectspace, ) -> dict: - if self.attribute_name != "default" and self.optional is True: - msg = f'"{self.attribute_name}" variable shall not have an "optional" attribute for variable "{self.variable}"' - raise DictConsistencyError(msg, 33, self.xmlfiles) - variable, suffix = self.get_variable(objectspace) - if not variable and self.optional: - msg = f'the dependent variable was not found "{self.optional}" for attribute "{self.attribute_name}" in variable "{self.path}"' - raise VariableCalculationDependencyError(msg, 90, self.xmlfiles) - params = self.get_params(objectspace, - variable, - suffix, - ) + params = self.get_params(objectspace) + if self.attribute_name == "choices": + if hasattr(self, "optional") and self.optional is True: + msg = "'choices' variable shall not have an 'optional' atttibute" + raise DictConsistencyError(msg, 33, self.xmlfiles) return { "function": "calc_value", "params": params, @@ -611,6 +604,9 @@ class SuffixCalculation(_SuffixCalculation): self, objectspace, ) -> dict: + suffix = {"type": "suffix"} + if self.suffix is not None: + suffix["suffix"] = self.suffix return { "function": "calc_value", "params": {None: [self.get_suffix()]}, diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index ee493abf2..47298c4b8 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -478,13 +478,13 @@ class Variable(Common): keys["default"] = self.populate_calculation(self.elt.default) except VariableCalculationDependencyError: pass - for attribute in ["frozen", "hidden", "mandatory", "disabled"]: - if hasattr(self.elt, attribute): # FIXME FIXME and attribute == "optional": - raise DictConsistencyError( - f"Sub-attributes not allowed in a '{attribute}' attribute", - 100, - self.elt.xmlfiles, - ) + # for attribute in ["frozen", "hidden", "mandatory", "disabled"]: + # if hasattr(self.elt, attribute): # FIXME FIXME and attribute == "optional": + # raise DictConsistencyError( + # f"Sub-attributes not allowed in a '{attribute}' attribute", + # 100, + # self.elt.xmlfiles, + # ) if self.elt.path in self.objectspace.default_multi: try: keys["default_multi"] = self.populate_calculation( diff --git a/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/base.py b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/base.py index 9a8691b8d..704faff60 100644 --- a/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/base.py +++ b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/base.py @@ -1,10 +1,24 @@ from tiramisu import * from tiramisu.setting import ALLOWED_LEADER_PROPERTIES from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription -load_functions('tests/dictionaries/../eosfunc/test.py') + +load_functions("tests/dictionaries/../eosfunc/test.py") ALLOWED_LEADER_PROPERTIES.add("basic") ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") -option_2 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2], properties=frozenset({"standard"})) -option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) +option_2 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_1 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_2], + properties=frozenset({"standard"}), +) +option_0 = OptionDescription( + name="baseoption", doc="baseoption", children=[optiondescription_1] +) diff --git a/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/multi.py b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/multi.py index f11223bfd..6bee1bb59 100644 --- a/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/multi.py +++ b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/multi.py @@ -1,14 +1,51 @@ from tiramisu import * from tiramisu.setting import ALLOWED_LEADER_PROPERTIES from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription -load_functions('tests/dictionaries/../eosfunc/test.py') + +load_functions("tests/dictionaries/../eosfunc/test.py") ALLOWED_LEADER_PROPERTIES.add("basic") ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") -option_3 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[option_3], properties=frozenset({"standard"})) -optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"})) -option_6 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_5 = OptionDescription(name="rougail", doc="rougail", children=[option_6], properties=frozenset({"standard"})) -optiondescription_4 = OptionDescription(name="2", doc="2", children=[optiondescription_5], properties=frozenset({"standard"})) -option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_4]) +option_3 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_2 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_3], + properties=frozenset({"standard"}), +) +optiondescription_1 = OptionDescription( + name="1", + doc="1", + children=[optiondescription_2], + properties=frozenset({"standard"}), +) +option_6 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_5 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_6], + properties=frozenset({"standard"}), +) +optiondescription_4 = OptionDescription( + name="2", + doc="2", + children=[optiondescription_5], + properties=frozenset({"standard"}), +) +option_0 = OptionDescription( + name="baseoption", + doc="baseoption", + children=[optiondescription_1, optiondescription_4], +) diff --git a/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/no_namespace.py b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/no_namespace.py new file mode 100644 index 000000000..900cb0f70 --- /dev/null +++ b/tests/dictionaries/90_optional_parameter_in_variable_default/tiramisu/no_namespace.py @@ -0,0 +1,16 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription + +load_functions("tests/dictionaries/../eosfunc/test.py") +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) diff --git a/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/base.py b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/base.py index 1d6d218ea..324e229ad 100644 --- a/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/base.py +++ b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/base.py @@ -1,11 +1,34 @@ from tiramisu import * from tiramisu.setting import ALLOWED_LEADER_PROPERTIES from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription -load_functions('tests/dictionaries/../eosfunc/test.py') + +load_functions("tests/dictionaries/../eosfunc/test.py") ALLOWED_LEADER_PROPERTIES.add("basic") ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") -option_2 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"})) -option_3 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3], properties=frozenset({"standard"})) -option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1]) +option_2 = StrOption( + name="my_variable", + doc="my_variable", + multi=True, + default=["val1", "val2"], + default_multi="val1", + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_3 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + default=Calculation(func["calc_value"], Params((ParamOption(option_2)))), + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_1 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_2, option_3], + properties=frozenset({"standard"}), +) +option_0 = OptionDescription( + name="baseoption", doc="baseoption", children=[optiondescription_1] +) diff --git a/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/multi.py b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/multi.py index a6fb04cab..5eb82f46e 100644 --- a/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/multi.py +++ b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/multi.py @@ -1,16 +1,71 @@ from tiramisu import * from tiramisu.setting import ALLOWED_LEADER_PROPERTIES from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription -load_functions('tests/dictionaries/../eosfunc/test.py') + +load_functions("tests/dictionaries/../eosfunc/test.py") ALLOWED_LEADER_PROPERTIES.add("basic") ALLOWED_LEADER_PROPERTIES.add("standard") ALLOWED_LEADER_PROPERTIES.add("advanced") -option_3 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"})) -option_4 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_3)))), properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_2 = OptionDescription(name="rougail", doc="rougail", children=[option_3, option_4], properties=frozenset({"standard"})) -optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"standard"})) -option_7 = StrOption(name="my_variable", doc="my_variable", multi=True, default=["val1", "val2"], default_multi="val1", properties=frozenset({"mandatory", "notempty", "standard"})) -option_8 = StrOption(name="my_calculated_variable", doc="my_calculated_variable", multi=True, default=Calculation(func['calc_value'], Params((ParamOption(option_7)))), properties=frozenset({"mandatory", "notempty", "standard"})) -optiondescription_6 = OptionDescription(name="rougail", doc="rougail", children=[option_7, option_8], properties=frozenset({"standard"})) -optiondescription_5 = OptionDescription(name="2", doc="2", children=[optiondescription_6], properties=frozenset({"standard"})) -option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_5]) +option_3 = StrOption( + name="my_variable", + doc="my_variable", + multi=True, + default=["val1", "val2"], + default_multi="val1", + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_4 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + default=Calculation(func["calc_value"], Params((ParamOption(option_3)))), + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_2 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_3, option_4], + properties=frozenset({"standard"}), +) +optiondescription_1 = OptionDescription( + name="1", + doc="1", + children=[optiondescription_2], + properties=frozenset({"standard"}), +) +option_7 = StrOption( + name="my_variable", + doc="my_variable", + multi=True, + default=["val1", "val2"], + default_multi="val1", + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_8 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + default=Calculation(func["calc_value"], Params((ParamOption(option_7)))), + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +optiondescription_6 = OptionDescription( + name="rougail", + doc="Rougail", + children=[option_7, option_8], + properties=frozenset({"standard"}), +) +optiondescription_5 = OptionDescription( + name="2", + doc="2", + children=[optiondescription_6], + properties=frozenset({"standard"}), +) +option_0 = OptionDescription( + name="baseoption", + doc="baseoption", + children=[optiondescription_1, optiondescription_5], +) diff --git a/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/no_namespace.py b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/no_namespace.py new file mode 100644 index 000000000..37ec3f4fc --- /dev/null +++ b/tests/dictionaries/90_optional_parameter_in_variable_exists/tiramisu/no_namespace.py @@ -0,0 +1,27 @@ +from tiramisu import * +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES +from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription + +load_functions("tests/dictionaries/../eosfunc/test.py") +ALLOWED_LEADER_PROPERTIES.add("basic") +ALLOWED_LEADER_PROPERTIES.add("standard") +ALLOWED_LEADER_PROPERTIES.add("advanced") +option_1 = StrOption( + name="my_variable", + doc="my_variable", + multi=True, + default=["val1", "val2"], + default_multi="val1", + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_2 = StrOption( + name="my_calculated_variable", + doc="my_calculated_variable", + multi=True, + properties=frozenset({"mandatory", "notempty", "standard"}), + informations={"type": "string"}, +) +option_0 = OptionDescription( + name="baseoption", doc="baseoption", children=[option_1, option_2] +)