1414
1515import logging
1616
17- from rocrate_validator import models
17+ from rocrate_validator import models , services
1818from tests .ro_crates import InvalidFileDescriptor , ValidROC
1919from tests .shared import do_entity_test
2020
@@ -32,8 +32,44 @@ def test_missing_file_descriptor():
3232
3333
3434def test_not_valid_json_format ():
35- """Test a RO-Crate with an invalid JSON file descriptor format."""
36- do_entity_test (paths .invalid_json_format , models .Severity .REQUIRED , False , ["File Descriptor JSON format" ], [])
35+ """
36+ Test a RO-Crate with an invalid JSON file descriptor format.
37+
38+ The validator must emit an ad-hoc issue reporting that the file descriptor is
39+ not valid JSON, including the position of the parsing error.
40+ """
41+ do_entity_test (
42+ paths .invalid_json_format ,
43+ models .Severity .REQUIRED ,
44+ False ,
45+ ["File Descriptor JSON format" ],
46+ ['RO-Crate file descriptor "ro-crate-metadata.json" is not valid JSON' ],
47+ )
48+
49+
50+ def test_not_valid_json_format_aborts_validation ():
51+ """
52+ An unparsable JSON file descriptor must abort the validation (fail-fast).
53+
54+ Since the metadata cannot be read, no further check can run meaningfully, so the
55+ only reported failure must be the JSON-format one (no false positives).
56+ """
57+ result = services .validate (
58+ models .ValidationSettings (
59+ rocrate_uri = models .URI (paths .invalid_json_format ),
60+ requirement_severity = models .Severity .REQUIRED ,
61+ )
62+ )
63+ assert not result .passed (), "An invalid-JSON crate must not pass validation"
64+
65+ failed_requirements = [r .name for r in result .failed_requirements ]
66+ assert failed_requirements == ["File Descriptor JSON format" ], (
67+ f"Only the JSON-format requirement should fail, got: { failed_requirements } "
68+ )
69+
70+ issues = [i .message for i in result .get_issues (models .Severity .REQUIRED ) if i .message ]
71+ assert len (issues ) == 1 , f"Exactly one issue expected, got: { issues } "
72+ assert "is not valid JSON" in issues [0 ]
3773
3874
3975def test_not_valid_jsonld_format_missing_context ():
0 commit comments