feat: add some tests
This commit is contained in:
parent
e7c157aa09
commit
e7f017c72e
11 changed files with 147 additions and 12 deletions
|
|
@ -5,8 +5,11 @@ from rougail import RougailConfig
|
|||
from .custom import CustomOption
|
||||
|
||||
|
||||
root_test_dir = Path(__file__).parent.parent.parent / 'structures'
|
||||
|
||||
|
||||
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():
|
||||
|
|
@ -14,7 +17,7 @@ def get_funcs():
|
|||
|
||||
|
||||
def get_rougail_config(test_dir, namespace=False, relative_to=None):
|
||||
rougailconfig = RougailConfig
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['functions_files'] = get_funcs()
|
||||
if relative_to:
|
||||
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:
|
||||
return None
|
||||
rougailconfig['extra_namespaces'] = extra_namespaces
|
||||
else:
|
||||
elif namespace:
|
||||
rougailconfig['extra_namespaces'] = {}
|
||||
rougailconfig['custom_types']['custom'] = CustomOption
|
||||
# rougailconfig['tiramisu_cache'] = "cache.py"
|
||||
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"
|
||||
|
||||
if use_unrestraint:
|
||||
|
|
@ -77,7 +80,7 @@ def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unre
|
|||
else:
|
||||
only = True
|
||||
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:
|
||||
for exclude in excludes:
|
||||
_values = values
|
||||
|
|
@ -103,7 +106,7 @@ def get_excludes(config, 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():
|
||||
return variable.value.get()
|
||||
tests = variable.information.get('test', None)
|
||||
|
|
@ -174,10 +177,12 @@ def get_value(variable, index, excludes, config, use_unrestraint):
|
|||
# tests = ""
|
||||
if index is not None and variable.isleader():
|
||||
tests = tests[index]
|
||||
if follower_with_index and variable.isfollower():
|
||||
tests = (index, 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):
|
||||
if key.name() == exclude_namespace:
|
||||
continue
|
||||
|
|
@ -191,19 +196,19 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
|
|||
leader_value = leader.value.get()
|
||||
leader_is_mandatory = False
|
||||
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
|
||||
has_value = False
|
||||
for idx_, val in enumerate(leader_value):
|
||||
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]:
|
||||
has_value = True
|
||||
if has_value:
|
||||
values[key.name()] = value
|
||||
else:
|
||||
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:
|
||||
values[key.name()] = value
|
||||
else:
|
||||
|
|
@ -218,7 +223,7 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
|
|||
if not only or mandatory:
|
||||
if key.index() is not None and index is not None and index != key.index():
|
||||
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:
|
||||
values[key.name()] = value
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
%YAML 1.2
|
||||
---
|
||||
version: '1.0'
|
||||
version: 1.1
|
||||
empty:
|
||||
...
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
%YAML 1.2
|
||||
---
|
||||
version: 1.1
|
||||
|
||||
var:
|
||||
description: the first variable
|
||||
type: integer
|
||||
multi: true
|
||||
...
|
||||
15
structures/02_0tags/rougail/00-base.yml
Normal file
15
structures/02_0tags/rougail/00-base.yml
Normal 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
|
||||
...
|
||||
|
|
@ -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
|
||||
15
structures/04_5validators_warnings/rougail/00-base.yml
Normal file
15
structures/04_5validators_warnings/rougail/00-base.yml
Normal 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
|
||||
...
|
||||
12
structures/04_5validators_warnings_all/rougail/00-base.yml
Normal file
12
structures/04_5validators_warnings_all/rougail/00-base.yml
Normal 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
|
||||
...
|
||||
|
|
@ -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
|
||||
...
|
||||
|
|
@ -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'
|
||||
...
|
||||
|
|
@ -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'
|
||||
...
|
||||
Loading…
Reference in a new issue