Skip to content

Commit

Permalink
add more tests for identifier and geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Aug 28, 2024
1 parent 1582632 commit ed38217
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pywcmp/wcmp2/ets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import uuid

from jsonschema.validators import Draft202012Validator
from shapely.geometry import shape

import pywcmp
from pywcmp.bundle import WCMP2_FILES
Expand Down Expand Up @@ -169,6 +170,11 @@ def test_requirement_identifier(self):
status['message'] = 'bad prefix'
return status

if ' ' in identifier_tokens[-1]:
status['code'] = 'FAILED'
status['message'] = 'spaces in local identifier'
return status

centre_id = identifier_tokens[3]

if centre_id.endswith('-test'):
Expand Down Expand Up @@ -228,9 +234,19 @@ def test_requirement_extent_geospatial(self):
status = {
'id': gen_test_id('extent_geospatial'),
'code': 'PASSED',
'message': 'Passes given schema is compliant/valid'
}

if self.record['geometry'] is not None:
geometry = shape(self.record['geometry'])
bounds = geometry.bounds

if not all([-180 <= bounds[0] <= 180,
-90 <= bounds[1] <= 90,
-180 <= bounds[2] <= 180,
-90 <= bounds[3] <= 90]):
status['code'] = 'FAILED'
status['messsage'] = 'Invalid geometry'

return status

