|
| 1 | +import pathlib |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | +from jinja2 import Template |
| 6 | + |
| 7 | +from dqgen.adapters.resource_fetcher import get_file_content |
| 8 | +from dqgen.services import ASCII_DOC_TEMPLATES |
| 9 | +from dqgen.services.asciidoc_generator import AsciiDocGenerator |
| 10 | +from dqgen.services.asciidoc_templates_generator import generate_asciidoc_templates_from_csv |
| 11 | +from tests.unit.test_queries_generator import PATH_TO_APS |
| 12 | + |
| 13 | + |
| 14 | +def test_instance_asciidoc_generator(tmp_path): |
| 15 | + expected_text = """== Added concepts""" |
| 16 | + asciidoc_generator = AsciiDocGenerator(cls="skos:Concept", operation="added_instance", class_name="concept", |
| 17 | + output_folder_path=str(tmp_path), |
| 18 | + template=ASCII_DOC_TEMPLATES.get_template("instance.jinja2")) |
| 19 | + |
| 20 | + generated_file_path = asciidoc_generator.build_file_path() |
| 21 | + asciidoc_generator.to_file() |
| 22 | + |
| 23 | + generated_file_content = get_file_content(generated_file_path) |
| 24 | + assert Path(generated_file_path).is_file() |
| 25 | + assert isinstance(generated_file_content, str) |
| 26 | + assert expected_text in generated_file_content |
| 27 | + |
| 28 | + |
| 29 | +def test_generate_asciidoc_templates_from_csv(tmp_path): |
| 30 | + |
| 31 | + generate_asciidoc_templates_from_csv(ap_file_path=PATH_TO_APS / "src_ap_mod.csv", output_base_dir=tmp_path,) |
| 32 | + assert pathlib.Path(tmp_path).is_dir() |
| 33 | + assert pathlib.Path(tmp_path / "src_ap_mod" / "asciidoc").is_dir() |
| 34 | + assert pathlib.Path(tmp_path / "src_ap_mod" / "asciidoc" / "main.adoc").is_file() |
| 35 | + |
| 36 | + with pytest.raises(ValueError): |
| 37 | + generate_asciidoc_templates_from_csv(ap_file_path=PATH_TO_APS / "skos_core.csv", output_base_dir=tmp_path) |
0 commit comments