@@ -38,14 +38,15 @@ def test_clear_directory(tmp_path):
3838 assert os .listdir (tmp_path ) == []
3939
4040
41- @pytest .mark .parametrize ("write_zarrs" , [False , True ])
42- def test_write_stac (tmp_path , dataset , write_zarrs ):
43- datasets = {"ds1" : dataset , "ds2" : dataset }
44- if write_zarrs :
41+ @pytest .mark .parametrize ("write_datasets" , [False , True ])
42+ def test_write_stac (tmp_path , dataset , write_datasets ):
43+ datasets = {"ds1" : dataset , "ds2" : dataset .copy ()}
44+ datasets ["ds2" ].attrs ["xcengine_output_format" ] = "netcdf"
45+ if write_datasets :
4546 output_path = tmp_path / "output"
4647 output_path .mkdir ()
47- for ds_id , ds in datasets . items ():
48- ds . to_zarr (output_path / (ds_id + ".zarr " ))
48+ datasets [ "ds1" ]. to_zarr ( output_path / ( "ds1.zarr" ))
49+ datasets [ "ds2" ]. to_netcdf (output_path / ("ds2.nc " ))
4950
5051 write_stac (datasets , tmp_path )
5152 catalog = pystac .Catalog .from_file (tmp_path / "catalog.json" )
@@ -57,21 +58,27 @@ def test_write_stac(tmp_path, dataset, write_zarrs):
5758 for item in items
5859 }
5960 assert data_asset_hrefs == {
60- ds_id : [
61- str (Path (tmp_path / ds_id / f"{ ds_id } .zarr" ).resolve (strict = False ))
62- ]
63- for ds_id in datasets .keys ()
61+ "ds1" : [str ((tmp_path / "ds1" / "ds1.zarr" ).resolve (strict = False ))],
62+ "ds2" : [str ((tmp_path / "ds2" / "ds2.nc" ).resolve (strict = False ))],
6463 }
6564
6665
6766@pytest .mark .parametrize ("eoap_mode" , [False , True ])
68- def test_save_datasets (tmp_path , dataset , eoap_mode ):
69- datasets = {"ds1" : dataset , "ds2" : dataset }
67+ @pytest .mark .parametrize ("ds2_format" , [None , "zarr" , "netcdf" ])
68+ def test_save_datasets (tmp_path , dataset , eoap_mode , ds2_format ):
69+ datasets = {"ds1" : dataset , "ds2" : dataset .copy ()}
70+ if ds2_format is not None :
71+ datasets ["ds2" ].attrs ["xcengine_output_format" ] = ds2_format
7072 save_datasets (datasets , tmp_path , eoap_mode )
71- for ds_id in datasets .keys ():
72- assert (
73- tmp_path / (ds_id if eoap_mode else "output" ) / (ds_id + ".zarr" )
74- ).is_dir ()
73+ def outdir (ds_id ):
74+ return tmp_path / (ds_id if eoap_mode else "output" )
75+ assert (outdir ("ds1" ) / "ds1.zarr" ).is_dir ()
76+ ds2_suffix = "nc" if ds2_format == "netcdf" else "zarr"
77+ ds2_path = outdir ("ds2" ) / f"ds2.{ ds2_suffix } "
78+ if ds2_format == "netcdf" :
79+ assert ds2_path .is_file ()
80+ else :
81+ assert ds2_path .is_dir ()
7582 catalogue_path = tmp_path / "catalog.json"
7683 if eoap_mode :
7784 assert catalogue_path .is_file ()
0 commit comments