Skip to content

Commit

Permalink
Update SPARQL query result strict typing
Browse files Browse the repository at this point in the history
References:
* RDFLib/rdflib#2283

Signed-off-by: Alex Nelson <[email protected]>
  • Loading branch information
ajnelson-nist committed Mar 20, 2023
1 parent d719b59 commit 7679d19
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions catalog/datasets/dfrws2017-challenge/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def ask_derivation(
""",
initBindings={"nSource": n_source, "nTarget": n_target},
):
assert isinstance(result, bool)
logging.debug(result)
computed = result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import Set, Tuple

from rdflib import PROV, Graph, Literal, URIRef
from rdflib.query import ResultRow

NS_PROV = PROV

Expand Down Expand Up @@ -59,11 +60,13 @@ def test_android7_distribution_inputs_and_outputs_matched() -> None:
"""

for result_extracted in graph.query(query_extracted):
assert isinstance(result_extracted, ResultRow)
assert isinstance(result_extracted[0], Literal)
expected.add(str(result_extracted[0]))
assert len(expected) > 0

for result_packaged in graph.query(query_packaged):
assert isinstance(result_packaged, ResultRow)
assert isinstance(result_packaged[0], Literal)
computed.add(str(result_packaged[0]))

Expand Down Expand Up @@ -315,6 +318,8 @@ def test_android7_hash_documented_sources() -> None:
}
"""
for result in graph.query(query):
assert isinstance(result, ResultRow)
assert isinstance(result[3], Literal)
computed.add(
(
str(result[0]),
Expand Down Expand Up @@ -350,6 +355,7 @@ def test_android7_hash_iris() -> None:
}
"""
for result in graph.query(query):
assert isinstance(result, ResultRow)
assert isinstance(result[0], URIRef)
hash_iri = str(result[0])
if RX_UUID.search(hash_iri) is None:
Expand Down
2 changes: 2 additions & 0 deletions src/filter_entity_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from case_utils.namespace import NS_RDF, NS_RDFS, NS_UCO_CORE
from rdflib import PROV, Graph, Namespace, URIRef
from rdflib.query import ResultRow

NS_KB = Namespace("http://example.org/kb/")
NS_PROV = PROV
Expand Down Expand Up @@ -78,6 +79,7 @@ def main() -> None:
"""
n_found_nodes: Set[URIRef] = set()
for result in in_graph.query(query, initBindings=initial_bindings):
assert isinstance(result, ResultRow)
assert isinstance(result[0], URIRef)
assert isinstance(result[1], URIRef)
assert isinstance(result[2], URIRef)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Set, Tuple

from rdflib import SH, TIME, Graph, URIRef
from rdflib.query import ResultRow

NS_SH = SH
NS_TIME = TIME
Expand All @@ -39,6 +40,7 @@ def test_qualified_url_shape() -> None:
}
"""
for result in graph.query(query):
assert isinstance(result, ResultRow)
assert isinstance(result[0], URIRef)
computed.add(result[0])
assert expected == computed
Expand Down Expand Up @@ -118,6 +120,7 @@ def test_time_XFAIL_disjoint_properties() -> None:
}
"""
for result in graph.query(query):
assert isinstance(result, ResultRow)
assert isinstance(result[0], URIRef)
assert isinstance(result[1], URIRef)
computed.add((result[0], result[1]))
Expand Down

0 comments on commit 7679d19

Please sign in to comment.