Skip to content

Commit

Permalink
Add constraint to items in adjoinedSequences (#556)
Browse files Browse the repository at this point in the history
* Add constraint to items in adjoinedSequences

* Add unit test for invalid adjoinedSequence
  • Loading branch information
Mrinal-Thomas-Epic authored Oct 26, 2024
1 parent de23c20 commit af21953
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/invalid_adjacency.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion schema/vrs/json/Adjacency
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions schema/vrs/vrs-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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}")

0 comments on commit af21953

Please sign in to comment.