Skip to content

Commit fba089f

Browse files
jbuseckeJulius Buseckehrodmn
authored
Parametrize test functions (#95)
--------- Co-authored-by: Julius Busecke <[email protected]> Co-authored-by: Henry Rodman <[email protected]>
1 parent 7d8869d commit fba089f

File tree

1 file changed

+27
-76
lines changed

1 file changed

+27
-76
lines changed

tests/test_app.py

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import pytest
34

45
from helpers import find_string_in_stream
56

@@ -9,7 +10,9 @@
910
test_unconsolidated_store = os.path.join(DATA_DIR, "unconsolidated.zarr")
1011
test_pyramid_store = os.path.join(DATA_DIR, "pyramid.zarr")
1112

12-
test_zarr_store_params = {
13+
store_params = {}
14+
15+
store_params["zarr_store"] = {
1316
"params": {
1417
"url": test_zarr_store,
1518
"variable": "CDD0",
@@ -19,7 +22,7 @@
1922
"variables": ["CDD0", "DISPH", "FROST_DAYS", "GWETPROF"],
2023
}
2124

22-
test_netcdf_store_params = {
25+
store_params["netcdf_store"] = {
2326
"params": {
2427
"url": test_netcdf_store,
2528
"variable": "data",
@@ -28,7 +31,7 @@
2831
},
2932
"variables": ["data"],
3033
}
31-
test_unconsolidated_store_params = {
34+
store_params["unconsolidated_store"] = {
3235
"params": {
3336
"url": test_unconsolidated_store,
3437
"variable": "var1",
@@ -37,7 +40,7 @@
3740
},
3841
"variables": ["var1", "var2"],
3942
}
40-
test_pyramid_store_params = {
43+
store_params["pyramid_store"] = {
4144
"params": {
4245
"url": test_pyramid_store,
4346
"variable": "value",
@@ -60,20 +63,9 @@ def get_variables_test(app, ds_params):
6063
assert timings[1].lstrip().startswith("1-xarray-open_dataset;dur=")
6164

6265

63-
def test_get_variables_test(app):
64-
return get_variables_test(app, test_zarr_store_params)
65-
66-
67-
def test_get_variables_netcdf(app):
68-
return get_variables_test(app, test_netcdf_store_params)
69-
70-
71-
def test_get_variables_unconsolidated(app):
72-
return get_variables_test(app, test_unconsolidated_store_params)
73-
74-
75-
def test_get_variables_pyramid(app):
76-
return get_variables_test(app, test_pyramid_store_params)
66+
@pytest.mark.parametrize("store_params", store_params.values(), ids=store_params.keys())
67+
def test_get_variables(store_params, app):
68+
return get_variables_test(app, store_params)
7769

7870

7971
def get_info_test(app, ds_params):
@@ -90,20 +82,9 @@ def get_info_test(app, ds_params):
9082
assert response.json() == json.load(f)
9183

9284

93-
def test_get_info_test(app):
94-
return get_info_test(app, test_zarr_store_params)
95-
96-
97-
def test_get_info_netcdf(app):
98-
return get_info_test(app, test_netcdf_store_params)
99-
100-
101-
def test_get_info_unconsolidated(app):
102-
return get_info_test(app, test_unconsolidated_store_params)
103-
104-
105-
def test_get_info_pyramid(app):
106-
return get_info_test(app, test_pyramid_store_params)
85+
@pytest.mark.parametrize("store_params", store_params.values(), ids=store_params.keys())
86+
def test_get_info(store_params, app):
87+
return get_info_test(app, store_params)
10788

10889

10990
def get_tilejson_test(app, ds_params):
@@ -121,20 +102,9 @@ def get_tilejson_test(app, ds_params):
121102
assert response.json() == json.load(f)
122103

123104

124-
def test_get_tilejson_test(app):
125-
return get_tilejson_test(app, test_zarr_store_params)
126-
127-
128-
def test_get_tilejson_netcdf(app):
129-
return get_tilejson_test(app, test_netcdf_store_params)
130-
131-
132-
def test_get_tilejson_unconsolidated(app):
133-
return get_tilejson_test(app, test_unconsolidated_store_params)
134-
135-
136-
def test_get_tilejson_pyramid(app):
137-
return get_tilejson_test(app, test_pyramid_store_params)
105+
@pytest.mark.parametrize("store_params", store_params.values(), ids=store_params.keys())
106+
def test_get_tilejson(store_params, app):
107+
return get_tilejson_test(app, store_params)
138108

139109

140110
def get_tile_test(app, ds_params, zoom: int = 0):
@@ -151,22 +121,14 @@ def get_tile_test(app, ds_params, zoom: int = 0):
151121
assert timings[2].lstrip().startswith("2-rioxarray-reproject;dur=")
152122

153123

154-
def test_get_tile_test(app):
155-
return get_tile_test(app, test_zarr_store_params)
156-
157-
158-
def test_get_tile_netcdf(app):
159-
return get_tile_test(app, test_netcdf_store_params)
160-
161-
162-
def test_get_tile_unconsolidated(app):
163-
return get_tile_test(app, test_unconsolidated_store_params)
164-
165-
166-
def test_get_tile_pyramid(app):
167-
# test that even a group outside of the range will return a tile
168-
for z in range(3):
169-
get_tile_test(app, test_pyramid_store_params, zoom=z)
124+
@pytest.mark.parametrize("store_params", store_params.values(), ids=store_params.keys())
125+
def test_get_tile(store_params, app):
126+
# if the store is a pyramid we test zoom levels 0-2
127+
if "group" in store_params["params"]:
128+
for z in range(3):
129+
get_tile_test(app, store_params, zoom=z)
130+
else:
131+
get_tile_test(app, store_params)
170132

171133

172134
def histogram_test(app, ds_params):
@@ -182,20 +144,9 @@ def histogram_test(app, ds_params):
182144
assert response.json() == json.load(f)
183145

184146

185-
def test_histogram_test(app):
186-
return histogram_test(app, test_zarr_store_params)
187-
188-
189-
def test_histogram_netcdf(app):
190-
return histogram_test(app, test_netcdf_store_params)
191-
192-
193-
def test_histogram_unconsolidated(app):
194-
return histogram_test(app, test_unconsolidated_store_params)
195-
196-
197-
def test_histogram_pyramid(app):
198-
return histogram_test(app, test_pyramid_store_params)
147+
@pytest.mark.parametrize("store_params", store_params.values(), ids=store_params.keys())
148+
def test_histogram(store_params, app):
149+
return histogram_test(app, store_params)
199150

200151

201152
def test_histogram_error(app):

0 commit comments

Comments
 (0)