Quick definition of an optional parameter variable #24
8 changed files with 214 additions and 46 deletions
|
@ -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()]},
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -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],
|
||||
)
|
||||
|
|
|
@ -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])
|
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -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],
|
||||
)
|
||||
|
|
|
@ -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]
|
||||
)
|
Loading…
Reference in a new issue