Skip to content

Commit

Permalink
fix tests and include validate entity output check
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jun 27, 2024
1 parent e670da8 commit 8cc6248
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tests/test_reason.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Plugin tests."""

from contextlib import suppress
from filecmp import cmp
from pathlib import Path

import pytest
Expand Down Expand Up @@ -51,12 +50,11 @@ def _setup(request: pytest.FixtureRequest) -> None:
request.addfinalizer(lambda: delete(REASON_RESULT_GRAPH_IRI))
request.addfinalizer(lambda: delete_project(PROJECT_ID))
request.addfinalizer(lambda: delete(OUTPUT_GRAPH_IRI))
request.addfinalizer(lambda: delete(VALIDATE_ONTOLOGY_GRAPH_IRI))
request.addfinalizer(lambda: Path(MD_FILENAME).unlink()) # noqa: PT021
request.addfinalizer(lambda: delete(VALIDATE_ONTOLOGY_GRAPH_IRI)) # noqa: PT021


@needs_cmem
def tests(_setup: None) -> None:
def tests(_setup: None) -> None: # noqa: C901
"""Tests for reason plugin"""

def get_remote_graph(iri: str) -> Graph:
Expand Down Expand Up @@ -87,25 +85,30 @@ def test_reasoner(reasoner: str, err_list: list) -> list:
return err_list

def test_validate(errors: str) -> str:
ValidatePlugin(
result = ValidatePlugin(
ontology_graph_iri=VALIDATE_ONTOLOGY_GRAPH_IRI,
produce_graph=True,
output_graph_iri=OUTPUT_GRAPH_IRI,
write_md=True,
md_filename=MD_FILENAME,
).execute((), context=TestExecutionContext(PROJECT_ID))

with Path(MD_FILENAME).open("wb") as md:
md.write(get_resource(PROJECT_ID, MD_FILENAME))
mdfile_test = Path(__path__[0]) / "test_validate.md"
errors = ""
if not cmp(MD_FILENAME, mdfile_test):
errors += "Markdown file error ."
val_errors = ""
md_test = (Path(__path__[0]) / "test_validate.md").read_text()

if md_test != next(iter(result.entities)).values[0][0]: # type: ignore[union-attr]
val_errors += "Entities output error. "

if md_test != get_resource(PROJECT_ID, MD_FILENAME).decode():
val_errors += "Markdown file error. "

output_graph = get_remote_graph(OUTPUT_GRAPH_IRI)
test = Graph().parse(Path(__path__[0]) / "test_validate_output.ttl", format="turtle")
if to_isomorphic(output_graph) != to_isomorphic(test):
errors += "Output graph error. "
val_errors += "Output graph error. "

if val_errors:
errors += "Validate: " + val_errors
return errors

errors_list: list[str] = []
Expand All @@ -115,7 +118,7 @@ def test_validate(errors: str) -> str:

errors = ""
if errors_list:
errors += f"Test failed for reasoners: {', '.join(errors_list)}. "
errors += f"Reason: test failed for reasoners {', '.join(errors_list)}. "

errors = test_validate(errors)

Expand Down

0 comments on commit 8cc6248

Please sign in to comment.