1515from virtualizarr .readers .hdf import HDFVirtualBackend
1616from virtualizarr .tests import (
1717 has_astropy ,
18- requires_kerchunk ,
18+ parametrize_over_hdf_backends ,
19+ requires_hdf5plugin ,
20+ requires_imagecodecs ,
1921 requires_network ,
2022 requires_s3fs ,
2123 requires_scipy ,
@@ -82,13 +84,14 @@ def test_FileType():
8284 FileType (None )
8385
8486
85- @requires_kerchunk
86- @pytest .mark .parametrize ("hdf_backend" , [HDF5VirtualBackend , HDFVirtualBackend ])
87+ @parametrize_over_hdf_backends
8788class TestOpenVirtualDatasetIndexes :
8889 def test_no_indexes (self , netcdf4_file , hdf_backend ):
8990 vds = open_virtual_dataset (netcdf4_file , indexes = {}, backend = hdf_backend )
9091 assert vds .indexes == {}
9192
93+ @requires_hdf5plugin
94+ @requires_imagecodecs
9295 def test_create_default_indexes_for_loadable_variables (
9396 self , netcdf4_file , hdf_backend
9497 ):
@@ -122,8 +125,9 @@ def index_mappings_equal(indexes1: Mapping[str, Index], indexes2: Mapping[str, I
122125 return True
123126
124127
125- @requires_kerchunk
126- @pytest .mark .parametrize ("hdf_backend" , [HDF5VirtualBackend , HDFVirtualBackend ])
128+ @requires_hdf5plugin
129+ @requires_imagecodecs
130+ @parametrize_over_hdf_backends
127131def test_cftime_index (tmpdir , hdf_backend ):
128132 """Ensure a virtual dataset contains the same indexes as an Xarray dataset"""
129133 # Note: Test was created to debug: https://github.com/zarr-developers/VirtualiZarr/issues/168
@@ -152,8 +156,7 @@ def test_cftime_index(tmpdir, hdf_backend):
152156 assert vds .attrs == ds .attrs
153157
154158
155- @requires_kerchunk
156- @pytest .mark .parametrize ("hdf_backend" , [HDF5VirtualBackend , HDFVirtualBackend ])
159+ @parametrize_over_hdf_backends
157160class TestOpenVirtualDatasetAttrs :
158161 def test_drop_array_dimensions (self , netcdf4_file , hdf_backend ):
159162 # regression test for GH issue #150
@@ -171,14 +174,16 @@ def test_coordinate_variable_attrs_preserved(self, netcdf4_file, hdf_backend):
171174 }
172175
173176
174- @requires_kerchunk
177+ @parametrize_over_hdf_backends
175178class TestDetermineCoords :
176- def test_infer_one_dimensional_coords (self , netcdf4_file ):
177- vds = open_virtual_dataset (netcdf4_file , indexes = {})
179+ def test_infer_one_dimensional_coords (self , netcdf4_file , hdf_backend ):
180+ vds = open_virtual_dataset (netcdf4_file , indexes = {}, backend = hdf_backend )
178181 assert set (vds .coords ) == {"time" , "lat" , "lon" }
179182
180- def test_var_attr_coords (self , netcdf4_file_with_2d_coords ):
181- vds = open_virtual_dataset (netcdf4_file_with_2d_coords , indexes = {})
183+ def test_var_attr_coords (self , netcdf4_file_with_2d_coords , hdf_backend ):
184+ vds = open_virtual_dataset (
185+ netcdf4_file_with_2d_coords , indexes = {}, backend = hdf_backend
186+ )
182187
183188 expected_dimension_coords = ["ocean_time" , "s_rho" ]
184189 expected_2d_coords = ["lon_rho" , "lat_rho" , "h" ]
@@ -189,6 +194,8 @@ def test_var_attr_coords(self, netcdf4_file_with_2d_coords):
189194 + expected_2d_coords
190195 + expected_1d_non_dimension_coords
191196 + expected_scalar_coords
197+ # These should not be included in coords see #401 for more information
198+ + (["xi_rho" , "eta_rho" ] if hdf_backend == HDFVirtualBackend else [])
192199 )
193200 assert set (vds .coords ) == set (expected_coords )
194201
@@ -199,7 +206,7 @@ class TestReadFromS3:
199206 @pytest .mark .parametrize (
200207 "indexes" , [None , {}], ids = ["None index" , "empty dict index" ]
201208 )
202- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
209+ @parametrize_over_hdf_backends
203210 def test_anon_read_s3 (self , indexes , hdf_backend ):
204211 """Parameterized tests for empty vs supplied indexes and filetypes."""
205212 # TODO: Switch away from this s3 url after minIO is implemented.
@@ -217,7 +224,7 @@ def test_anon_read_s3(self, indexes, hdf_backend):
217224
218225
219226@requires_network
220- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
227+ @parametrize_over_hdf_backends
221228class TestReadFromURL :
222229 @pytest .mark .parametrize (
223230 "filetype, url" ,
@@ -320,46 +327,55 @@ def test_virtualizarr_vs_local_nisar(self, hdf_backend):
320327 xrt .assert_equal (dsXR , dsV )
321328
322329
323- @requires_kerchunk
324- def test_open_empty_group (empty_netcdf4_file ):
325- vds = open_virtual_dataset (empty_netcdf4_file , indexes = {})
326- assert isinstance (vds , xr .Dataset )
327- expected = Dataset ()
328- xrt .assert_identical (vds , expected )
329-
330-
331- @requires_kerchunk
330+ @parametrize_over_hdf_backends
332331class TestOpenVirtualDatasetHDFGroup :
333- def test_open_subgroup (self , netcdf4_file_with_data_in_multiple_groups ):
332+ def test_open_empty_group (self , empty_netcdf4_file , hdf_backend ):
333+ vds = open_virtual_dataset (empty_netcdf4_file , indexes = {}, backend = hdf_backend )
334+ assert isinstance (vds , xr .Dataset )
335+ expected = Dataset ()
336+ xrt .assert_identical (vds , expected )
337+
338+ def test_open_subgroup (
339+ self , netcdf4_file_with_data_in_multiple_groups , hdf_backend
340+ ):
334341 vds = open_virtual_dataset (
335- netcdf4_file_with_data_in_multiple_groups , group = "subgroup" , indexes = {}
342+ netcdf4_file_with_data_in_multiple_groups ,
343+ group = "subgroup" ,
344+ indexes = {},
345+ backend = hdf_backend ,
346+ )
347+ # This should just be ["bar"] see #401 for more information
348+ assert list (vds .variables ) == (
349+ ["bar" , "dim_0" ] if hdf_backend == HDFVirtualBackend else ["bar" ]
336350 )
337- assert list (vds .variables ) == ["bar" ]
338351 assert isinstance (vds ["bar" ].data , ManifestArray )
339352 assert vds ["bar" ].shape == (2 ,)
340353
341- def test_open_root_group_manually (self , netcdf4_file_with_data_in_multiple_groups ):
342- vds = open_virtual_dataset (
343- netcdf4_file_with_data_in_multiple_groups , group = "" , indexes = {}
344- )
345- assert list (vds .variables ) == ["foo" ]
346- assert isinstance (vds ["foo" ].data , ManifestArray )
347- assert vds ["foo" ].shape == (3 ,)
348-
349- def test_open_root_group_by_default (
350- self , netcdf4_file_with_data_in_multiple_groups
354+ @pytest .mark .parametrize ("group" , ["" , None ])
355+ def test_open_root_group (
356+ self ,
357+ netcdf4_file_with_data_in_multiple_groups ,
358+ hdf_backend ,
359+ group ,
351360 ):
352361 vds = open_virtual_dataset (
353- netcdf4_file_with_data_in_multiple_groups , indexes = {}
362+ netcdf4_file_with_data_in_multiple_groups ,
363+ group = group ,
364+ indexes = {},
365+ backend = hdf_backend ,
366+ )
367+ # This should just be ["foo"] see #401 for more information
368+ assert list (vds .variables ) == (
369+ ["foo" , "dim_0" ] if hdf_backend == HDFVirtualBackend else ["foo" ]
354370 )
355- assert list (vds .variables ) == ["foo" ]
356371 assert isinstance (vds ["foo" ].data , ManifestArray )
357372 assert vds ["foo" ].shape == (3 ,)
358373
359374
360- @requires_kerchunk
375+ @requires_hdf5plugin
376+ @requires_imagecodecs
361377class TestLoadVirtualDataset :
362- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
378+ @parametrize_over_hdf_backends
363379 def test_loadable_variables (self , netcdf4_file , hdf_backend ):
364380 vars_to_load = ["air" , "time" ]
365381 vds = open_virtual_dataset (
@@ -399,18 +415,18 @@ def test_explicit_filetype_and_backend(self, netcdf4_file):
399415 netcdf4_file , filetype = "hdf" , backend = HDFVirtualBackend
400416 )
401417
402- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
418+ @parametrize_over_hdf_backends
403419 def test_group_kwarg (self , hdf5_groups_file , hdf_backend ):
404420 if hdf_backend == HDFVirtualBackend :
405- with pytest .raises (NotImplementedError , match = "Nested groups" ):
406- open_virtual_dataset (hdf5_groups_file , backend = hdf_backend )
407421 with pytest .raises (KeyError , match = "doesn't exist" ):
408422 open_virtual_dataset (
409423 hdf5_groups_file , group = "doesnt_exist" , backend = hdf_backend
410424 )
411425 if hdf_backend == HDF5VirtualBackend :
412426 with pytest .raises (ValueError , match = "not found in" ):
413- open_virtual_dataset (hdf5_groups_file , group = "doesnt_exist" )
427+ open_virtual_dataset (
428+ hdf5_groups_file , group = "doesnt_exist" , backend = hdf_backend
429+ )
414430
415431 vars_to_load = ["air" , "time" ]
416432 vds = open_virtual_dataset (
@@ -443,13 +459,13 @@ def test_open_virtual_dataset_passes_expected_args(
443459 }
444460 mock_read_kerchunk .assert_called_once_with (** args )
445461
446- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
462+ @parametrize_over_hdf_backends
447463 def test_open_dataset_with_empty (self , hdf5_empty , hdf_backend ):
448464 vds = open_virtual_dataset (hdf5_empty , backend = hdf_backend )
449465 assert vds .empty .dims == ()
450466 assert vds .empty .attrs == {"empty" : "true" }
451467
452- @pytest . mark . parametrize ( "hdf_backend" , [ HDF5VirtualBackend , HDFVirtualBackend ])
468+ @parametrize_over_hdf_backends
453469 def test_open_dataset_with_scalar (self , hdf5_scalar , hdf_backend ):
454470 vds = open_virtual_dataset (hdf5_scalar , backend = hdf_backend )
455471 assert vds .scalar .dims == ()
0 commit comments