Skip to content

Commit

Permalink
Jon improve tests (#26)
Browse files Browse the repository at this point in the history
* Improved Trajectory and VerticalProfile domain tests

* Added tests for all remaining domain types (Point and Polygon-based domains, plus Section)

* Added tests for empty axes
  • Loading branch information
Jon Blower authored Apr 22, 2022
1 parent 5597a78 commit b986422
Show file tree
Hide file tree
Showing 67 changed files with 3,430 additions and 13 deletions.
306 changes: 303 additions & 3 deletions schemas/domainBase.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions schemas/stringSingleValueAxis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$id": "/schemas/stringSingleValueAxis",
"description" : "Axis defined by single string value",
"allOf" :
[
{ "$ref": "/schemas/stringValuesAxis" },
{
"properties" :
{
"values" :
{
"maxItems" : 1
}
}
}
]
}
32 changes: 32 additions & 0 deletions test/domain_types/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ def test_missing_y_axis(validator, grid_domain):
validator.validate(grid_domain)


def test_empty_x_axis(validator, grid_domain):
''' Invalid: Grid domain with empty 'x' axis '''

grid_domain["axes"]["x"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(grid_domain)


def test_empty_y_axis(validator, grid_domain):
''' Invalid: Grid domain with empty 'y' axis '''

grid_domain["axes"]["y"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(grid_domain)


def test_empty_z_axis(validator, grid_domain):
''' Invalid: Grid domain with empty 'z' axis '''

grid_domain["axes"]["z"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(grid_domain)


def test_empty_t_axis(validator, grid_domain):
''' Invalid: Grid domain with empty 't' axis '''

grid_domain["axes"]["t"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(grid_domain)


def test_extra_multi_coordinate_axis(validator, grid_domain):
''' Invalid: Grid domain with unrecognised multi-coordinate axis '''

Expand Down
92 changes: 92 additions & 0 deletions test/domain_types/test_multipoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Pytests to test the MultiPoint domain type in the domain.json schema file

import pytest
from jsonschema.exceptions import ValidationError

pytestmark = pytest.mark.schema("/schemas/domain")


@pytest.mark.exhaustive
def test_valid_multipoint_domain(validator, multipoint_domain):
''' Tests an example of a MultiPoint domain '''

validator.validate(multipoint_domain)


def test_missing_composite_axis(validator, multipoint_domain):
''' Invalid: MultiPoint domain with missing 'composite' axis '''

del multipoint_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_empty_composite_axis(validator, multipoint_domain):
''' Invalid: MultiPoint domain with empty 'composite' axis '''

multipoint_domain["axes"]["composite"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_composite_axis_with_1_value(validator, multipoint_domain):
''' Invalid: MultiPoint domain with composite axis with tuples of length 1 '''

multipoint_domain["axes"]["composite"]["values"] = [
[1],
[2],
[3]
]
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_composite_axis_with_4_values(validator, multipoint_domain):
''' Invalid: MultiPoint domain with composite axis with tuples of length 4 '''

multipoint_domain["axes"]["composite"]["values"] = [
["2008-01-01T04:00:00Z", 1, 1, 1],
["2008-01-01T05:00:00Z", 2, 2, 2],
["2008-01-01T06:00:00Z", 3, 3, 3]
]
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_wrong_composite_axis_type(validator, multipoint_domain):
''' Invalid: MultiPoint domain with primitive instead of tuple axis '''

multipoint_domain["axes"]["composite"] = {
"values": [1, 2, 3]
}
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_extra_axis(validator, multipoint_domain):
''' Invalid: MultiPoint domain with unrecognised extra axis '''

multipoint_domain["axes"]["composite2"] = \
multipoint_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_multivalued_t_axis(validator, multipoint_domain):
''' Invalid: MultiPoint domain with multi-valued 't' axis '''

multipoint_domain["axes"]["t"] = { "values" : ["2008-01-01T04:00:00Z", "2008-01-01T05:00:00Z"] }
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


def test_empty_t_axis(validator, multipoint_domain):
''' Invalid: MultiPoint domain with empty 't' axis '''

multipoint_domain["axes"]["t"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipoint_domain)


# TODO test coordinate identifiers of 'composite' axis
# to be "x","y","z" or "x","y"
93 changes: 93 additions & 0 deletions test/domain_types/test_multipointseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Pytests to test the MultiPointSeries domain type in the domain.json schema file

import pytest
from jsonschema.exceptions import ValidationError

pytestmark = pytest.mark.schema("/schemas/domain")


@pytest.mark.exhaustive
def test_valid_multipointseries_domain(validator, multipointseries_domain):
''' Tests an example of a MultiPointSeries domain '''

validator.validate(multipointseries_domain)


def test_missing_composite_axis(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with missing 'composite' axis '''

del multipointseries_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_empty_composite_axis(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with empty 'composite' axis '''

multipointseries_domain["axes"]["composite"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_missing_t_axis(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with missing 't' axis '''

del multipointseries_domain["axes"]["t"]
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_empty_t_axis(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with empty 't' axis '''

multipointseries_domain["axes"]["t"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_wrong_composite_axis_type(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with primitive instead of tuple axis '''

multipointseries_domain["axes"]["composite"] = {
"values": [1, 2, 3]
}
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_composite_axis_with_1_value(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with composite axis with tuples of length 1 '''

multipointseries_domain["axes"]["composite"]["values"] = [
[1],
[2],
[3]
]
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_composite_axis_with_4_values(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with composite axis with tuples of length 4 '''

multipointseries_domain["axes"]["composite"]["values"] = [
["2008-01-01T04:00:00Z", 1, 1, 1],
["2008-01-01T05:00:00Z", 2, 2, 2],
["2008-01-01T06:00:00Z", 3, 3, 3]
]
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


def test_extra_axis(validator, multipointseries_domain):
''' Invalid: MultiPointSeries domain with unrecognised extra axis '''

multipointseries_domain["axes"]["composite2"] = \
multipointseries_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipointseries_domain)


# TODO test coordinate identifiers of 'composite' axis
# to be "x","y","z" or "x","y"
# TODO test that all values in 'composite' axis are valid and consistent tuples
99 changes: 99 additions & 0 deletions test/domain_types/test_multipolygon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Pytests to test the MultiPolygon domain type in the domain.json schema file

import pytest
from jsonschema.exceptions import ValidationError

pytestmark = pytest.mark.schema("/schemas/domain")


@pytest.mark.exhaustive
def test_valid_multipolygon_domain(validator, multipolygon_domain):
''' Tests an example of a MultiPolygon domain '''

validator.validate(multipolygon_domain)


def test_missing_composite_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with missing 'composite' axis '''

del multipolygon_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_empty_composite_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with empty 'composite' axis '''

multipolygon_domain["axes"]["composite"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_wrong_composite_axis_type(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with primitive instead of polygon axis '''

multipolygon_domain["axes"]["composite"] = {
"values": [1, 2, 3]
}
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_wrong_composite_axis_type2(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with tuple instead of polygon axis (invalid polygons) '''

multipolygon_domain["axes"]["composite"]["values"] = [ [1, 1], [2, 2], [3, 3] ]
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_wrong_data_type(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with wrong data type '''

multipolygon_domain["axes"]["composite"]["dataType"] = "tuple"
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_extra_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with unrecognised extra axis '''

multipolygon_domain["axes"]["composite2"] = \
multipolygon_domain["axes"]["composite"]
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_empty_z_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with empty 'z' axis '''

multipolygon_domain["axes"]["z"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_multivalued_z_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with multi-valued 'z' axis '''

multipolygon_domain["axes"]["z"] = { "values" : [1, 2] }
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_empty_t_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with empty 't' axis '''

multipolygon_domain["axes"]["t"] = { "values" : [] }
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


def test_multivalued_t_axis(validator, multipolygon_domain):
''' Invalid: MultiPolygon domain with multi-valued 't' axis '''

multipolygon_domain["axes"]["t"] = { "values" : ["2008-01-01T04:00:00Z", "2008-01-01T05:00:00Z"] }
with pytest.raises(ValidationError):
validator.validate(multipolygon_domain)


# TODO check coordinates are "x","y", in that order
Loading

0 comments on commit b986422

Please sign in to comment.