This commit is contained in:
gwen 2024-09-23 14:34:15 +02:00
parent 7f684290b8
commit 13ea60ab7e

View file

@ -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 .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') dico_dirs = Path('../rougail/tests/dictionaries')
test_ok = set() #test_ok = set()
excludes = set([ #excludes = set([
'60_5family_dynamic_unknown_suffix', # '60_5family_dynamic_unknown_suffix',
'60_5family_dynamic_variable_outside_sub_suffix', # '60_5family_dynamic_variable_outside_sub_suffix',
]) #])
for test in dico_dirs.iterdir(): #for test in dico_dirs.iterdir():
if (test / 'tiramisu').is_dir() and test.name not in excludes: # if (test / 'tiramisu').is_dir() and test.name not in excludes:
test_ok.add(test) # test_ok.add(test)
test_ok = list(test_ok) #test_ok = list(test_ok)
test_ok.sort() #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) @fixture(scope="module", params=test_ok)
@ -30,74 +34,48 @@ def test_dir(request):
return request.param return request.param
def _test_dictionaries(test_dir, output, namespace): def _test_dictionaries(test_dir):
rougailconfig = RougailConfig.copy() rougailconfig = RougailConfig.copy()
rougailconfig['step.output'] = 'doc' # rougailconfig['step.output'] = 'environment'
rougailconfig['doc.output_format'] = output
rougailconfig['functions_files'] = [str(dico_dirs.parent / 'eosfunc' / 'test.py')]
# rougailconfig['tiramisu_cache'] = "cache.py"
dirs = [str(test_dir / 'dictionaries' / 'rougail')] 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 rougailconfig['custom_types']['custom'] = CustomOption
inventory = RougailOutputDoc(rougailconfig=rougailconfig) rougailconfig['main_dictionaries'] = dirs
doc = inventory.formater.header() return rougailconfig
yaml = YAML()
len_subdir = len(str(dico_dirs)) + 1 #def option_value(parent, key_is_option=False):
if extra_dictionaries: # for option, value in parent.items():
all_dirs = [[rougailconfig['main_dictionaries']], rougailconfig['extra_dictionaries'].values()] # if option.isoptiondescription():
else: # if not key_is_option and option.isleadership():
all_dirs = [[rougailconfig['main_dictionaries']]] # ret = []
for r in all_dirs: # for idx, datas in enumerate(option_value(value, key_is_option=True)):
for dirs in r: # sub_option, sub_value = datas
for d in dirs: # if not idx:
for f in Path(d).iterdir(): # sub_option = sub_option.path()
if f.name.endswith('.yml') or f.name.endswith('.yaml'): # key = sub_option
doc += inventory.formater.title(str(f)[len_subdir:].split('/', 1)[-1], 1) # for val in sub_value:
with f.open(encoding="utf8") as file_fh: # ret.append({sub_option: val})
objects = yaml.load(file_fh) # else:
doc += inventory.formater.yaml(objects) # index = sub_option.index()
doc += inventory.gen_doc() # sub_option = sub_option.path()
if namespace: # ret[index][sub_option] = sub_value
name = 'base' # yield key, ret
else: # else:
name = 'no_namespace' # yield from option_value(value, key_is_option)
doc_file = Path('tests') / 'docs' / name / (test_dir.name + {'github': '.md', 'asciidoc': '.adoc'}.get(output)) # elif key_is_option:
with doc_file.open('w') as docfh: # yield option, value
docfh.write(doc) # else:
# yield option.path(), value
def test_dictionaries_github(test_dir): def test_dictionaries_warning(test_dir):
_test_dictionaries(test_dir, 'github', True) 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_asciidoc(test_dir):
def test_dictionaries_github_no_namespace(test_dir): # _test_dictionaries(test_dir, 'asciidoc', True)
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)