Skip to content

Commit

Permalink
Add unit test for invalid adjoinedSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrinal-Thomas-Epic committed Oct 9, 2024
1 parent bbaaa0e commit 1d8514e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 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
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 1d8514e

Please sign in to comment.