Skip to content

Commit

Permalink
test(py-target): add test cases for custom Python-based targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleycaselli committed May 28, 2024
1 parent d962cee commit b65cf78
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/resources/py/tests/target/pyTarget-001.test.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# baseURI: http://datashapes.org/py/tests/target/pyTarget-001.test
# imports: http://datashapes.org/dash
# prefix: ex

@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://datashapes.org/py/tests/target/pyTarget-001.test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://datashapes.org/py/tests/target/pyTarget-001.test>
rdf:type owl:Ontology ;
rdfs:label "Test of sh:PyTarget 001" ;
owl:imports <http://datashapes.org/dash> ;
.
ex:GraphValidationTestCase
rdf:type dash:GraphValidationTestCase ;
dash:expectedResult [
rdf:type sh:ValidationReport ;
sh:conforms "false"^^xsd:boolean ;
sh:result [
rdf:type sh:ValidationResult ;
sh:focusNode ex:InvalidInstance1 ;
sh:resultPath rdfs:label ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MaxCountConstraintComponent ;
sh:sourceShape ex:TestShape-label ;
] ;
] ;
.
ex:InvalidInstance1
rdf:type owl:Thing ;
rdfs:label "Invalid instance1" ;
.
ex:TestShape
rdf:type sh:NodeShape ;
rdfs:label "Test shape" ;
sh:property ex:TestShape-label ;
sh:target [
rdf:type sh:PyTarget ;
sh:pyLibrary [
a sh:PyLibrary ;
sh:pyLibraryURL "http://datashapes.org/py/tests/target/py_target-001.py"^^xsd:anyURI ;
] ;
sh:pyFunctionName "py_target001" ;
] ;
.
ex:TestShape-label
sh:path rdfs:label ;
rdfs:comment "Must not have any rdfs:label" ;
rdfs:label "label" ;
sh:datatype xsd:string ;
sh:maxCount 0 ;
.
ex:ValidInstance1
rdf:type owl:Thing ;
.
8 changes: 8 additions & 0 deletions src/test/resources/py/tests/target/py_target-001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def py_target001(_this):
target_nodes = []
rdf_type = py_tf.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
owl_thing = py_tf.namedNode("http://www.w3.org/2002/07/owl#Thing")
it = _data.find(_this, rdf_type, owl_thing)
while t := it.next():
target_nodes.append(t.getSubject())
return target_nodes

0 comments on commit b65cf78

Please sign in to comment.