@@ -232,11 +232,10 @@ def test_write_assets_samples_tile_grid_batch(self, tmp_path):
232
232
@pytest .mark .parametrize ("space_type" , ["spacetime" , "spatial" ])
233
233
@pytest .mark .parametrize ("stitch" , [False , True ])
234
234
@pytest .mark .parametrize ("catalog" , [False , True ])
235
- @pytest .mark .parametrize ("sample_by_feature" , [False , True ])
236
235
@pytest .mark .parametrize ("format_arg" , ["netCDF" ]) # "GTIFF" behaves different from "netCDF", so not testing now
237
236
def test_write_assets_parameterize_batch (self , tmp_path , imagecollection_with_two_bands_and_three_dates ,
238
237
imagecollection_with_two_bands_spatial_only ,
239
- format_arg , sample_by_feature , catalog , stitch , space_type ,
238
+ format_arg , catalog , stitch , space_type ,
240
239
tile_grid , filename_prefix ):
241
240
d = locals ()
242
241
d = {i : d [i ] for i in d if i != 'self' and i != "tmp_path" and i != "d" }
@@ -248,7 +247,7 @@ def test_write_assets_parameterize_batch(self, tmp_path, imagecollection_with_tw
248
247
imagecollection = imagecollection_with_two_bands_spatial_only
249
248
250
249
geometries = geojson_to_geometry (self .features )
251
- assets = imagecollection .write_assets (
250
+ items = imagecollection .write_assets (
252
251
str (tmp_path / "ignored<\0 >.extension" ), # null byte to cause error if filename would be written to fs
253
252
format = format_arg ,
254
253
format_options = {
@@ -261,6 +260,8 @@ def test_write_assets_parameterize_batch(self, tmp_path, imagecollection_with_tw
261
260
"tile_grid" : tile_grid ,
262
261
}
263
262
)
263
+
264
+ assets = [(asset_key , asset ) for item in items .values () for asset_key , asset in item ["assets" ].items ()]
264
265
with open (self .test_write_assets_parameterize_batch_path + test_name + ".json" , 'w' ) as fp :
265
266
json .dump (assets , fp , indent = 2 )
266
267
@@ -269,13 +270,15 @@ def test_write_assets_parameterize_batch(self, tmp_path, imagecollection_with_tw
269
270
else :
270
271
extension = ".tif"
271
272
assert len (assets ) >= 3
272
- assert len (assets ) <= geometries .length
273
+ assert len (assets ) <= geometries .length # a netCDF asset contains all dates
274
+ assert {asset_key for asset_key , _ in assets } == {"openEO" }
275
+ asset_filenames = {Path (asset ["href" ]).name for _ , asset in assets }
273
276
if format_arg == "netCDF" :
274
277
if filename_prefix :
275
- assert assets [ filename_prefix + "_0" + extension ]
278
+ assert filename_prefix + "_0" + extension in asset_filenames
276
279
else :
277
- assert assets [ "openEO_0" + extension ]
278
- name , asset = next ( iter ( assets . items ()))
280
+ assert "openEO_0" + extension in asset_filenames
281
+ _ , asset = assets [ 0 ]
279
282
assert Path (asset ['href' ]).parent == tmp_path
280
283
if filename_prefix :
281
284
assert filename_prefix in asset ['href' ]
@@ -340,7 +343,7 @@ def test_write_assets_parameterize(self, tmp_path, imagecollection_with_two_band
340
343
assert False
341
344
filename = "test_download_result" + extension
342
345
geometries = geojson_to_geometry (self .features )
343
- assets_all = imagecollection .write_assets (
346
+ items_all = imagecollection .write_assets (
344
347
str (tmp_path / filename ),
345
348
format = format_arg ,
346
349
format_options = {
@@ -365,18 +368,19 @@ def test_write_assets_parameterize(self, tmp_path, imagecollection_with_two_band
365
368
# with open(self.test_write_assets_parameterize_path + test_name + ".json", 'w') as fp:
366
369
# json.dump(assets, fp, indent=2)
367
370
368
- assets_data = {k : v for (k , v ) in assets_all .items () if "data" in v ["roles" ]}
369
- name , asset = next (iter (assets_data .items ()))
371
+ assets_all = [(asset_key , asset ) for item in items_all .values () for asset_key , asset in item ["assets" ].items ()]
372
+ assets_data = [(asset_key , asset ) for asset_key , asset in assets_all if "data" in asset ["roles" ]]
373
+ name , asset = assets_data [0 ]
370
374
print ("href of first asset: " + asset ["href" ])
371
- assets_metadata = { k : v for ( k , v ) in assets_all . items () if "data" not in v ["roles" ]}
375
+ assets_metadata = [( asset_key , asset ) for asset_key , asset in assets_all if "data" not in asset ["roles" ]]
372
376
if format_arg == "GTIFF" and not catalog :
373
377
if attach_gdalinfo_assets :
374
378
assert len (assets_metadata ) == len (assets_data )
375
379
else :
376
380
assert len (assets_metadata ) == 0
377
381
378
382
if len (assets_data ) == 1 :
379
- assert assets_data [filename ]
383
+ assert assets_data [0 ][ 0 ] == "openEO"
380
384
assert filename in asset ['href' ]
381
385
else :
382
386
if filename_prefix :
0 commit comments