|
| 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 | +# ----- SHOULD fails tests |
| 26 | + |
| 27 | + |
| 28 | +def test_input_does_not_reference_formalparameter(): |
| 29 | + """ |
| 30 | + Test a Five Safes Crate where an input entity does not reference a |
| 31 | + `bioschemas:FormalParameter using `schema:exampleOfWork`. |
| 32 | + (We replace tjhe ?object of input --> exampleOfWork with a literal) |
| 33 | + """ |
| 34 | + sparql = ( |
| 35 | + SPARQL_PREFIXES |
| 36 | + + """ |
| 37 | + PREFIX bioschemas: <https://bioschemas.org/> |
| 38 | + DELETE { |
| 39 | + ?input schema:exampleOfWork ?formalParameter . |
| 40 | + } |
| 41 | + INSERT { |
| 42 | + ?input schema:exampleOfWork "not-a-formal-parameter" . |
| 43 | + } |
| 44 | + WHERE { |
| 45 | + ?input schema:exampleOfWork ?formalParameter . |
| 46 | + ?formalParameter a bioschemas:FormalParameter . |
| 47 | + ?action a schema:CreateAction ; |
| 48 | + schema:object ?input . |
| 49 | + } |
| 50 | + """ |
| 51 | + ) |
| 52 | + |
| 53 | + do_entity_test( |
| 54 | + rocrate_path=ValidROC().five_safes_crate_request, |
| 55 | + requirement_severity=Severity.RECOMMENDED, |
| 56 | + expected_validation_result=False, |
| 57 | + expected_triggered_requirements=["Input"], |
| 58 | + expected_triggered_issues=[ |
| 59 | + "Input SHOULD reference a FormalParameter using exampleOfWork" |
| 60 | + ], |
| 61 | + profile_identifier="five-safes-crate", |
| 62 | + rocrate_entity_mod_sparql=sparql, |
| 63 | + ) |
0 commit comments