Skip to content

Commit d76515b

Browse files
committed
Issue #720/#402/#725 re-add tests about create_job/execute_batch with out_format on a result
1 parent 49482bb commit d76515b

File tree

3 files changed

+123
-35
lines changed

3 files changed

+123
-35
lines changed

tests/rest/datacube/test_datacube.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,18 @@ def test_save_result_and_create_job_at_most_one_with_format(
11101110
"result": True,
11111111
}
11121112

1113+
@pytest.mark.parametrize(
1114+
["save_result_format", "execute_format"],
1115+
[
1116+
("NetCDF", "NetCDF"),
1117+
("GTiff", "NetCDF"),
1118+
],
1119+
)
1120+
def test_save_result_and_create_job_both_with_format(self, s2cube, save_result_format, execute_format):
1121+
cube = s2cube.save_result(format=save_result_format)
1122+
with pytest.raises(TypeError, match="got an unexpected keyword argument 'out_format'"):
1123+
cube.create_job(out_format=execute_format)
1124+
11131125
@pytest.mark.parametrize(
11141126
["auto_add_save_result", "process_ids"],
11151127
[
@@ -1231,6 +1243,18 @@ def test_save_result_and_execute_batch_at_most_one_with_format(
12311243
"result": True,
12321244
}
12331245

1246+
@pytest.mark.parametrize(
1247+
["save_result_format", "execute_format"],
1248+
[
1249+
("NetCDF", "NetCDF"),
1250+
("GTiff", "NetCDF"),
1251+
],
1252+
)
1253+
def test_execute_batch_existing_save_result_incompatible(self, s2cube, save_result_format, execute_format):
1254+
cube = s2cube.save_result(format=save_result_format)
1255+
with pytest.raises(TypeError, match="got an unexpected keyword argument 'out_format'"):
1256+
cube.execute_batch(out_format=execute_format)
1257+
12341258
@pytest.mark.parametrize(
12351259
["save_result_format", "execute_output_file", "expected"],
12361260
[

tests/rest/datacube/test_datacube100.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,7 +3527,37 @@ def test_apply_append_math_keep_context(con100):
35273527
({}, "result.tiff", {"format": "GTiff"}, b"this is GTiff data"),
35283528
({}, "result.nc", {"format": "netCDF"}, b"this is netCDF data"),
35293529
({}, "result.meh", {"format": "netCDF"}, b"this is netCDF data"),
3530+
(
3531+
{"format": "GTiff"},
3532+
"result.tiff",
3533+
{"format": "GTiff"},
3534+
TypeError("got an unexpected keyword argument 'format'"),
3535+
),
3536+
(
3537+
{"format": "netCDF"},
3538+
"result.tiff",
3539+
{"format": "NETCDF"},
3540+
TypeError("got an unexpected keyword argument 'format'"),
3541+
),
3542+
(
3543+
{"format": "netCDF"},
3544+
"result.json",
3545+
{"format": "JSON"},
3546+
TypeError("got an unexpected keyword argument 'format'"),
3547+
),
35303548
({"options": {}}, "result.tiff", {}, b"this is GTiff data"),
3549+
(
3550+
{"options": {"quality": "low"}},
3551+
"result.tiff",
3552+
{"options": {"quality": "low"}},
3553+
TypeError("got an unexpected keyword argument 'options'"),
3554+
),
3555+
(
3556+
{"options": {"colormap": "jet"}},
3557+
"result.tiff",
3558+
{"options": {"quality": "low"}},
3559+
TypeError("got an unexpected keyword argument 'options'"),
3560+
),
35313561
],
35323562
)
35333563
def test_save_result_and_download(
@@ -3550,15 +3580,17 @@ def post_result(request, context):
35503580

35513581
cube = con100.load_collection("S2")
35523582
if save_result_kwargs:
3553-
res = cube.save_result(**save_result_kwargs)
3554-
else:
3555-
res = cube
3583+
cube = cube.save_result(**save_result_kwargs)
35563584

35573585
path = tmp_path / download_filename
3558-
res.download(str(path), **download_kwargs)
3559-
3560-
assert path.read_bytes() == expected
3561-
assert post_result_mock.call_count == 1
3586+
if isinstance(expected, Exception):
3587+
with pytest.raises(type(expected), match=re.escape(str(expected))):
3588+
cube.download(str(path), **download_kwargs)
3589+
assert post_result_mock.call_count == 0
3590+
else:
3591+
cube.download(str(path), **download_kwargs)
3592+
assert path.read_bytes() == expected
3593+
assert post_result_mock.call_count == 1
35623594

35633595

35643596
@pytest.mark.parametrize(

tests/rest/datacube/test_vectorcube.py

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -230,31 +230,47 @@ def test_save_result_and_download_filename(
230230
(None, None, "result.geojson", "GeoJSON"),
231231
("GeoJSON", None, None, "GeoJSON"),
232232
(None, "GeoJSON", None, "GeoJSON"),
233+
(
234+
"GeoJSON",
235+
"GeoJSON",
236+
None,
237+
TypeError("got an unexpected keyword argument 'format'"),
238+
),
233239
(None, None, "result.nc", "netCDF"),
234240
("netCDF", None, None, "netCDF"),
235241
(None, "netCDF", None, "netCDF"),
242+
(
243+
"GeoJson",
244+
"netCDF",
245+
None,
246+
TypeError("got an unexpected keyword argument 'format'"),
247+
),
236248
],
237249
)
238250
def test_save_result_and_download_with_format(
239251
vector_cube, dummy_backend, tmp_path, save_result_format, execute_format, output_file, expected
240252
):
241253
if save_result_format:
242-
res = vector_cube.save_result(format=save_result_format)
243-
else:
244-
res = vector_cube
245-
254+
vector_cube = vector_cube.save_result(format=save_result_format)
246255
output_path = tmp_path / (output_file or "data")
247-
if execute_format:
248-
res.download(output_path, format=execute_format)
249-
else:
250-
res.download(output_path)
251256

252-
assert dummy_backend.get_pg()["saveresult1"] == {
253-
"process_id": "save_result",
254-
"arguments": {"data": {"from_node": "loadgeojson1"}, "format": expected, "options": {}},
255-
"result": True,
256-
}
257-
assert output_path.read_bytes() == DummyBackend.DEFAULT_RESULT
257+
def do_it():
258+
if execute_format:
259+
vector_cube.download(output_path, format=execute_format)
260+
else:
261+
vector_cube.download(output_path)
262+
263+
if isinstance(expected, Exception):
264+
with pytest.raises(type(expected), match=re.escape(str(expected))):
265+
do_it()
266+
else:
267+
do_it()
268+
assert dummy_backend.get_pg()["saveresult1"] == {
269+
"process_id": "save_result",
270+
"arguments": {"data": {"from_node": "loadgeojson1"}, "format": expected, "options": {}},
271+
"result": True,
272+
}
273+
assert output_path.read_bytes() == DummyBackend.DEFAULT_RESULT
258274

259275

260276
@pytest.mark.parametrize(
@@ -264,31 +280,47 @@ def test_save_result_and_download_with_format(
264280
(None, None, "result.geojson", "GeoJSON"),
265281
("GeoJSON", None, None, "GeoJSON"),
266282
(None, "GeoJSON", None, "GeoJSON"),
283+
(
284+
"GeoJSON",
285+
"GeoJSON",
286+
None,
287+
TypeError("got an unexpected keyword argument 'out_format'"),
288+
),
267289
(None, None, "result.nc", "netCDF"),
268290
("netCDF", None, None, "netCDF"),
269291
(None, "netCDF", None, "netCDF"),
292+
(
293+
"GeoJson",
294+
"netCDF",
295+
None,
296+
TypeError("got an unexpected keyword argument 'out_format'"),
297+
),
270298
],
271299
)
272300
def test_save_result_and_execute_batch_with_format(
273301
vector_cube, dummy_backend, tmp_path, save_result_format, execute_format, output_file, expected
274302
):
275303
if save_result_format:
276-
res = vector_cube.save_result(format=save_result_format)
277-
else:
278-
res = vector_cube
279-
304+
vector_cube = vector_cube.save_result(format=save_result_format)
280305
output_path = tmp_path / (output_file or "data")
281-
if execute_format:
282-
res.execute_batch(outputfile=output_path, out_format=execute_format)
283-
else:
284-
res.execute_batch(outputfile=output_path)
285306

286-
assert dummy_backend.get_pg()["saveresult1"] == {
287-
"process_id": "save_result",
288-
"arguments": {"data": {"from_node": "loadgeojson1"}, "format": expected, "options": {}},
289-
"result": True,
290-
}
291-
assert output_path.read_bytes() == DummyBackend.DEFAULT_RESULT
307+
def do_it():
308+
if execute_format:
309+
vector_cube.execute_batch(outputfile=output_path, out_format=execute_format)
310+
else:
311+
vector_cube.execute_batch(outputfile=output_path)
312+
313+
if isinstance(expected, Exception):
314+
with pytest.raises(type(expected), match=re.escape(str(expected))):
315+
do_it()
316+
else:
317+
do_it()
318+
assert dummy_backend.get_pg()["saveresult1"] == {
319+
"process_id": "save_result",
320+
"arguments": {"data": {"from_node": "loadgeojson1"}, "format": expected, "options": {}},
321+
"result": True,
322+
}
323+
assert output_path.read_bytes() == DummyBackend.DEFAULT_RESULT
292324

293325

294326
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)