Skip to content

Commit b16679f

Browse files
committed
version check tests
1 parent fd7046d commit b16679f

4 files changed

Lines changed: 274 additions & 7 deletions

File tree

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
{
2+
"@context": ["https://w3id.org/ro/crate/1.2/context", "http://schema.org", {"test": "http://schema.org/test"}],
3+
"@graph": [
4+
{
5+
"@type": "CreativeWork",
6+
"@id": "ro-crate-metadata.json",
7+
"about": {
8+
"@id": "./"
9+
},
10+
"conformsTo": {
11+
"@id": "https://w3id.org/ro/crate/1.2"
12+
}
13+
},
14+
{
15+
"@id": "./",
16+
"@type": "Dataset",
17+
"name": "5-Safe RO-Crate Request",
18+
"description": "example 5-Safe RO-Crate request metadata for testing",
19+
"license": "Apache-2.0",
20+
"datePublished": "2025-09-20T14:38:00+00:00",
21+
"conformsTo": {
22+
"@id": "https://w3id.org/5s-crate/0.4"
23+
},
24+
"hasPart": [
25+
{
26+
"@id": "https://workflowhub.eu/workflows/289?version=1"
27+
},
28+
{
29+
"@id": "input1.txt"
30+
}
31+
],
32+
"mainEntity": {
33+
"@id": "https://workflowhub.eu/workflows/289?version=1"
34+
},
35+
"mentions": {
36+
"@id": "#query-37252371-c937-43bd-a0a7-3680b48c0538"
37+
},
38+
"sourceOrganization": {
39+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70"
40+
}
41+
},
42+
{
43+
"@id": "https://w3id.org/5s-crate/0.4",
44+
"@type": "Profile",
45+
"name": "Five Safes RO-Crate profile"
46+
},
47+
{
48+
"@id": "https://workflowhub.eu/workflows/289?version=1",
49+
"@type": "Dataset",
50+
"name": "CWL Protein MD Setup tutorial with mutations",
51+
"conformsTo": {
52+
"@id": "https://w3id.org/workflowhub/workflow-ro-crate/1.0"
53+
},
54+
"distribution": {
55+
"@id": "https://workflowhub.eu/workflows/289/ro_crate?version=1"
56+
}
57+
},
58+
{
59+
"@id": "https://workflowhub.eu/workflows/289/ro_crate?version=1",
60+
"@type": "DataDownload",
61+
"conformsTo": {
62+
"@id": "https://w3id.org/ro/crate"
63+
},
64+
"encodingFormat": "application/zip"
65+
},
66+
{
67+
"@id": "#query-37252371-c937-43bd-a0a7-3680b48c0538",
68+
"@type": "CreateAction",
69+
"actionStatus": "http://schema.org/PotentialActionStatus",
70+
"agent": {
71+
"@id": "https://orcid.org/0000-0001-9842-9718"
72+
},
73+
"instrument": {
74+
"@id": "https://workflowhub.eu/workflows/289?version=1"
75+
},
76+
"name": "Execute query 12389 on workflow ",
77+
"object": [
78+
{
79+
"@id": "input1.txt"
80+
},
81+
{
82+
"@id": "#enableFastMode"
83+
}
84+
]
85+
},
86+
{
87+
"@id": "https://orcid.org/0000-0001-9842-9718",
88+
"@type": "Person",
89+
"name": "Stian Soiland-Reyes",
90+
"affiliation": {
91+
"@id": "https://ror.org/027m9bs27"
92+
},
93+
"memberOf": [
94+
{
95+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70"
96+
}
97+
]
98+
},
99+
{
100+
"@id": "https://ror.org/027m9bs27",
101+
"@type": "Organization",
102+
"name": "The University of Manchester"
103+
},
104+
{
105+
"@id": "https://ror.org/01ee9ar58",
106+
"@type": "Organization",
107+
"name": "University of Nottingham"
108+
},
109+
{
110+
"@id": "#project-be6ffb55-4f5a-4c14-b60e-47e0951090c70",
111+
"@type": "Project",
112+
"name": "Investigation of cancer (TRE72 project 81)",
113+
"identifier": [
114+
{
115+
"@id": "_:localid:tre72:project81"
116+
}
117+
],
118+
"funding": {
119+
"@id": "https://gtr.ukri.org/projects?ref=10038961"
120+
},
121+
"member": [
122+
{
123+
"@id": "https://ror.org/027m9bs27"
124+
},
125+
{
126+
"@id": "https://ror.org/01ee9ar58"
127+
}
128+
]
129+
},
130+
{
131+
"@id": "_:localid:tre72:project81",
132+
"@type": "PropertyValue",
133+
"name": "tre72",
134+
"value": "project81"
135+
},
136+
{
137+
"@id": "https://gtr.ukri.org/projects?ref=10038961",
138+
"@type": "Grant",
139+
"name": "EOSC4Cancer"
140+
},
141+
{
142+
"@id": "input1.txt",
143+
"@type": "File",
144+
"name": "input1",
145+
"exampleOfWork": {
146+
"@id": "#sequence"
147+
}
148+
},
149+
{
150+
"@id": "#enableFastMode",
151+
"@type": "PropertyValue",
152+
"name": "--fast-mode",
153+
"value": "True",
154+
"exampleOfWork": {
155+
"@id": "#fast"
156+
}
157+
},
158+
{
159+
"@id": "#sequence",
160+
"@type": "FormalParameter",
161+
"name": "input-sequence"
162+
},
163+
{
164+
"@id": "#fast",
165+
"@type": "FormalParameter",
166+
"name": "fast-mode"
167+
}
168+
]
169+
}

