Skip to content

Commit a58d89e

Browse files
committed
Added tests for rules 1-7.
1 parent 974b84d commit a58d89e

2 files changed

Lines changed: 232 additions & 3 deletions

File tree

rocrate_validator/profiles/five-safes-crate/must/12_check_phase.ttl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ five-safes-crate:CheckValueObjectHasDescriptiveNameAndIsAssessAction
4242
] ;
4343

4444
sh:property [
45-
sh:a sh:PropertyShape ;
46-
sh:name "AssessAction" ;
47-
sh:description "CheckValue MUST be a `schema:AssessAction`." ;
4845
sh:path rdf:type ;
4946
sh:minCount 1 ;
5047
sh:hasValue schema:AssessAction;
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# Copyright (c) 2024-2025 CRS4
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import logging
16+
17+
from rocrate_validator.models import Severity
18+
from tests.ro_crates import ValidROC
19+
from tests.shared import do_entity_test, SPARQL_PREFIXES
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
26+
# ----- MUST fails tests
27+
28+
# TO BE CHECKED AGAIN
29+
def test_5src_check_value_not_of_type_assess_action():
30+
sparql = """
31+
PREFIX schema: <http://schema.org/>
32+
PREFIX shp: <https://w3id.org/shp#>
33+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
34+
35+
DELETE {
36+
?this rdf:type ?type .
37+
}
38+
INSERT {
39+
?this rdf:type <something_wrong> .
40+
}
41+
WHERE {
42+
?this a schema:AssessAction ;
43+
schema:additionalType shp:CheckValue ;
44+
rdf:type ?type .
45+
}
46+
"""
47+
48+
49+
do_entity_test(
50+
rocrate_path=ValidROC().five_safes_crate_result,
51+
requirement_severity=Severity.REQUIRED,
52+
expected_validation_result=False,
53+
expected_triggered_requirements=["CheckValue"],
54+
expected_triggered_issues=["CheckValue MUST be a `schema:AssessAction`."],
55+
profile_identifier="five-safes-crate",
56+
rocrate_entity_mod_sparql=sparql,
57+
)
58+
59+
60+
def test_5src_check_value_name_not_a_string():
61+
sparql = """
62+
PREFIX schema: <http://schema.org/>
63+
PREFIX shp: <https://w3id.org/shp#>
64+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
65+
66+
DELETE {
67+
?this schema:name ?name .
68+
}
69+
INSERT {
70+
?this schema:name 123 .
71+
}
72+
WHERE {
73+
?this schema:additionalType shp:CheckValue .
74+
}
75+
"""
76+
77+
do_entity_test(
78+
rocrate_path=ValidROC().five_safes_crate_result,
79+
requirement_severity=Severity.REQUIRED,
80+
expected_validation_result=False,
81+
expected_triggered_requirements=["CheckValue"],
82+
expected_triggered_issues=["CheckValue MUST have a human readable name string of at least 20 characters."],
83+
profile_identifier="five-safes-crate",
84+
rocrate_entity_mod_sparql=sparql,
85+
)
86+
87+
88+
89+
def test_5src_check_value_name_not_long_enough():
90+
sparql = """
91+
PREFIX schema: <http://schema.org/>
92+
PREFIX shp: <https://w3id.org/shp#>
93+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
94+
95+
DELETE {
96+
?this schema:name ?name .
97+
}
98+
INSERT {
99+
?this schema:name "Short" .
100+
}
101+
WHERE {
102+
?this schema:additionalType shp:CheckValue .
103+
}
104+
"""
105+
106+
do_entity_test(
107+
rocrate_path=ValidROC().five_safes_crate_result,
108+
requirement_severity=Severity.REQUIRED,
109+
expected_validation_result=False,
110+
expected_triggered_requirements=["CheckValue"],
111+
expected_triggered_issues=["CheckValue MUST have a human readable name string of at least 20 characters."],
112+
profile_identifier="five-safes-crate",
113+
rocrate_entity_mod_sparql=sparql,
114+
)
115+
116+
117+
118+
119+
# ----- SHOULD fails tests
120+
121+
122+
def test_5src_root_data_entity_does_not_mention_check_value_entity():
123+
sparql = """
124+
PREFIX schema: <http://schema.org/>
125+
PREFIX shp: <https://w3id.org/shp#>
126+
127+
DELETE {
128+
<./> schema:mentions ?o .
129+
}
130+
WHERE {
131+
?o schema:additionalType shp:CheckValue ;
132+
}
133+
"""
134+
135+
do_entity_test(
136+
rocrate_path=ValidROC().five_safes_crate_result,
137+
requirement_severity=Severity.RECOMMENDED,
138+
expected_validation_result=False,
139+
expected_triggered_requirements=["RootDataEntity"],
140+
expected_triggered_issues=["RootDataEntity SHOULD mention a check value object."],
141+
profile_identifier="five-safes-crate",
142+
rocrate_entity_mod_sparql=sparql,
143+
)
144+
145+
146+
147+
def test_5src_check_value_object_does_not_point_to_root_data_entity():
148+
sparql = """
149+
PREFIX schema: <http://schema.org/>
150+
PREFIX shp: <https://w3id.org/shp#>
151+
152+
DELETE {
153+
?s schema:object <./> .
154+
}
155+
INSERT {
156+
?s schema:object "not the RootDataEntity" .
157+
}
158+
WHERE {
159+
?s schema:additionalType shp:CheckValue ;
160+
}
161+
"""
162+
163+
do_entity_test(
164+
rocrate_path=ValidROC().five_safes_crate_result,
165+
requirement_severity=Severity.RECOMMENDED,
166+
expected_validation_result=False,
167+
expected_triggered_requirements=["CheckValue"],
168+
expected_triggered_issues=["`CheckValue` --> `object` SHOULD point to the root of the RO-Crate"],
169+
profile_identifier="five-safes-crate",
170+
rocrate_entity_mod_sparql=sparql,
171+
)
172+
173+
174+
def test_5src_check_value_instrument_does_not_point_to_entity_with_type_defined_term():
175+
sparql = """
176+
PREFIX schema: <http://schema.org/>
177+
PREFIX shp: <https://w3id.org/shp#>
178+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
179+
180+
DELETE {
181+
?s rdf:type schema:DefinedTerm .
182+
}
183+
INSERT {
184+
?s rdf:type schema:Persona .
185+
}
186+
WHERE {
187+
?cv schema:additionalType shp:CheckValue ;
188+
schema:instrument ?s .
189+
?s rdf:type schema:DefinedTerm .
190+
}
191+
"""
192+
193+
do_entity_test(
194+
rocrate_path=ValidROC().five_safes_crate_result,
195+
requirement_severity=Severity.RECOMMENDED,
196+
expected_validation_result=False,
197+
expected_triggered_requirements=["CheckValue"],
198+
expected_triggered_issues=["`CheckValue` --> `instrument` SHOULD point to an entity typed `schema:DefinedTerm`"],
199+
profile_identifier="five-safes-crate",
200+
rocrate_entity_mod_sparql=sparql,
201+
)
202+
203+
204+
205+
206+
# ----- MAY fails tests
207+
208+
209+
def test_5src_check_value_does_not_have_start_time():
210+
sparql = """
211+
PREFIX schema: <http://schema.org/>
212+
PREFIX shp: <https://w3id.org/shp#>
213+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
214+
215+
DELETE {
216+
?c schema:startTime ?t .
217+
}
218+
WHERE {
219+
?c schema:additionalType shp:CheckValue ;
220+
schema:startTime ?t .
221+
}
222+
"""
223+
224+
do_entity_test(
225+
rocrate_path=ValidROC().five_safes_crate_result,
226+
requirement_severity=Severity.OPTIONAL,
227+
expected_validation_result=False,
228+
expected_triggered_requirements=["CheckValue"],
229+
expected_triggered_issues=["`CheckValue` MAY have the `startTime` property."],
230+
profile_identifier="five-safes-crate",
231+
rocrate_entity_mod_sparql=sparql,
232+
)

0 commit comments

Comments
 (0)