Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nextstrain/augur
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d763c05bc0c26feeb95a11adaa51b490e4cabf7c
Choose a base ref
..
head repository: nextstrain/augur
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 35c688c9b9932d03cf0836059cdf116b5dfbdee8
Choose a head ref
Showing with 80 additions and 5 deletions.
  1. +8 −4 augur/data/schema-annotations.json
  2. +72 −1 tests/test_validate.py
12 changes: 8 additions & 4 deletions augur/data/schema-annotations.json
Original file line number Diff line number Diff line change
@@ -7,10 +7,14 @@
"type": "object",
"allOf": [{ "$ref": "#/$defs/startend" }],
"properties": {
"start": {
"enum": [1],
"$comment": "nuc must begin at 1"
},
"strand": {
"type": "string",
"not": {"enum":["-"]},
"$comment": "Auspice assumes +ve strand for 'nuc', but will not proceed if you specify '-'"
"$comment": "The strand for 'nuc' is not needed, as it should be +ve for all genomes. Auspice will not proceed if you specify '-'"
}
},
"additionalProperties": true,
@@ -32,9 +36,9 @@
"$comment": "Shown in on-hover infobox & influences default CDS colors"
},
"strand": {
"description": "Is the CDS on the positive ('+') or negative ('-') strand.",
"$comment": "Auspice assumes positive strand unless strand is '-'",
"type": "string"
"description": "Strand of the CDS",
"type": "string",
"enum": ["-", "+"]
},
"color": {
"type": "string",
73 changes: 72 additions & 1 deletion tests/test_validate.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,10 @@
from augur.validate import (
validate_collection_config_fields,
validate_collection_display_defaults,
validate_measurements_config
validate_measurements_config,
load_json_schema,
validate_json,
ValidateError
)


@@ -88,3 +91,71 @@ def test_validate_measurements_config_invalid_default_collection(self, example_m
}
assert not validate_measurements_config(measurements)
assert capsys.readouterr().err == "ERROR: The default collection key 'invalid_collection' does not match any of the collections' keys.\n"


@pytest.fixture
def genome_annotation_schema():
return load_json_schema("schema-annotations.json")

class TestValidateGenomeAnnotations():
def test_negative_strand_nuc(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 200, "strand": "-"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_nuc_not_starting_at_one(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 100, "end": 200, "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_missing_nuc(self, capsys, genome_annotation_schema):
d = {"cds": {"start": 100, "end": 200, "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_missing_properties(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100}, "cds": {"start": 20, "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_not_stranded_cds(self, capsys, genome_annotation_schema):
# Strand . is for features that are not stranded (as per GFF spec), and thus they're not CDSs
d = {"nuc": {"start": 1, "end": 100}, "cds": {"start": 18, "end": 20, "strand": "."}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_negative_coordinates(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100}, "cds": {"start": -2, "end": 10, "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_valid_genome(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100}, "cds": {"start": 20, "end": 28, "strand": "+"}}
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_valid_segmented_genome(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100},
"cds": {"segments": [{"start": 20, "end": 28}], "strand": "+"}}
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_invalid_segmented_genome(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100},
"cds": {"segments": [{"start": 20, "end": 28}, {"start": 27}], "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing

def test_string_coordinates(self, capsys, genome_annotation_schema):
d = {"nuc": {"start": 1, "end": 100},
"cds": {"segments": [{"start": 20, "end": 28}, {"start": "27", "end": "29"}], "strand": "+"}}
with pytest.raises(ValidateError):
validate_json(d, genome_annotation_schema, "<test-json>")
capsys.readouterr() # suppress validation error printing