From 13ea60ab7e833ba32a4876d7622eac7e400c8f97 Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 23 Sep 2024 14:34:15 +0200 Subject: [PATCH] tests --- tests/test_load.py | 138 +++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 80 deletions(-) diff --git a/tests/test_load.py b/tests/test_load.py index e3ac952..f826f8a 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -1,28 +1,32 @@ -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 +from pathlib import Path + +from pytest import fixture # , raises +from ruamel.yaml import YAML + +from rougail import RougailConfig, Rougail +#from tiramisu import Config + +#from rougail.output_doc import RougailOutputDoc + dico_dirs = Path('../rougail/tests/dictionaries') -test_ok = set() +#test_ok = set() -excludes = set([ - '60_5family_dynamic_unknown_suffix', - '60_5family_dynamic_variable_outside_sub_suffix', -]) +#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: - test_ok.add(test) +#for test in dico_dirs.iterdir(): +# if (test / 'tiramisu').is_dir() and test.name not in excludes: +# test_ok.add(test) -test_ok = list(test_ok) -test_ok.sort() +#test_ok = list(test_ok) +#test_ok.sort() -# test_ok = [dico_dirs / '60_0family_dynamic_variable_suffix'] +test_ok = [dico_dirs / '60_0family_dynamic_variable_suffix'] @fixture(scope="module", params=test_ok) @@ -30,74 +34,48 @@ def test_dir(request): return request.param -def _test_dictionaries(test_dir, output, namespace): +def _test_dictionaries(test_dir): rougailconfig = RougailConfig.copy() - rougailconfig['step.output'] = 'doc' - rougailconfig['doc.output_format'] = output - rougailconfig['functions_files'] = [str(dico_dirs.parent / 'eosfunc' / 'test.py')] -# rougailconfig['tiramisu_cache'] = "cache.py" +# rougailconfig['step.output'] = 'environment' 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) - doc = inventory.formater.header() - 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'): - doc += inventory.formater.title(str(f)[len_subdir:].split('/', 1)[-1], 1) - with f.open(encoding="utf8") as file_fh: - objects = yaml.load(file_fh) - doc += inventory.formater.yaml(objects) - doc += inventory.gen_doc() - if namespace: - name = 'base' - else: - name = 'no_namespace' - doc_file = Path('tests') / 'docs' / name / (test_dir.name + {'github': '.md', 'asciidoc': '.adoc'}.get(output)) - with doc_file.open('w') as docfh: - docfh.write(doc) + rougailconfig['main_dictionaries'] = dirs + return rougailconfig + +#def option_value(parent, key_is_option=False): +# for option, value in parent.items(): +# if option.isoptiondescription(): +# if not key_is_option and option.isleadership(): +# ret = [] +# for idx, datas in enumerate(option_value(value, key_is_option=True)): +# sub_option, sub_value = datas +# if not idx: +# sub_option = sub_option.path() +# key = sub_option +# for val in sub_value: +# ret.append({sub_option: val}) +# else: +# index = sub_option.index() +# sub_option = sub_option.path() +# ret[index][sub_option] = sub_value +# yield key, ret +# else: +# yield from option_value(value, key_is_option) +# elif key_is_option: +# yield option, value +# else: +# yield option.path(), value -def test_dictionaries_github(test_dir): - _test_dictionaries(test_dir, 'github', True) +def test_dictionaries_warning(test_dir): + rougailconfig = _test_dictionaries(test_dir) + # loads the config in the tiramisu's meaning + config = Rougail(rougailconfig).run() #Config(optiondescription["option_0"]) + print(type(config)) +# config_dict = dict(option_value(config.value.get())) +# print(config_dict) -def test_dictionaries_asciidoc(test_dir): - _test_dictionaries(test_dir, 'asciidoc', True) - -def test_dictionaries_github_no_namespace(test_dir): - if (test_dir / 'force_namespace').is_file(): - return - _test_dictionaries(test_dir, 'github', False) - - -def test_dictionaries_asciidoc_no_namespace(test_dir): - if (test_dir / 'force_namespace').is_file(): - return - _test_dictionaries(test_dir, 'asciidoc', False) +#def test_dictionaries_asciidoc(test_dir): +# _test_dictionaries(test_dir, 'asciidoc', True)