diff --git a/rocrate_validator/profiles/five-safes-crate/should/9_inputs.ttl b/rocrate_validator/profiles/five-safes-crate/should/9_inputs.ttl new file mode 100644 index 000000000..572610962 --- /dev/null +++ b/rocrate_validator/profiles/five-safes-crate/should/9_inputs.ttl @@ -0,0 +1,58 @@ +# Copyright (c) 2025 eScience Lab, The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +@prefix ro: <./> . +@prefix ro-crate: . +@prefix five-safes-crate: . +@prefix rdf: . +@prefix schema: . +@prefix bioschemas: . +@prefix purl: . +@prefix sh: . +@prefix validator: . +@prefix xsd: . + + + +five-safes-crate:InputEntityReferencesFormalParameterViaExampleOfWork + a sh:NodeShape ; + sh:name "Input" ; + sh:description "" ; + sh:target [ + a sh:SPARQLTarget ; + sh:prefixes ro-crate:sparqlPrefixes ; + sh:select """ + SELECT ?this WHERE { + ?action a schema:CreateAction ; + schema:object ?this . + } + """ + ] ; + sh:sparql [ + a sh:SPARQLConstraint ; + sh:name "exampleOfWork" ; + sh:description "Input SHOULD reference a FormalParameter using exampleOfWork" ; + + sh:prefixes ro-crate:sparqlPrefixes ; + sh:select """ + SELECT $this WHERE { + FILTER NOT EXISTS { + $this schema:exampleOfWork ?par . + ?par a bioschemas:FormalParameter . + } + } + """ ; + sh:severity sh:Warning ; + sh:message "Input SHOULD reference a FormalParameter using exampleOfWork" ; + ] . \ No newline at end of file diff --git a/tests/integration/profiles/five-safes-crate/test_5src_9_inputs.py b/tests/integration/profiles/five-safes-crate/test_5src_9_inputs.py new file mode 100644 index 000000000..7796d0b8f --- /dev/null +++ b/tests/integration/profiles/five-safes-crate/test_5src_9_inputs.py @@ -0,0 +1,63 @@ +# Copyright (c) 2024-2025 CRS4 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging + +from rocrate_validator.models import Severity +from tests.ro_crates import ValidROC +from tests.shared import do_entity_test, SPARQL_PREFIXES + +# set up logging +logger = logging.getLogger(__name__) + + +# ----- SHOULD fails tests + + +def test_input_does_not_reference_formalparameter(): + """ + Test a Five Safes Crate where an input entity does not reference a + `bioschemas:FormalParameter using `schema:exampleOfWork`. + (We replace tjhe ?object of input --> exampleOfWork with a literal) + """ + sparql = ( + SPARQL_PREFIXES + + """ + PREFIX bioschemas: + DELETE { + ?input schema:exampleOfWork ?formalParameter . + } + INSERT { + ?input schema:exampleOfWork "not-a-formal-parameter" . + } + WHERE { + ?input schema:exampleOfWork ?formalParameter . + ?formalParameter a bioschemas:FormalParameter . + ?action a schema:CreateAction ; + schema:object ?input . + } + """ + ) + + do_entity_test( + rocrate_path=ValidROC().five_safes_crate_request, + requirement_severity=Severity.RECOMMENDED, + expected_validation_result=False, + expected_triggered_requirements=["Input"], + expected_triggered_issues=[ + "Input SHOULD reference a FormalParameter using exampleOfWork" + ], + profile_identifier="five-safes-crate", + rocrate_entity_mod_sparql=sparql, + )