83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
import os
|
|
from pytest import fixture, raises
|
|
from pathlib import Path
|
|
from rougail import Rougail, RougailConfig
|
|
#########################
|
|
from rougail.output_environment import RougailOutputEnvironment as RougailOutput
|
|
from json import load, dump
|
|
#########################
|
|
|
|
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict
|
|
|
|
EXT = "env"
|
|
|
|
|
|
excludes = [
|
|
]
|
|
|
|
test_ok = get_structures_list(excludes)
|
|
# test_ok = [Path('../rougail-tests/structures/60_5family_dynamic_calc_suffix_disabled2')]
|
|
|
|
|
|
def idfn(fixture_value):
|
|
return fixture_value.name
|
|
|
|
|
|
@fixture(scope="module", params=test_ok, ids=idfn)
|
|
def test_dir(request):
|
|
return request.param
|
|
|
|
|
|
def _test_structural_files(test_dir, namespace, ext, change=False):
|
|
rougailconfig = get_rougail_config(test_dir, namespace)
|
|
if not rougailconfig:
|
|
return
|
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
|
##################################
|
|
rougailconfig['step.output'] = 'environment'
|
|
dir_name = 'test'
|
|
if change:
|
|
rougailconfig["environment.output.prefix"] = "ROUGAIL_"
|
|
rougailconfig["environment.output.boolean_type"] = "number"
|
|
rougailconfig["environment.output.upper"] = False
|
|
rougailconfig["environment.output.path_is_variable_name"] = False
|
|
rougailconfig["environment.output.multi_in_array"] = False
|
|
dir_name += "_change"
|
|
##################################
|
|
if namespace:
|
|
dir_name += '_namespace'
|
|
elif (test_dir / 'force_namespace').is_file():
|
|
return
|
|
rougail = Rougail(rougailconfig)
|
|
config = rougail.run()
|
|
##################################
|
|
get_values_for_config(config, level="mandatory")
|
|
##################################
|
|
# loads variables in the tiramisu config
|
|
if change and (Path(__file__).parent / 'results' / dir_name / (test_dir.name + ".duplicate")).is_file():
|
|
return
|
|
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
|
output_file = Path(__file__).parent / 'results' / dir_name / (test_dir.name + "." + ext)
|
|
if not output_file.is_file():
|
|
if not output_file.parent.is_dir():
|
|
output_file.parent.mkdir()
|
|
with output_file.open('w') as outfh:
|
|
outfh.write(generated_output)
|
|
with output_file.open() as outfh:
|
|
attented_output = outfh.read()
|
|
assert generated_output == attented_output, f'filename {output_file}'
|
|
|
|
|
|
def test_structural_files(test_dir):
|
|
"tests the output"
|
|
_test_structural_files(test_dir, False, EXT)
|
|
|
|
|
|
def test_structural_files_namespace(test_dir):
|
|
"tests the output"
|
|
_test_structural_files(test_dir, True, EXT)
|
|
|
|
|
|
def test_structural_files_change(test_dir):
|
|
"tests the output"
|
|
_test_structural_files(test_dir, False, EXT, True)
|