feat: add some tests

This commit is contained in:
egarette@silique.fr 2025-11-05 21:39:56 +01:00
parent e7c157aa09
commit e7f017c72e
11 changed files with 147 additions and 12 deletions

View file

@ -5,8 +5,11 @@ from rougail import RougailConfig
from .custom import CustomOption from .custom import CustomOption
root_test_dir = Path(__file__).parent.parent.parent / 'structures'
def get_structures_list(excludes): def get_structures_list(excludes):
return [test for test in sorted((Path(__file__).parent.parent.parent / 'structures').iterdir()) if test.name not in excludes] return [test for test in sorted(root_test_dir.iterdir()) if test.name not in excludes]
def get_funcs(): def get_funcs():
@ -14,7 +17,7 @@ def get_funcs():
def get_rougail_config(test_dir, namespace=False, relative_to=None): def get_rougail_config(test_dir, namespace=False, relative_to=None):
rougailconfig = RougailConfig rougailconfig = RougailConfig.copy()
rougailconfig['functions_files'] = get_funcs() rougailconfig['functions_files'] = get_funcs()
if relative_to: if relative_to:
dirs = [str((test_dir / 'rougail').relative_to(relative_to, walk_up=True))] dirs = [str((test_dir / 'rougail').relative_to(relative_to, walk_up=True))]
@ -54,14 +57,14 @@ def get_rougail_config(test_dir, namespace=False, relative_to=None):
if not namespace: if not namespace:
return None return None
rougailconfig['extra_namespaces'] = extra_namespaces rougailconfig['extra_namespaces'] = extra_namespaces
else: elif namespace:
rougailconfig['extra_namespaces'] = {} rougailconfig['extra_namespaces'] = {}
rougailconfig['custom_types']['custom'] = CustomOption rougailconfig['custom_types']['custom'] = CustomOption
# rougailconfig['tiramisu_cache'] = "cache.py" # rougailconfig['tiramisu_cache'] = "cache.py"
return rougailconfig return rougailconfig
def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unrestraint=True, exclude_namespace=None): def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unrestraint=True, exclude_namespace=None, follower_with_index=False):
# level is "all" or "mandatories" # level is "all" or "mandatories"
if use_unrestraint: if use_unrestraint:
@ -77,7 +80,7 @@ def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unre
else: else:
only = True only = True
values = {} values = {}
get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id, use_unrestraint, exclude_namespace) get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id, use_unrestraint, exclude_namespace, follower_with_index=follower_with_index)
if not specify_dynamic_id: if not specify_dynamic_id:
for exclude in excludes: for exclude in excludes:
_values = values _values = values
@ -103,7 +106,7 @@ def get_excludes(config, excludes):
get_excludes(option, excludes) get_excludes(option, excludes)
def get_value(variable, index, excludes, config, use_unrestraint): def get_value(variable, index, excludes, config, use_unrestraint, follower_with_index):
if 'force_store_value' in variable.property.get(): if 'force_store_value' in variable.property.get():
return variable.value.get() return variable.value.get()
tests = variable.information.get('test', None) tests = variable.information.get('test', None)
@ -174,10 +177,12 @@ def get_value(variable, index, excludes, config, use_unrestraint):
# tests = "" # tests = ""
if index is not None and variable.isleader(): if index is not None and variable.isleader():
tests = tests[index] tests = tests[index]
if follower_with_index and variable.isfollower():
tests = (index, tests)
return tests return tests
def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, use_unrestraint, exclude_namespace, *, index=None, leader_is_mandatory=False): def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, use_unrestraint, exclude_namespace, *, index=None, leader_is_mandatory=False, follower_with_index=False):
for idx, key in enumerate(config): for idx, key in enumerate(config):
if key.name() == exclude_namespace: if key.name() == exclude_namespace:
continue continue
@ -191,19 +196,19 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
leader_value = leader.value.get() leader_value = leader.value.get()
leader_is_mandatory = False leader_is_mandatory = False
else: else:
leader_value = get_value(leader, None, excludes, root_config, use_unrestraint) leader_value = get_value(leader, None, excludes, root_config, use_unrestraint, follower_with_index)
leader_is_mandatory = True leader_is_mandatory = True
has_value = False has_value = False
for idx_, val in enumerate(leader_value): for idx_, val in enumerate(leader_value):
value.append({}) value.append({})
get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, use_unrestraint, None, index=idx_, leader_is_mandatory=leader_is_mandatory) get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, use_unrestraint, None, index=idx_, leader_is_mandatory=leader_is_mandatory, follower_with_index=follower_with_index)
if value[-1]: if value[-1]:
has_value = True has_value = True
if has_value: if has_value:
values[key.name()] = value values[key.name()] = value
else: else:
value = {} value = {}
get_variables(root_config, key, value, only, excludes, specify_dynamic_id, use_unrestraint, None) get_variables(root_config, key, value, only, excludes, specify_dynamic_id, use_unrestraint, None, follower_with_index=follower_with_index)
if value: if value:
values[key.name()] = value values[key.name()] = value
else: else:
@ -218,7 +223,7 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
if not only or mandatory: if not only or mandatory:
if key.index() is not None and index is not None and index != key.index(): if key.index() is not None and index is not None and index != key.index():
continue continue
value = get_value(key, index, excludes, root_config, use_unrestraint) value = get_value(key, index, excludes, root_config, use_unrestraint, follower_with_index)
if specify_dynamic_id or key.path(uncalculated=True) not in excludes: if specify_dynamic_id or key.path(uncalculated=True) not in excludes:
values[key.name()] = value values[key.name()] = value

