Skip to content

Commit

Permalink
Parameterise OGC tests and xfail the CRS & api Definition tests.
Browse files Browse the repository at this point in the history
Black all code.
  • Loading branch information
recalcitrantsupplant committed Sep 24, 2024
1 parent 8ebfb89 commit 7156ed3
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 32 deletions.
5 changes: 4 additions & 1 deletion prez/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ def _get_sparql_service_description(request, format):
try:
import uvicorn
except ImportError:
print("Error: Uvicorn is not installed. Install it with 'poetry install --extras \"server\".")
print(
'Error: Uvicorn is not installed. Install it with \'poetry install --extras "server".'
)
import sys

sys.exit(1)
uvicorn.run(assemble_app, factory=True, port=settings.port, host=settings.host)
71 changes: 47 additions & 24 deletions prez/services/query_generation/shacl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from __future__ import annotations

from string import Template
from typing import List, Optional, Any, Dict, Literal as TypingLiteral, Union, Tuple, Type
from typing import (
List,
Optional,
Any,
Dict,
Literal as TypingLiteral,
Union,
Tuple,
Type,
)

from pydantic import BaseModel
from rdflib import URIRef, BNode, Graph, RDFS
Expand Down Expand Up @@ -36,7 +45,12 @@
GraphNodePath,
VarOrTerm,
GraphTerm,
GroupOrUnionGraphPattern, PathElt, PathEltOrInverse, PathPrimary, PathSequence, PathMod,
GroupOrUnionGraphPattern,
PathElt,
PathEltOrInverse,
PathPrimary,
PathSequence,
PathMod,
)

from prez.reference_data.prez_ns import ONT, SHEXT
Expand Down Expand Up @@ -252,8 +266,6 @@ def optional_gpnt(depth):
self.gpnt_list.append(nested_ogp)




class PropertyShape(Shape):
uri: URIRef | BNode # URI of the shape
graph: Graph
Expand Down Expand Up @@ -354,7 +366,6 @@ def _add_path(self, path: PropertyPath, union: bool):
else:
self.and_property_paths.append(path)


def to_grammar(self):
# label nodes in the inner select and profile part of the query differently for clarity.
if self.kind == "endpoint":
Expand Down Expand Up @@ -441,9 +452,7 @@ def to_grammar(self):
)
self.gpnt_list.append(
GraphPatternNotTriples(
content=GroupOrUnionGraphPattern(
group_graph_patterns=ggp_list
)
content=GroupOrUnionGraphPattern(group_graph_patterns=ggp_list)
)
)

Expand Down Expand Up @@ -522,24 +531,39 @@ def process_property_paths(self, property_paths, path_or_prop, tssp_list, pp_i):
current_tssp.append(TriplesSameSubjectPath.from_spo(*triple))
pp_i += 1

elif isinstance(property_path, Union[ZeroOrMorePath, OneOrMorePath, ZeroOrOnePath]):
elif isinstance(
property_path, Union[ZeroOrMorePath, OneOrMorePath, ZeroOrOnePath]
):
triple = (self.focus_node, IRI(value=property_path.value), path_node_1)
self.tss_list.append(TriplesSameSubject.from_spo(*triple))
self.tssp_list.append(
_tssp_for_pathmods(self.focus_node, IRI(value=property_path.value), path_node_1, property_path.operand)
_tssp_for_pathmods(
self.focus_node,
IRI(value=property_path.value),
path_node_1,
property_path.operand,
)
)
pp_i += 1

elif isinstance(property_path, SequencePath):
for j, path in enumerate(property_path.value):
if isinstance(path, Path):
if j == 0:
triple = (self.focus_node, IRI(value=path.value), path_node_1)
triple = (
self.focus_node,
IRI(value=path.value),
path_node_1,
)
else:
triple = (path_node_1, IRI(value=path.value), path_node_2)
elif isinstance(path, InversePath):
if j == 0:
triple = (path_node_1, IRI(value=path.value), self.focus_node)
triple = (
path_node_1,
IRI(value=path.value),
self.focus_node,
)
else:
triple = (path_node_2, IRI(value=path.value), path_node_1)
self.tss_list.append(TriplesSameSubject.from_spo(*triple))
Expand All @@ -566,20 +590,19 @@ def _tssp_for_pathmods(focus_node, pred, obj, pathmod):
VerbPath(
path=SG_Path(
path_alternative=PathAlternative(
sequence_paths=[PathSequence(
list_path_elt_or_inverse=[
PathEltOrInverse(
path_elt=PathElt(
path_primary=PathPrimary(
value=pred,
),
path_mod=PathMod(
pathmod=pathmod
sequence_paths=[
PathSequence(
list_path_elt_or_inverse=[
PathEltOrInverse(
path_elt=PathElt(
path_primary=PathPrimary(
value=pred,
),
path_mod=PathMod(pathmod=pathmod),
)
)
)
]
)
]
)
]
)
)
Expand Down
30 changes: 27 additions & 3 deletions tests/test_ogc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,32 @@ def override_get_data_repo():
app.dependency_overrides.clear()


@pytest.mark.xfail()
def test_features_core(client: TestClient):
scope = "features/core"
@pytest.mark.parametrize(
"test_file",
[
pytest.param(
"apidefinition",
marks=pytest.mark.xfail(
reason="see https://github.com/RDFLib/prez/pull/265#issuecomment-2367130294"
),
),
"collection",
"collections",
"conformance",
pytest.param(
"crs",
marks=pytest.mark.xfail(
reason="see https://github.com/RDFLib/prez/issues/267"
),
),
"errorconditions",
"feature",
"features",
"general",
"landingpage",
],
)
def test_features_core(client: TestClient, test_file: str):
scope = f"features/core/test_{test_file}.py"
exit_code = run_ogctests(scope, test_client=client)
assert exit_code == pytest.ExitCode.OK
18 changes: 14 additions & 4 deletions tests/test_property_selection_shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
IRI,
OptionalGraphPattern,
Filter,
TriplesSameSubjectPath, TriplesSameSubject,
TriplesSameSubjectPath,
TriplesSameSubject,
)


Expand Down Expand Up @@ -223,9 +224,18 @@ def test_excluded_props():
@pytest.mark.parametrize(
["cardinality_type", "expected_result"],
[
("sh:zeroOrMorePath", '?focus_node <http://purl.org/dc/terms/publisher>* ?prof_1_node_1'),
("sh:oneOrMorePath", '?focus_node <http://purl.org/dc/terms/publisher>+ ?prof_1_node_1'),
("sh:zeroOrOnePath", '?focus_node <http://purl.org/dc/terms/publisher>? ?prof_1_node_1'),
(
"sh:zeroOrMorePath",
"?focus_node <http://purl.org/dc/terms/publisher>* ?prof_1_node_1",
),
(
"sh:oneOrMorePath",
"?focus_node <http://purl.org/dc/terms/publisher>+ ?prof_1_node_1",
),
(
"sh:zeroOrOnePath",
"?focus_node <http://purl.org/dc/terms/publisher>? ?prof_1_node_1",
),
],
)
def test_cardinality_props(cardinality_type, expected_result):
Expand Down

0 comments on commit 7156ed3

Please sign in to comment.