2024-12-02 20:21:31 +01:00
|
|
|
import os
|
2025-05-04 14:29:51 +02:00
|
|
|
import warnings
|
|
|
|
|
from json import dumps, loads
|
2024-07-10 21:27:48 +02:00
|
|
|
from pytest import fixture # , raises
|
|
|
|
|
from pathlib import Path
|
2025-05-04 14:29:51 +02:00
|
|
|
from contextlib import chdir
|
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
|
|
|
|
|
|
|
|
|
2025-05-04 14:29:51 +02:00
|
|
|
HERE = Path(__file__).parent
|
|
|
|
|
|
|
|
|
|
|
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)
|
2025-10-14 13:50:02 +02:00
|
|
|
# test_ok = [HERE.parent.parent / "rougail-tests" / "structures" / "40_8calculation_boolean"]
|
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
|
|
|
|
|
|
|
|
|
|
|
2025-10-14 13:50:02 +02:00
|
|
|
EXT = {'github': 'md', 'asciidoc': 'adoc', 'json': 'json', 'console': 'sh', 'gitlab': 'gitlab.md', "html": "html"}
|
2025-10-14 12:58:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _test_structural_files(test_dir, namespace, ext, *, examples=False, without_family=False):
|
2025-05-04 14:29:51 +02:00
|
|
|
with chdir(HERE):
|
|
|
|
|
rougailconfig = get_rougail_config(test_dir, namespace, relative_to=HERE)
|
|
|
|
|
if not rougailconfig:
|
|
|
|
|
return
|
|
|
|
|
rougailconfig['tiramisu_cache'] = 'p.py'
|
|
|
|
|
##################################
|
|
|
|
|
rougailconfig['step.output'] = 'doc'
|
|
|
|
|
rougailconfig['doc.output_format'] = ext
|
2025-10-14 12:58:39 +02:00
|
|
|
ext = EXT.get(ext)
|
2025-05-04 14:29:51 +02:00
|
|
|
if examples:
|
2025-10-14 12:58:39 +02:00
|
|
|
rougailconfig['doc.contents'] = ['example']
|
2025-05-04 14:29:51 +02:00
|
|
|
else:
|
2025-10-14 12:58:39 +02:00
|
|
|
rougailconfig['doc.contents'] = ['variables']
|
|
|
|
|
if without_family:
|
|
|
|
|
rougailconfig['doc.without_family'] = True
|
|
|
|
|
else:
|
|
|
|
|
rougailconfig['doc.without_family'] = False
|
2025-05-04 14:29:51 +02:00
|
|
|
##################################
|
|
|
|
|
dir_name = 'test'
|
|
|
|
|
if namespace:
|
|
|
|
|
dir_name += '_namespace'
|
|
|
|
|
elif (test_dir / 'force_namespace').is_file():
|
|
|
|
|
return
|
|
|
|
|
##################################
|
|
|
|
|
if examples:
|
|
|
|
|
dir_name += '_examples'
|
2025-10-14 12:58:39 +02:00
|
|
|
if without_family:
|
|
|
|
|
dir_name += '_without_family'
|
2025-05-04 14:29:51 +02:00
|
|
|
##################################
|
|
|
|
|
rougail = Rougail(rougailconfig)
|
|
|
|
|
warnings.simplefilter("always", UserWarning)
|
|
|
|
|
with warnings.catch_warnings(record=True) as wn:
|
|
|
|
|
config = rougail.run()
|
|
|
|
|
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
|
|
|
|
output_file = HERE / '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}'
|
|
|
|
|
#
|
|
|
|
|
warns = [str(w.message) for w in wn]
|
|
|
|
|
output_file = HERE / 'results' / dir_name / ("warnings_" + test_dir.name)
|
|
|
|
|
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(dumps(warns))
|
|
|
|
|
with output_file.open() as outfh:
|
|
|
|
|
attented_output = loads(outfh.read())
|
|
|
|
|
assert warns == attented_output, f'filename {output_file}'
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_json(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'json')
|
2024-11-15 08:13:45 +01:00
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_console(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'console')
|
2024-11-20 21:12:56 +01:00
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_github(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'github')
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
|
|
2025-10-02 08:19:18 +02:00
|
|
|
def test_structural_files_gitlab(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'gitlab')
|
|
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_asciidoc(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'asciidoc')
|
2024-07-10 21:27:48 +02:00
|
|
|
|
2025-10-14 13:50:02 +02:00
|
|
|
|
|
|
|
|
def test_structural_files_html(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'html')
|
|
|
|
|
|
2024-12-02 20:21:31 +01:00
|
|
|
################
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_examples(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'github', examples=True)
|
2024-11-15 08:13:45 +01:00
|
|
|
|
2025-10-14 12:58:39 +02:00
|
|
|
def test_structural_files_without_family(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, True, 'github', without_family=True)
|
|
|
|
|
|
2024-12-02 20:21:31 +01:00
|
|
|
################
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_json_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'json')
|
2024-11-15 08:13:45 +01:00
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_console_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'console')
|
2024-11-20 21:12:56 +01:00
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_github_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'github')
|
2024-07-10 21:27:48 +02:00
|
|
|
|
|
|
|
|
|
2025-10-02 08:19:18 +02:00
|
|
|
def test_structural_files_gitlab_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'gitlab')
|
|
|
|
|
|
|
|
|
|
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_asciidoc_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'asciidoc')
|
2024-12-02 20:21:31 +01:00
|
|
|
|
2025-10-14 13:50:02 +02:00
|
|
|
def test_structural_files_html_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'html')
|
|
|
|
|
|
2024-12-02 20:21:31 +01:00
|
|
|
################
|
2025-09-22 09:42:46 +02:00
|
|
|
def test_structural_files_examples_no_namespace(test_dir):
|
|
|
|
|
_test_structural_files(test_dir, False, 'github', examples=True)
|
2025-10-14 12:58:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
################
|
|
|
|
|
def _test_changelog_add(test_dir, ext):
|
|
|
|
|
with chdir(HERE):
|
|
|
|
|
rougailconfig = get_rougail_config(test_dir, True, relative_to=HERE)
|
|
|
|
|
if not rougailconfig:
|
|
|
|
|
return
|
|
|
|
|
rougailconfig["step.output"] = "doc"
|
|
|
|
|
rougailconfig["doc.output_format"] = ext
|
|
|
|
|
rougailconfig["doc.contents"] = ["changelog"]
|
|
|
|
|
rougailconfig["doc.previous_json_file"] = str(HERE / "empty" / "out.json")
|
|
|
|
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
|
|
|
|
config = eolobj.run()
|
|
|
|
|
result = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
|
|
|
|
dir_name = 'test_namespace'
|
|
|
|
|
output_file = HERE / 'results' / dir_name / (test_dir.name + ".changelog." + EXT.get(ext))
|
|
|
|
|
if not output_file.is_file():
|
|
|
|
|
with output_file.open('w') as outfh:
|
|
|
|
|
outfh.write(result)
|
|
|
|
|
with output_file.open() as outfh:
|
|
|
|
|
attented_output = outfh.read()
|
|
|
|
|
assert result == attented_output, f'filename {output_file}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_changelog_add(test_dir):
|
|
|
|
|
for output_format in EXT:
|
|
|
|
|
if output_format == 'json':
|
|
|
|
|
continue
|
|
|
|
|
_test_changelog_add(test_dir, output_format)
|