View file

@ -1,3 +1,5 @@
%YAML 1.2
--- ---
version: '1.0' version: 1.1
empty: empty:
...

View file

@ -0,0 +1,9 @@
%YAML 1.2
---
version: 1.1
var:
description: the first variable
type: integer
multi: true
...

View file

@ -0,0 +1,15 @@
%YAML 1.2
---
version: 1.1
var1:
description: the first variable
tags:
- one_tag
var2:
description: the second variable
tags:
- one_tag
- second_tag
...

View file

@ -0,0 +1,21 @@
%YAML 1.2
---
version: 1.1
condition: "no" # a conditional variable
variable1:
description: a first variable
disabled:
jinja: |-
{{ _.condition == "yes" }}
description: if condition is egal to "yes"
return_type: boolean
variable2:
description: a seconde variable
disabled:
jinja: |-
{{ _.condition != "yes" }}
description: if condition is not egal to "yes"
return_type: boolean

View file

@ -0,0 +1,15 @@
%YAML 1.2
---
version: 1.1
int:
description: An integer
default: 1000
validators:
- jinja: |-
{% if _.int > 100 %}
value is too high
{% endif %}
description: the max value is 100
warnings: true
...

View file

@ -0,0 +1,12 @@
%YAML 1.2
---
version: 1.1
int:
description: An integer
default: 1000
params:
min_integer: 10
max_integer: 100
warnings: true
...

View file

@ -0,0 +1,18 @@
%YAML 1.2
---
version: 1.1
var:
description: A suffix variable
default:
- val1
- val2
hidden: true
dyn{{ identifier }}:
description: A dynamic family
dynamic:
variable: _.var
var: # A dynamic variable
...

View file

@ -0,0 +1,19 @@
%YAML 1.2
---
version: 1.1
dyn{{ identifier }}:
description: A dynamic famify for {{ identifier }}
dynamic:
- val1
- val2
var1:
description: A dynamic variable
var2:
description: A new variable
disabled:
variable: _.var1
when: 'val1'
...

View file

@ -0,0 +1,19 @@
%YAML 1.2
---
version: 1.1
dyn{{ identifier }}:
description: A dynamic famify for {{ identifier }}
dynamic:
- val1
- val2
var1:
description: A dynamic variable
var2:
description: A new variable
disabled:
variable: _.dynval1.var1
when: 'val1'
...