@@ -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)
238250def 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)
272300def 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