Skip to content

Commit

Permalink
OGC API Coverages: improve source code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pont-us committed Aug 31, 2023
1 parent 6ac6e89 commit f65860d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
4 changes: 1 addition & 3 deletions test/webapi/ows/coverages/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# DEALINGS IN THE SOFTWARE.



import unittest
from typing import Optional, Union, Mapping, Any

Expand All @@ -31,13 +30,12 @@


def get_coverages_ctx(
server_config: Optional[Union[str, Mapping[str, Any]]] = None
server_config: Optional[Union[str, Mapping[str, Any]]] = None
) -> CoveragesContext:
return get_api_ctx("ows.coverages", CoveragesContext, server_config)


class CoveragesContextTest(unittest.TestCase):

def test_ctx_ok(self):
ctx = get_coverages_ctx()
self.assertIsInstance(ctx.server_ctx, Context)
Expand Down
41 changes: 27 additions & 14 deletions test/webapi/ows/coverages/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@
import rioxarray

from test.webapi.ows.coverages.test_context import get_coverages_ctx
from xcube.webapi.ows.coverages.controllers import get_coverage_as_json, \
get_coverage_data
from xcube.webapi.ows.coverages.controllers import (
get_coverage_as_json,
get_coverage_data,
)


class CoveragesControllersTest(unittest.TestCase):

def test_get_coverage_as_json(self):
result = get_coverage_as_json(get_coverages_ctx().datasets_ctx,
'demo')
result = get_coverage_as_json(get_coverages_ctx().datasets_ctx, 'demo')
self.assertIsInstance(result, dict)
path = Path(__file__).parent / 'expected.json'
# with open(path, mode="w") as fp:
# json.dump(result, fp, indent=2)
with open(path, mode="r") as fp:
expected_result = json.load(fp)
expected_result = json.load(fp)
self.assertEqual(expected_result, result)

def test_get_coverage_data_tiff(self):
query = dict(
bbox=['52,1,51,2'],
datetime=['2017-01-25'],
properties=['conc_chl']
properties=['conc_chl'],
)
result = get_coverage_data(
get_coverages_ctx().datasets_ctx, 'demo', query, 'image/tiff'
)
result = get_coverage_data(get_coverages_ctx().datasets_ctx,
'demo', query, 'image/tiff')
with BytesIO(result) as fh:
da = rioxarray.open_rasterio(fh)
self.assertIsInstance(da, xr.DataArray)
Expand All @@ -65,10 +66,14 @@ def test_get_coverage_data_netcdf(self):
query = dict(
bbox=['52,1,51,2'],
datetime=['2017-01-25'],
properties=['conc_chl,kd489']
properties=['conc_chl,kd489'],
)
result = get_coverage_data(
get_coverages_ctx().datasets_ctx,
'demo',
query,
'application/netcdf',
)
result = get_coverage_data(get_coverages_ctx().datasets_ctx,
'demo', query, 'application/netcdf')
# We can't read this directly from memory: the netcdf4 engine only
# reads from filesystem paths, the h5netcdf engine (which can read
# from memory) isn't an xcube dependency, and the scipy engine only
Expand All @@ -83,6 +88,14 @@ def test_get_coverage_data_netcdf(self):
self.assertEqual(list(ds.data_vars), ['conc_chl', 'kd489'])
self.assertEqual(
list(ds.variables),
['lat', 'lat_bnds', 'lon', 'lon_bnds', 'time', 'time_bnds',
'conc_chl', 'kd489']
[
'lat',
'lat_bnds',
'lon',
'lon_bnds',
'time',
'time_bnds',
'conc_chl',
'kd489',
],
)
9 changes: 6 additions & 3 deletions test/webapi/ows/coverages/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


class CoveragesRoutesTest(RoutesTestCase):

def test_fetch_coverage(self):
response = self.fetch('/catalog/collections/demo/coverage?f=text/json')
self.assertResponseOK(response)
Expand All @@ -33,11 +32,15 @@ def test_fetch_domainset(self):
self.assertResponseOK(response)

def test_fetch_rangetype(self):
response = self.fetch('/catalog/collections/{collectionId}/coverage/rangetype')
response = self.fetch(
'/catalog/collections/{collectionId}/coverage/rangetype'
)
self.assertResponseOK(response)

def test_fetch_metadata(self):
response = self.fetch('/catalog/collections/{collectionId}/coverage/metadata')
response = self.fetch(
'/catalog/collections/{collectionId}/coverage/metadata'
)
self.assertResponseOK(response)

def test_fetch_rangeset(self):
Expand Down
6 changes: 3 additions & 3 deletions xcube/webapi/ows/coverages/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@


class CoveragesContext(ResourcesContext):

def __init__(self, server_ctx: Context):
super().__init__(server_ctx)
self._datasets_ctx = server_ctx.get_api_ctx('datasets',
cls=DatasetsContext)
self._datasets_ctx = server_ctx.get_api_ctx(
'datasets', cls=DatasetsContext
)

@property
def datasets_ctx(self) -> DatasetsContext:
Expand Down

0 comments on commit f65860d

Please sign in to comment.