tests/data/crates/valid/five-safes-crate-request/ro-crate-metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"@context": "https://w3id.org/ro/crate/1.1/context",
2+
"@context": "https://w3id.org/ro/crate/1.2/context",
33
"@graph": [
44
{
55
"@type": "CreativeWork",
@@ -8,7 +8,7 @@
88
"@id": "./"
99
},
1010
"conformsTo": {
11-
"@id": "https://w3id.org/ro/crate/1.1"
11+
"@id": "https://w3id.org/ro/crate/1.2"
1212
}
1313
},
1414
{
@@ -166,4 +166,4 @@
166166
"name": "fast-mode"
167167
}
168168
]
169-
}
169+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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, Invalid5sROC
19+
from tests.shared import do_entity_test, SPARQL_PREFIXES
20+
21+
# set up logging
22+
logger = logging.getLogger(__name__)
23+
24+
25+
# ----- MUST fails tests
26+
27+
28+
def test_5src_conforms_to_old_version():
29+
sparql = SPARQL_PREFIXES + """
30+
DELETE {
31+
<ro-crate-metadata.json> dct:conformsTo ?version .
32+
}
33+
INSERT {
34+
<ro-crate-metadata.json> dct:conformsTo <https://w3id.org/ro/crate/1.1> .
35+
}
36+
WHERE {
37+
<ro-crate-metadata.json> dct:conformsTo ?version .
38+
}
39+
"""
40+
41+
do_entity_test(
42+
rocrate_path=ValidROC().five_safes_crate_request,
43+
requirement_severity=Severity.REQUIRED,
44+
expected_validation_result=False,
45+
expected_triggered_requirements=["RO-Crate conforms to 1.2 or later minor version"],
46+
expected_triggered_issues=["The RO-Crate metadata file descriptor MUST have a `conformsTo` property with RO-Crate specification version 1.2 or later minor version"],
47+
profile_identifier="five-safes-crate",
48+
rocrate_entity_mod_sparql=sparql,
49+
)
50+
51+
def test_5src_context_single_wrong_version():
52+
do_entity_test(
53+
rocrate_path=Invalid5sROC().context_single_wrong_version,
54+
requirement_severity=Severity.REQUIRED,
55+
expected_validation_result=False,
56+
expected_triggered_requirements=["RO-Crate context version"],
57+
expected_triggered_issues=["The RO-Crate metadata file MUST include the RO-Crate context version 1.2 (or later minor version) in `@context`"],
58+
profile_identifier="five-safes-crate",
59+
)
60+
61+
def test_5src_context_multiple_wrong_version():
62+
do_entity_test(
63+
rocrate_path=Invalid5sROC().context_multiple_wrong_version,
64+
requirement_severity=Severity.REQUIRED,
65+
expected_validation_result=False,
66+
expected_triggered_requirements=["RO-Crate context version"],
67+
expected_triggered_issues=["The RO-Crate metadata file MUST include the RO-Crate context version 1.2 (or later minor version) in `@context`"],
68+
profile_identifier="five-safes-crate",
69+
)

tests/integration/profiles/five-safes-crate/test_valid_5src.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
import logging
16+
import pytest
1617

18+
from rocrate_validator import services
1719
from rocrate_validator.models import Severity
1820
from tests.conftest import SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER
1921
from tests.ro_crates import ValidROC
@@ -23,23 +25,50 @@
2325
logger.setLevel(logging.DEBUG)
2426

2527

26-
def test_valid_five_safes_crate_request_required():
28+
@pytest.fixture
29+
def skip_spec_version_identifier():
30+
"""Returns identifiers for RO-Crate version checks in the base RO-Crate profile.
31+
32+
Used to skip version checks while there is not a base profile available for RO-Crate 1.2 (only 1.1)
33+
"""
34+
rocrate_profile = services.get_profile("ro-crate")
35+
if not rocrate_profile:
36+
raise RuntimeError("Unable to load the RO-Crate profile")
37+
check_conformsTo_version = \
38+
rocrate_profile.get_requirement_check("Metadata File Descriptor entity: `conformsTo` property")
39+
assert check_conformsTo_version, \
40+
"Metadata File Descriptor entity: `conformsTo` property"
41+
SKIP_CONFORMSTO_VERSION_CHECK_IDENTIFIER = check_conformsTo_version.identifier
42+
return SKIP_CONFORMSTO_VERSION_CHECK_IDENTIFIER
43+
44+
45+
def test_valid_five_safes_crate_request_required(skip_spec_version_identifier):
2746
"""Test a valid Five Safes Crate representing a request."""
2847
do_entity_test(
2948
ValidROC().five_safes_crate_request,
3049
Severity.REQUIRED,
3150
True,
3251
profile_identifier="five-safes-crate",
33-
skip_checks=[SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER],
52+
skip_checks=[ SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER, skip_spec_version_identifier],
3453
)
3554

3655

37-
def test_valid_five_safes_crate_result_required():
56+
def test_valid_five_safes_crate_result_required(skip_spec_version_identifier):
3857
"""Test a valid Five Safes Crate representing a result."""
3958
do_entity_test(
4059
ValidROC().five_safes_crate_result,
4160
Severity.REQUIRED,
4261
True,
4362
profile_identifier="five-safes-crate",
44-
skip_checks=[SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER],
63+
skip_checks=[SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER, skip_spec_version_identifier],
64+
)
65+
66+
def test_valid_five_safes_crate_multiple_context(skip_spec_version_identifier):
67+
"""Test a valid Five Safes Crate representing a result."""
68+
do_entity_test(
69+
ValidROC().five_safes_crate_multiple_context,
70+
Severity.REQUIRED,
71+
True,
72+
profile_identifier="five-safes-crate",
73+
skip_checks=[SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER, skip_spec_version_identifier],
4574
)

0 commit comments

Comments
 (0)