2024-07-10 21:27:48 +02:00
|
|
|
from pytest import fixture # , raises
|
|
|
|
from pathlib import Path
|
|
|
|
from ruamel.yaml import YAML
|
|
|
|
from rougail import RougailConfig
|
|
|
|
from rougail.output_doc import RougailOutputDoc
|
|
|
|
|
|
|
|
from .custom import CustomOption
|
|
|
|
|
|
|
|
|
|
|
|
dico_dirs = Path('../rougail/tests/dictionaries')
|
|
|
|
test_ok = set()
|
|
|
|
|
|
|
|
excludes = set([
|
|
|
|
'60_5family_dynamic_unknown_suffix',
|
|
|
|
'60_5family_dynamic_variable_outside_sub_suffix',
|
|
|
|
])
|
|
|
|
|
|
|
|
for test in dico_dirs.iterdir():
|
|
|
|
if (test / 'tiramisu').is_dir() and test.name not in excludes:
|
2024-11-15 08:13:45 +01:00
|
|
|
test_ok.add(test.name)
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
test_ok = list(test_ok)
|
|
|
|
test_ok.sort()
|
|
|
|
|
2024-11-15 08:13:45 +01:00
|
|
|
# test_ok = ['00_9default_calculation_multi_optional2']
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@fixture(scope="module", params=test_ok)
|
|
|
|
def test_dir(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2024-11-15 08:13:45 +01:00
|
|
|
def _test_dictionaries(test, output, namespace, examples=False):
|
|
|
|
test_dir = dico_dirs / test
|
2024-07-10 21:27:48 +02:00
|
|
|
rougailconfig = RougailConfig.copy()
|
|
|
|
rougailconfig['step.output'] = 'doc'
|
|
|
|
rougailconfig['doc.output_format'] = output
|
|
|
|
rougailconfig['functions_files'] = [str(dico_dirs.parent / 'eosfunc' / 'test.py')]
|
2024-11-15 08:13:45 +01:00
|
|
|
if examples:
|
|
|
|
rougailconfig['doc.with_example'] = True
|
|
|
|
else:
|
|
|
|
rougailconfig['doc.with_example'] = False
|
2024-07-10 21:27:48 +02:00
|
|
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
|
|
|
dirs = [str(test_dir / 'dictionaries' / 'rougail')]
|
|
|
|
subfolder = test_dir / 'dictionaries' / 'rougail2'
|
|
|
|
if subfolder.is_dir():
|
|
|
|
dirs.append(str(subfolder))
|
|
|
|
rougailconfig['main_dictionaries'] = dirs
|
|
|
|
if namespace:
|
|
|
|
rougailconfig['main_namespace'] = 'Rougail'
|
|
|
|
else:
|
|
|
|
rougailconfig['main_namespace'] = None
|
|
|
|
extra_dictionaries = {}
|
|
|
|
extras = list((test_dir / 'dictionaries').iterdir())
|
|
|
|
extras.sort()
|
|
|
|
for extra in extras:
|
|
|
|
if extra.name in ['rougail', 'rougail2']:
|
|
|
|
continue
|
|
|
|
if extra.is_dir():
|
|
|
|
extra_dictionaries[extra.name] = [str(extra)]
|
|
|
|
if extra_dictionaries:
|
|
|
|
rougailconfig['extra_dictionaries'] = extra_dictionaries
|
|
|
|
rougailconfig['custom_types']['custom'] = CustomOption
|
|
|
|
inventory = RougailOutputDoc(rougailconfig=rougailconfig)
|
2024-11-15 08:13:45 +01:00
|
|
|
try:
|
|
|
|
doc = inventory.formater.header()
|
|
|
|
except:
|
|
|
|
doc = ''
|
2024-07-10 21:27:48 +02:00
|
|
|
yaml = YAML()
|
|
|
|
len_subdir = len(str(dico_dirs)) + 1
|
|
|
|
if extra_dictionaries:
|
|
|
|
all_dirs = [[rougailconfig['main_dictionaries']], rougailconfig['extra_dictionaries'].values()]
|
|
|
|
else:
|
|
|
|
all_dirs = [[rougailconfig['main_dictionaries']]]
|
|
|
|
for r in all_dirs:
|
|
|
|
for dirs in r:
|
|
|
|
for d in dirs:
|
|
|
|
for f in Path(d).iterdir():
|
|
|
|
if f.name.endswith('.yml') or f.name.endswith('.yaml'):
|
2024-11-15 08:13:45 +01:00
|
|
|
try:
|
|
|
|
doc += inventory.formater.title(str(f)[len_subdir:].split('/', 1)[-1], 1)
|
|
|
|
except:
|
|
|
|
pass
|
2024-07-10 21:27:48 +02:00
|
|
|
with f.open(encoding="utf8") as file_fh:
|
|
|
|
objects = yaml.load(file_fh)
|
2024-11-15 08:13:45 +01:00
|
|
|
try:
|
|
|
|
doc += inventory.formater.yaml(objects)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if examples:
|
|
|
|
name = 'examples'
|
|
|
|
doc += inventory.gen_doc_examples()
|
2024-07-10 21:27:48 +02:00
|
|
|
else:
|
2024-11-15 08:13:45 +01:00
|
|
|
if namespace:
|
|
|
|
name = 'base'
|
|
|
|
else:
|
|
|
|
name = 'no_namespace'
|
|
|
|
doc += inventory.gen_doc()
|
|
|
|
doc_file = Path('tests') / 'docs' / name / (test_dir.name + {'github': '.md', 'asciidoc': '.adoc', 'json': '.json'}.get(output))
|
2024-11-07 22:51:28 +01:00
|
|
|
if not doc_file.is_file():
|
|
|
|
with doc_file.open('w') as docfh:
|
|
|
|
docfh.write(doc)
|
|
|
|
with doc_file.open() as docfh:
|
|
|
|
result = docfh.read()
|
|
|
|
assert doc == result
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
|
2024-11-15 08:13:45 +01:00
|
|
|
def test_dictionaries_json(test_dir):
|
|
|
|
_test_dictionaries(test_dir, 'json', True)
|
|
|
|
|
|
|
|
|
2024-07-10 21:27:48 +02:00
|
|
|
def test_dictionaries_github(test_dir):
|
|
|
|
_test_dictionaries(test_dir, 'github', True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_dictionaries_asciidoc(test_dir):
|
|
|
|
_test_dictionaries(test_dir, 'asciidoc', True)
|
|
|
|
|
|
|
|
|
2024-11-15 08:13:45 +01:00
|
|
|
def test_dictionaries_examples(test_dir):
|
|
|
|
_test_dictionaries(test_dir, 'github', True, True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_dictionaries_json_no_namespace(test_dir):
|
|
|
|
if (dico_dirs / test_dir / 'force_namespace').is_file():
|
|
|
|
return
|
|
|
|
_test_dictionaries(test_dir, 'json', False)
|
|
|
|
|
|
|
|
|
2024-07-10 21:27:48 +02:00
|
|
|
def test_dictionaries_github_no_namespace(test_dir):
|
2024-11-15 08:13:45 +01:00
|
|
|
if (dico_dirs / test_dir / 'force_namespace').is_file():
|
2024-07-10 21:27:48 +02:00
|
|
|
return
|
|
|
|
_test_dictionaries(test_dir, 'github', False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_dictionaries_asciidoc_no_namespace(test_dir):
|
2024-11-15 08:13:45 +01:00
|
|
|
if (dico_dirs / test_dir / 'force_namespace').is_file():
|
2024-07-10 21:27:48 +02:00
|
|
|
return
|
|
|
|
_test_dictionaries(test_dir, 'asciidoc', False)
|