Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Aug 29, 2024
1 parent 1cd8789 commit 38a8fcf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 37 deletions.
70 changes: 70 additions & 0 deletions tests/test_reason.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Plugin tests."""

from pathlib import Path

import pytest
from cmem.cmempy.dp.proxy.graph import delete
from rdflib import Graph
from rdflib.compare import to_isomorphic

from cmem_plugin_reason.plugin_reason import ReasonPlugin
from cmem_plugin_reason.utils import REASONERS
from tests.utils import TestExecutionContext, needs_cmem
from tests.utils2 import get_remote_graph, import_graph

from . import __path__

UID = "e02aaed014c94e0c91bf960fed127750"
REASON_DATA_GRAPH_IRI = f"https://ns.eccenca.com/reasoning/{UID}/data/"
REASON_ONTOLOGY_GRAPH_IRI_1 = f"https://ns.eccenca.com/reasoning/{UID}/vocab/"
REASON_ONTOLOGY_GRAPH_IRI_2 = f"https://ns.eccenca.com/reasoning/{UID}/vocab2/"
REASON_ONTOLOGY_GRAPH_IRI_3 = f"https://ns.eccenca.com/reasoning/{UID}/vocab3/"
REASON_RESULT_GRAPH_IRI = f"https://ns.eccenca.com/reasoning/{UID}/result/"


@pytest.fixture
def _setup(request: pytest.FixtureRequest) -> None:
"""Set up Reason test"""
import_graph(REASON_DATA_GRAPH_IRI, "dataset_owl.ttl")
import_graph(REASON_ONTOLOGY_GRAPH_IRI_1, "test_reason_ontology_1.ttl")
import_graph(REASON_ONTOLOGY_GRAPH_IRI_2, "test_reason_ontology_2.ttl")
import_graph(REASON_ONTOLOGY_GRAPH_IRI_3, "test_reason_ontology_3.ttl")

request.addfinalizer(lambda: delete(REASON_DATA_GRAPH_IRI))
request.addfinalizer(lambda: delete(REASON_ONTOLOGY_GRAPH_IRI_1))
request.addfinalizer(lambda: delete(REASON_ONTOLOGY_GRAPH_IRI_2))
request.addfinalizer(lambda: delete(REASON_ONTOLOGY_GRAPH_IRI_3))
request.addfinalizer(lambda: delete(REASON_RESULT_GRAPH_IRI)) # noqa: PT021


@needs_cmem
def tests_reason(_setup: None) -> None:
"""Tests for Reason plugin"""

def test_reasoner(reasoner: str, err_list: list) -> list:
ReasonPlugin(
data_graph_iri=REASON_DATA_GRAPH_IRI,
ontology_graph_iri=REASON_ONTOLOGY_GRAPH_IRI_1,
output_graph_iri=REASON_RESULT_GRAPH_IRI,
reasoner=reasoner,
sub_class=False,
class_assertion=True,
property_assertion=True,
validate_profile=True,
import_ontology=True,
).execute(None, context=TestExecutionContext())

result = get_remote_graph(REASON_RESULT_GRAPH_IRI)
test = Graph().parse(Path(__path__[0]) / f"test_{reasoner}.ttl", format="turtle")
if to_isomorphic(result) != to_isomorphic(test):
err_list.append(reasoner)
return err_list

errors_list: list[str] = []
for reasoner in REASONERS:
errors_list = test_reasoner(reasoner, errors_list)

if errors_list:
errors = ""
errors += f"Test failed for reasoners {', '.join(errors_list)}."
raise AssertionError(errors[:-1])
40 changes: 3 additions & 37 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from cmem_plugin_reason.plugin_validate import ValidatePlugin
from cmem_plugin_reason.utils import REASONERS
from tests.utils import TestExecutionContext
from tests.utils import TestExecutionContext, needs_cmem
from tests.utils2 import get_remote_graph, import_graph

from . import __path__
Expand Down Expand Up @@ -54,42 +54,8 @@ def _setup(request: pytest.FixtureRequest) -> None:
request.addfinalizer(lambda: delete(VALIDATE_ONTOLOGY_GRAPH_IRI_3)) # noqa: PT021


# @needs_cmem
# def tests_validate(_setup: None) -> None:
# """Tests for Validate plugin"""
# result = ValidatePlugin(
# ontology_graph_iri=VALIDATE_ONTOLOGY_GRAPH_IRI_1,
# output_graph_iri=VALIDATE_RESULT_GRAPH_IRI,
# reasoner="elk",
# validate_profile=True,
# md_filename=MD_FILENAME,
# output_entities=True,
# mode="inconsistency",
# ).execute(None, context=TestExecutionContext(PROJECT_ID))
#
# md_test = (Path(__path__[0]) / "test_validate.md").read_text()
# value_dict = get_value_dict(result)
# output_graph = get_remote_graph(VALIDATE_RESULT_GRAPH_IRI)
# test = Graph().parse(Path(__path__[0]) / "test_validate_output.ttl", format="turtle")
# val_errors = ""
#
# if value_dict["markdown"] != md_test:
# val_errors += 'EntityPath "markdown" output error. '
# if value_dict["ontology_graph_iri"] != VALIDATE_ONTOLOGY_GRAPH_IRI_1:
# val_errors += 'EntityPath "ontology_graph_iri" output error. '
# if value_dict["reasoner"] != "elk":
# val_errors += 'EntityPath "reasoner" output error. '
# if value_dict["valid_profiles"] != "Full,DL,EL,QL,RL":
# val_errors += 'EntityPath "valid_profiles" output error. '
# if md_test != get_resource(PROJECT_ID, MD_FILENAME).decode():
# val_errors += "Markdown file error. "
# if to_isomorphic(output_graph) != to_isomorphic(test):
# val_errors += "Output graph error. "
# if val_errors:
# raise AssertionError("Validate: " + val_errors[:-1])


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

def test_validate(reasoner: str, err_list: list) -> list:
Expand Down

0 comments on commit 38a8fcf

Please sign in to comment.