diff --git a/src/rougail_tests/utils.py b/src/rougail_tests/utils.py index 4d34cf5..3cb9f9f 100644 --- a/src/rougail_tests/utils.py +++ b/src/rougail_tests/utils.py @@ -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 diff --git a/structures/00_1empty_variable/rougail/00-base.yml b/structures/00_1empty_variable/rougail/00-base.yml index 7bee2df..25e8eb9 100644 --- a/structures/00_1empty_variable/rougail/00-base.yml +++ b/structures/00_1empty_variable/rougail/00-base.yml @@ -1,3 +1,5 @@ +%YAML 1.2 --- -version: '1.0' +version: 1.1 empty: +... diff --git a/structures/01_6integer_multi_mandatory/rougail/00-base.yml b/structures/01_6integer_multi_mandatory/rougail/00-base.yml new file mode 100644 index 0000000..45f93b6 --- /dev/null +++ b/structures/01_6integer_multi_mandatory/rougail/00-base.yml @@ -0,0 +1,9 @@ +%YAML 1.2 +--- +version: 1.1 + +var: + description: the first variable + type: integer + multi: true +... diff --git a/structures/02_0tags/rougail/00-base.yml b/structures/02_0tags/rougail/00-base.yml new file mode 100644 index 0000000..1f15dbc --- /dev/null +++ b/structures/02_0tags/rougail/00-base.yml @@ -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 +... diff --git a/structures/04_5disabled_calculation_boolean/rougail/00-base.yml b/structures/04_5disabled_calculation_boolean/rougail/00-base.yml new file mode 100644 index 0000000..66dce68 --- /dev/null +++ b/structures/04_5disabled_calculation_boolean/rougail/00-base.yml @@ -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 diff --git a/structures/04_5validators_warnings/rougail/00-base.yml b/structures/04_5validators_warnings/rougail/00-base.yml new file mode 100644 index 0000000..dcd00f8 --- /dev/null +++ b/structures/04_5validators_warnings/rougail/00-base.yml @@ -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 +... diff --git a/structures/04_5validators_warnings_all/rougail/00-base.yml b/structures/04_5validators_warnings_all/rougail/00-base.yml new file mode 100644 index 0000000..4329cda --- /dev/null +++ b/structures/04_5validators_warnings_all/rougail/00-base.yml @@ -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 +... diff --git a/structures/60_0family_dynamic_source_hidden/rougail/00-base.yml b/structures/60_0family_dynamic_source_hidden/rougail/00-base.yml new file mode 100644 index 0000000..0ea8c74 --- /dev/null +++ b/structures/60_0family_dynamic_source_hidden/rougail/00-base.yml @@ -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 +... diff --git a/structures/60_5family_dynamic_calc_suffix_disabled/force_namespace b/structures/60_5family_dynamic_calc_suffix_disabled/force_namespace deleted file mode 100644 index e69de29..0000000 diff --git a/structures/60_5family_dynamic_calc_variable_disabled/rougail/00-base.yml b/structures/60_5family_dynamic_calc_variable_disabled/rougail/00-base.yml new file mode 100644 index 0000000..cddae1f --- /dev/null +++ b/structures/60_5family_dynamic_calc_variable_disabled/rougail/00-base.yml @@ -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' +... diff --git a/structures/60_5family_dynamic_calc_variable_disabled_outside/rougail/00-base.yml b/structures/60_5family_dynamic_calc_variable_disabled_outside/rougail/00-base.yml new file mode 100644 index 0000000..38339b1 --- /dev/null +++ b/structures/60_5family_dynamic_calc_variable_disabled_outside/rougail/00-base.yml @@ -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' +...