109 lines
3.3 KiB
Python
109 lines
3.3 KiB
Python
from pytest import fixture # , raises
|
|
from pathlib import Path
|
|
from rougail import Rougail
|
|
from rougail.output_json import RougailOutputJson as RougailOutput
|
|
|
|
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
|
|
|
|
|
|
EXT = 'json'
|
|
|
|
|
|
excludes = []
|
|
#excludes = [
|
|
# '60_5family_dynamic_unknown_suffix',
|
|
# '60_5family_dynamic_variable_outside_sub_suffix',
|
|
#]
|
|
|
|
test_ok = get_structures_list(excludes)
|
|
#test_ok = [Path('../rougail-tests/structures/00_0version_underscore')]
|
|
|
|
|
|
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_dictionaries(test_dir, namespace, ext, *, read_write=True, mandatory=False, do_calc=True):
|
|
rougailconfig = get_rougail_config(test_dir, namespace)
|
|
if not rougailconfig:
|
|
return
|
|
##################################
|
|
rougailconfig['step.output'] = 'json'
|
|
rougailconfig["json.read_write"] = read_write
|
|
rougailconfig["json.mandatory"] = mandatory
|
|
##################################
|
|
dir_name = 'test'
|
|
if namespace:
|
|
dir_name += '_namespace'
|
|
elif (test_dir / 'force_namespace').is_file():
|
|
return
|
|
##################################
|
|
if read_write:
|
|
dir_name += '_read_write'
|
|
if mandatory:
|
|
dir_name += '_mandatory'
|
|
if not do_calc:
|
|
dir_name += '_errors'
|
|
##################################
|
|
rougail = Rougail(rougailconfig)
|
|
config = rougail.run()
|
|
##################################
|
|
if do_calc and (mandatory or not read_write):
|
|
get_values_for_config(config)
|
|
##################################
|
|
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()
|
|
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_dictionaries_json(test_dir):
|
|
_test_dictionaries(test_dir, True, EXT)
|
|
|
|
|
|
def test_dictionaries_json_errors(test_dir):
|
|
_test_dictionaries(test_dir, True, EXT, do_calc=False, mandatory=True)
|
|
|
|
|
|
def test_dictionaries_json_read_only(test_dir):
|
|
_test_dictionaries(test_dir, True, EXT, read_write=False)
|
|
|
|
|
|
def test_dictionaries_json_mandatory(test_dir):
|
|
_test_dictionaries(test_dir, True, EXT, mandatory=True)
|
|
|
|
|
|
def test_dictionaries_json_mandatory_read_only(test_dir):
|
|
_test_dictionaries(test_dir, True, EXT, read_write=False, mandatory=True)
|
|
|
|
|
|
#################
|
|
def test_dictionaries_json_namespace(test_dir):
|
|
_test_dictionaries(test_dir, False, EXT)
|
|
|
|
|
|
def test_dictionaries_json_namespace_errors(test_dir):
|
|
_test_dictionaries(test_dir, False, EXT, do_calc=False, mandatory=True)
|
|
|
|
|
|
def test_dictionaries_json_namespace_read_only(test_dir):
|
|
_test_dictionaries(test_dir, False, EXT, read_write=False)
|
|
|
|
|
|
def test_dictionaries_json_namespace_mandatory(test_dir):
|
|
_test_dictionaries(test_dir, False, EXT, mandatory=True)
|
|
|
|
|
|
def test_dictionaries_json_namespace_mandatory_read_only(test_dir):
|
|
_test_dictionaries(test_dir, False, EXT, read_write=False, mandatory=True)
|