rougail-output-doc/tests/test_load.py

106 lines
3.1 KiB
Python
Raw Normal View History

2024-12-02 20:21:31 +01:00
import os
2024-07-10 21:27:48 +02:00
from pytest import fixture # , raises
from pathlib import Path
2024-12-02 20:21:31 +01:00
from rougail import Rougail
from rougail.output_doc import RougailOutputDoc as RougailOutput
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
excludes = []
excludes = [
2024-07-10 21:27:48 +02:00
'60_5family_dynamic_unknown_suffix',
'60_5family_dynamic_variable_outside_sub_suffix',
2024-12-02 20:21:31 +01:00
]
test_ok = get_structures_list(excludes)
#test_ok = [Path('../rougail-tests/structures/00_0version_underscore')]
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
os.environ['COLUMNS'] = '80'
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
def idfn(fixture_value):
return fixture_value.name
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
@fixture(scope="module", params=test_ok, ids=idfn)
2024-07-10 21:27:48 +02:00
def test_dir(request):
return request.param
2024-12-02 20:21:31 +01:00
def _test_dictionaries(test_dir, namespace, ext, *, examples=False):
rougailconfig = get_rougail_config(test_dir, namespace)
if not rougailconfig:
return
##################################
2024-07-10 21:27:48 +02:00
rougailconfig['step.output'] = 'doc'
2024-12-02 20:21:31 +01:00
rougailconfig['doc.output_format'] = ext
ext = {'github': 'md', 'asciidoc': 'adoc', 'json': 'json', 'console': 'sh'}.get(ext)
2024-11-15 08:13:45 +01:00
if examples:
rougailconfig['doc.with_example'] = True
else:
rougailconfig['doc.with_example'] = False
2024-12-02 20:21:31 +01:00
##################################
dir_name = 'test'
2024-07-10 21:27:48 +02:00
if namespace:
2024-12-02 20:21:31 +01:00
dir_name += '_namespace'
elif (test_dir / 'force_namespace').is_file():
return
##################################
2024-11-15 08:13:45 +01:00
if examples:
2024-12-02 20:21:31 +01:00
dir_name += '_examples'
##################################
rougail = Rougail(rougailconfig)
config = rougail.run()
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}'
2024-07-10 21:27:48 +02:00
2024-11-15 08:13:45 +01:00
def test_dictionaries_json(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, True, 'json')
2024-11-15 08:13:45 +01:00
2024-11-20 21:12:56 +01:00
def test_dictionaries_console(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, True, 'console')
2024-11-20 21:12:56 +01:00
2024-07-10 21:27:48 +02:00
def test_dictionaries_github(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, True, 'github')
2024-07-10 21:27:48 +02:00
def test_dictionaries_asciidoc(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, True, 'asciidoc')
2024-07-10 21:27:48 +02:00
2024-12-02 20:21:31 +01:00
################
2024-11-15 08:13:45 +01:00
def test_dictionaries_examples(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, True, 'github', examples=True)
2024-11-15 08:13:45 +01:00
2024-12-02 20:21:31 +01:00
################
2024-11-15 08:13:45 +01:00
def test_dictionaries_json_no_namespace(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, False, 'json')
2024-11-15 08:13:45 +01:00
2024-11-20 21:12:56 +01:00
def test_dictionaries_console_no_namespace(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, False, 'console')
2024-11-20 21:12:56 +01:00
2024-07-10 21:27:48 +02:00
def test_dictionaries_github_no_namespace(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, False, 'github')
2024-07-10 21:27:48 +02:00
def test_dictionaries_asciidoc_no_namespace(test_dir):
2024-12-02 20:21:31 +01:00
_test_dictionaries(test_dir, False, 'asciidoc')
################
def test_dictionaries_examples_no_namespace(test_dir):
_test_dictionaries(test_dir, False, 'github', examples=True)