Skip to content

Commit f23457a

Browse files
committed
o Fix tests for other readers
1 parent e63cb6e commit f23457a

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

test/grid/grid/test_initialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_grid_init_verts_fill_values():
4949
def test_read_shpfile(test_data_dir):
5050
"""Reads a shape file and write ugrid file."""
5151
shp_filename = test_data_dir / "shp" / "grid_fire.shp"
52-
with pytest.raises(ValueError):
52+
with pytest.raises((ValueError, FileNotFoundError, OSError)):
5353
grid_shp = ux.open_grid(shp_filename)
5454

5555

uxarray/core/utils.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,14 @@ def _open_dataset_with_fallback(filename_or_obj, chunks=None, **kwargs):
2828
xr.Dataset
2929
The opened dataset
3030
"""
31-
# First attempt: use xarray's default read engine
32-
original_error = None
3331
try:
32+
# Try opening with xarray's default read engine
3433
return xr.open_dataset(filename_or_obj, chunks=chunks, **kwargs)
35-
except Exception as e:
36-
original_error = e
37-
38-
# Second attempt: fallback to netcdf4 engine
39-
try:
34+
except Exception:
35+
# If it fails, use the "netcdf4" engine as backup
4036
# Extract engine from kwargs to prevent duplicate parameter error
4137
engine = kwargs.pop("engine", "netcdf4")
4238
return xr.open_dataset(filename_or_obj, engine=engine, chunks=chunks, **kwargs)
43-
except Exception:
44-
# If both attempts fail, raise the original error to preserve behavior
45-
raise original_error
4639

4740

4841
def _map_dims_to_ugrid(

0 commit comments

Comments
 (0)