diff --git a/examples/invalid_adjacency.yaml b/examples/invalid_adjacency.yaml new file mode 100644 index 00000000..853d0282 --- /dev/null +++ b/examples/invalid_adjacency.yaml @@ -0,0 +1,18 @@ +id: simple_breakpoint +type: Adjacency +adjoinedSequences: + - type: SequenceLocation + sequenceReference: + type: SequenceReference + refgetAccession: SQ.S_KjnFVz-FE7M0W6yoaUDgYxLPc1jyWU + residueAlphabet: na + id: NC_000001.10 + start: 100 + end: 200 + - type: SequenceLocation + sequenceReference: + type: SequenceReference + refgetAccession: SQ.9KdcA9ZpY1Cpvxvg8bMSLYDUpsX6GDLO + residueAlphabet: na + id: NC_000002.11 + start: 456 \ No newline at end of file diff --git a/schema/vrs/json/Adjacency b/schema/vrs/json/Adjacency index 1283335a..eb578ddc 100644 --- a/schema/vrs/json/Adjacency +++ b/schema/vrs/json/Adjacency @@ -74,7 +74,13 @@ { "$ref": "/ga4gh/schema/gks-common/1.x/core-im/json/IRI" } - ] + ], + "not": { + "required": [ + "start", + "end" + ] + } }, "description": "The terminal sequence or pair of adjoined sequences that defines in the adjacency.", "minItems": 2, diff --git a/schema/vrs/vrs-source.yaml b/schema/vrs/vrs-source.yaml index 09ee9bf3..896cb288 100644 --- a/schema/vrs/vrs-source.yaml +++ b/schema/vrs/vrs-source.yaml @@ -516,6 +516,8 @@ $defs: oneOf: - $ref: "/ga4gh/schema/gks-common/1.x/core-im/json/IRI" - $ref: "#/$defs/Location" + not: + required: ["start", "end"] description: The terminal sequence or pair of adjoined sequences that defines in the adjacency. minItems: 2 maxItems: 2 diff --git a/tests/test_definitions.yaml b/tests/test_definitions.yaml index 881a0f23..82bf3513 100644 --- a/tests/test_definitions.yaml +++ b/tests/test_definitions.yaml @@ -46,3 +46,8 @@ tests: description: A simple RLE expansion from SPDI representation schema: vrs definition: Allele + - test_file: invalid_adjacency.yaml + description: An adjacency with an adjoinedSequence incorrectly containing both a start and end + schema: vrs + definition: Adjacency + shouldValidationFail: true \ No newline at end of file diff --git a/tests/test_examples.py b/tests/test_examples.py index 76a38265..58ea9b70 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -1,7 +1,9 @@ from config import test_path, examples_path import yaml from config import validator - +from pytest import raises +from jsonschema.exceptions import ValidationError +from contextlib import nullcontext def test_examples(): with open(test_path / 'test_definitions.yaml') as def_file: @@ -10,7 +12,9 @@ def test_examples(): with open(examples_path / test['test_file']) as datafile: data = yaml.safe_load(datafile) class_validator = validator[test['definition']] + try: - assert class_validator.validate(data) is None + with raises(ValidationError) if test.get("shouldValidationFail") else nullcontext(): + assert class_validator.validate(data) is None except AssertionError as e: raise AssertionError(f"AssertionError in {test['test_file']}: {e}")