def test_requirement_extent_temporal(self):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ click
jsonschema>4.19
pyspellchecker
pywis-topics
shapely
161 changes: 161 additions & 0 deletions tests/data/wcmp2-failing-invalid-geometry-range.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"id": "urn:wmo:md:ca-eccc-msc:weather.observations.swob-realtime",
"conformsTo": [
"http://wis.wmo.int/spec/wcmp/2/conf/core"
],
"time": {
"interval": [
"2010-11-11T11:11:11Z",
".."
],
"resolution": "P1H"
},
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-242,
28
],
[
-142,
82
],
[
-52,
82
],
[
-52,
28
],
[
-142,
28
]
]
]
},
"properties": {
"title": "Surface weather observations",
"description": "Surface Observations measured at the automatic and manual stations of the Environment and Climate Change Canada and partners networks, either for a single station, or for the stations of specific provinces and territories (last 30 days)",
"themes": [
{
"concepts": [
{
"id": "Weather"
},
{
"id": "Archives"
},
{
"id": "Precipitation"
},
{
"id": "Air temperature"
},
{
"id": "Humidity"
},
{
"id": "Snow"
},
{
"id": "Wind"
},
{
"id": "Meteorological data"
}
],
"scheme": "https://library-archives.canada.ca/eng/services/government-canada/controlled-vocabularies-government-canada/pages/controlled-vocabularies-government-canada.aspx"
},
{
"concepts": [
{
"id": "weather"
}
],
"scheme": "https://codes.wmo.int/wis/topic-hierarchy/earth-system-discipline"
}
],
"contacts": [
{
"organization": "Government of Canada; Environment and Climate Change Canada; Meteorological Service of Canada",
"position": "National Inquiry Response Team",
"phones": [
{
"value": "+18199972800"
}
],
"emails": [
{
"value": "[email protected]"
}
],
"addresses": [
{
"deliveryPoint": [
"77 Westmorland Street, suite 260"
],
"city": "Fredericton",
"administrativeArea": "NB",
"postalCode": "E3B 6Z4",
"country": "Canada"
}
],
"links": [
{
"rel": "canonical",
"type": "text/html",
"href": "https://eccc-msc.github.io/open-data"
}
],
"contactInstructions": "via email",
"roles": [
"host",
"producer"
]
}
],
"type": "dataset",
"created": "2018-01-01T11:11:11Z",
"updated": "2022-06-22T12:42:46Z",
"wmo:dataPolicy": "core"
},
"links": [
{
"rel": "stations",
"href": "https://dd.weather.gc.ca/observations/doc/swob-xml_station_list.csv",
"type": "text/csv",
"title": "Stations associated with this dataset"
},
{
"rel": "data",
"href": "https://dd.weather.gc.ca/observations/swob-ml",
"type": "text/html",
"hreflang": "en",
"title": "Raw data download (CSV files)"
},
{
"rel": "items",
"href": "https://api.weather.gc.ca/collections/swob-realtime/items",
"type": "application/json",
"title": "Data access API interface"
},
{
"rel": "related",
"href": "https://eccc-msc.github.io/open-data/msc-data/obs_station/readme_obs_insitu_swobdatamart_en",
"type": "text/html",
"title": "Documentation"
},
{
"rel": "items",
"href": "mqtt://example.org:8883",
"channel": "origin/a/wis2/ca-eccc-msc/data/core/weather/surface-based-observations/synop",
"type": "application/json",
"title": "Data notifications"
}
]
}
161 changes: 161 additions & 0 deletions tests/data/wcmp2-failing-invalid-identifier-space.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"id": "urn:wmo:md:ca-eccc-msc:weather.observations.swob realtime",
"conformsTo": [
"http://wis.wmo.int/spec/wcmp/2/conf/core"
],
"time": {
"interval": [
"2010-11-11T11:11:11Z",
".."
],
"resolution": "P1H"
},
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-142,
28
],
[
-142,
82
],
[
-52,
82
],
[
-52,
28
],
[
-142,
28
]
]
]
},
"properties": {
"title": "Surface weather observations",
"description": "Surface Observations measured at the automatic and manual stations of the Environment and Climate Change Canada and partners networks, either for a single station, or for the stations of specific provinces and territories (last 30 days)",
"themes": [
{
"concepts": [
{
"id": "Weather"
},
{
"id": "Archives"
},
{
"id": "Precipitation"
},
{
"id": "Air temperature"
},
{
"id": "Humidity"
},
{
"id": "Snow"
},
{
"id": "Wind"
},
{
"id": "Meteorological data"
}
],
"scheme": "https://library-archives.canada.ca/eng/services/government-canada/controlled-vocabularies-government-canada/pages/controlled-vocabularies-government-canada.aspx"
},
{
"concepts": [
{
"id": "weather"
}
],
"scheme": "https://codes.wmo.int/wis/topic-hierarchy/earth-system-discipline"
}
],
"contacts": [
{
"organization": "Government of Canada; Environment and Climate Change Canada; Meteorological Service of Canada",
"position": "National Inquiry Response Team",
"phones": [
{
"value": "+18199972800"
}
],
"emails": [
{
"value": "[email protected]"
}
],
"addresses": [
{
"deliveryPoint": [
"77 Westmorland Street, suite 260"
],
"city": "Fredericton",
"administrativeArea": "NB",
"postalCode": "E3B 6Z4",
"country": "Canada"
}
],
"links": [
{
"rel": "canonical",
"type": "text/html",
"href": "https://eccc-msc.github.io/open-data"
}
],
"contactInstructions": "via email",
"roles": [
"host",
"producer"
]
}
],
"type": "dataset",
"created": "2018-01-01T11:11:11Z",
"updated": "2022-06-22T12:42:46Z",
"wmo:dataPolicy": "core"
},
"links": [
{
"rel": "stations",
"href": "https://dd.weather.gc.ca/observations/doc/swob-xml_station_list.csv",
"type": "text/csv",
"title": "Stations associated with this dataset"
},
{
"rel": "data",
"href": "https://dd.weather.gc.ca/observations/swob-ml",
"type": "text/html",
"hreflang": "en",
"title": "Raw data download (CSV files)"
},
{
"rel": "items",
"href": "https://api.weather.gc.ca/collections/swob-realtime/items",
"type": "application/json",
"title": "Data access API interface"
},
{
"rel": "related",
"href": "https://eccc-msc.github.io/open-data/msc-data/obs_station/readme_obs_insitu_swobdatamart_en",
"type": "text/html",
"title": "Documentation"
},
{
"rel": "items",
"href": "mqtt://example.org:8883",
"channel": "origin/a/wis2/ca-eccc-msc/data/core/weather/surface-based-observations/synop",
"type": "application/json",
"title": "Data notifications"
}
]
}
Loading

0 comments on commit ed38217

Please sign in to comment.