add 'whole' attribute to variable

This commit is contained in:
egarette@silique.fr 2024-08-25 12:22:22 +02:00 committed by gwen
parent 90ef65dd40
commit 9e614eb7a4
22 changed files with 171 additions and 7 deletions

View file

@ -132,6 +132,7 @@ class VariableParam(Param):
type: str
variable: str
propertyerror: bool = True
whole: bool = False
optional: bool = False

View file

@ -41,10 +41,9 @@ from .utils import normalize_family
global func
func = {}
dict_env = {}
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
ENV.filters = func
func = ENV.filters
ENV.compile_templates('jinja_caches', zip=None)

View file

@ -332,6 +332,7 @@ class Common:
param.get("propertyerror", True),
param.get("suffix"),
param.get("dynamic"),
param.get('whole', False),
)
if param["type"] == "any":
if isinstance(param["value"], str):
@ -343,15 +344,19 @@ class Common:
def build_option_param(
self,
param,
variable,
propertyerror,
suffix: Optional[str],
dynamic,
whole: bool,
) -> str:
"""build variable parameters"""
if param.path == self.elt.path:
return "ParamSelfOption(whole=False)"
option_name = self.tiramisu.reflector_objects[param.path].get(
if variable.path == self.elt.path:
return f"ParamSelfOption(whole={whole})"
if whole:
msg = f'variable param "{variable.path}" has whole attribute but it\'s not allowed for external variable'
raise DictConsistencyError(msg, 34, self.elt.xmlfiles)
option_name = self.tiramisu.reflector_objects[variable.path].get(
self.calls, self.elt.path
)
params = [f"{option_name}"]

View file

@ -0,0 +1,15 @@
---
version: 1.1
var1:
description: a second variable
multi: true
default:
- 'no'
- 'yes'
validators:
- type: jinja
jinja: |
{% if _.var1 | length > 9 %}
length must be less than 10
{% endif %}
description: check length is less than 10

View file

@ -0,0 +1,9 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"no",
"yes"
]
}
}

View file

@ -0,0 +1,6 @@
{
"rougail.var1": [
"no",
"yes"
]
}

View file

@ -0,0 +1,9 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"no",
"yes"
]
}
}

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1,11 @@
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")
dict_env['validators_rougail.var1'] = "{% if _.var1 | length > 9 %}\nlength must be less than 10\n{% endif %}\n"
option_2 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var1': ParamSelfOption(whole=False)}))], 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])

View file

@ -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")
dict_env['validators_1.rougail.var1'] = "{% if _.var1 | length > 9 %}\nlength must be less than 10\n{% endif %}\n"
dict_env['validators_2.rougail.var1'] = "{% if _.var1 | length > 9 %}\nlength must be less than 10\n{% endif %}\n"
option_3 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_1.rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var1': ParamSelfOption(whole=False)}))], 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="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_2.rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_.var1': ParamSelfOption(whole=False)}))], 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])

View file

@ -0,0 +1,10 @@
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")
dict_env['validators_var1'] = "{% if _.var1 | length > 9 %}\nlength must be less than 10\n{% endif %}\n"
option_1 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), '_': ParamValue({}), '_.var1': ParamSelfOption(whole=False)}))], properties=frozenset({"mandatory", "notempty", "standard"}), informations={'type': 'string'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -0,0 +1,20 @@
---
version: 1.1
var1:
description: a second variable
multi: true
default:
- 'no'
- 'yes'
validators:
- type: jinja
params:
values:
type: variable
variable: _.var1
whole: true
jinja: |
{% if values | length > 2 %}
length must be less than 3
{% endif %}
description: check length is less than 3

View file

@ -0,0 +1,9 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"no",
"yes"
]
}
}

View file

@ -0,0 +1,6 @@
{
"rougail.var1": [
"no",
"yes"
]
}

View file

@ -0,0 +1,9 @@
{
"rougail.var1": {
"owner": "default",
"value": [
"no",
"yes"
]
}
}

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1,11 @@
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")
dict_env['validators_rougail.var1'] = "{% if values | length > 2 %}\nlength must be less than 3\n{% endif %}\n"
option_2 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'values': ParamSelfOption(whole=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])

View file

@ -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")
dict_env['validators_1.rougail.var1'] = "{% if values | length > 2 %}\nlength must be less than 3\n{% endif %}\n"
dict_env['validators_2.rougail.var1'] = "{% if values | length > 2 %}\nlength must be less than 3\n{% endif %}\n"
option_3 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_1.rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'values': ParamSelfOption(whole=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="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_2.rougail.var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'values': ParamSelfOption(whole=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])

View file

@ -0,0 +1,10 @@
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")
dict_env['validators_var1'] = "{% if values | length > 2 %}\nlength must be less than 3\n{% endif %}\n"
option_1 = StrOption(name="var1", doc="a second variable", multi=True, default=["no", "yes"], default_multi="no", validators=[Calculation(func['valid_with_jinja'], Params((), kwargs={'__internal_jinja': ParamValue("validators_var1"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'values': ParamSelfOption(whole=True)}))], properties=frozenset({"mandatory", "notempty", "standard"}), informations={'type': 'string'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -180,7 +180,7 @@ def test_error_dictionary(test_dir_error):
errno = []
rougailconfig = RougailConfig.copy()
rougailconfig['main_namespace'] = 'Rougail'
eolobj = load_rougail_object(test_dir_, rougailconfig)
eolobj = load_rougail_object(test_dir_, rougailconfig, namespace=True)
if eolobj is None:
return
for i in listdir(test_dir_):