Skip to content

Commit 81bfa76

Browse files
committed
Improve code coverage
1 parent a4ff4a9 commit 81bfa76

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/mdio/schemas/v1/dataset_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _get_np_datatype(data_type: ScalarType | StructuredType) -> np_dtype:
9797
return np_dtype(data_type.value)
9898
if isinstance(data_type, StructuredType):
9999
return np_dtype([(f.name, f.format.value) for f in data_type.fields])
100-
msg = f"Expected ScalarType or StructuredType, got {type(data_type).__name__}"
100+
msg = f"Expected ScalarType or StructuredType, got '{type(data_type).__name__}'"
101101
raise ValueError(msg)
102102

103103

tests/unit/v1/test_dataset_serializer.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def test__get_np_datatype() -> None:
160160
(ScalarType.COMPLEX128, "complex128"),
161161
(ScalarType.BOOL, "bool"),
162162
]
163+
err = "Expected ScalarType or StructuredType, got 'str'"
164+
with pytest.raises(ValueError, match=err):
165+
_get_np_datatype("parameter of invalid type")
163166

164167
for scalar_type, expected_numpy_type in scalar_type_tests:
165168
result = _get_np_datatype(scalar_type)
@@ -194,9 +197,24 @@ def test__get_zarr_shape() -> None:
194197
d1 = NamedDimension(name="inline", size=100)
195198
d2 = NamedDimension(name="crossline", size=200)
196199
d3 = NamedDimension(name="depth", size=300)
200+
all_named_dims = {"inline": d1, "crossline": d2, "depth": d3}
201+
v1 = Variable(name="named dims var", data_type=ScalarType.FLOAT32, dimensions=[d1, d2, d3])
202+
v2 = Variable(
203+
name="str var", data_type=ScalarType.FLOAT32, dimensions=["inline", "crossline", "depth"]
204+
)
205+
Dataset(
206+
variables=[v1, v2],
207+
metadata=_to_dictionary(
208+
[
209+
DatasetInfo(
210+
name="test_dataset", api_version="1.0.0", created_on="2023-10-01T00:00:00Z"
211+
)
212+
]
213+
),
214+
)
197215

198-
v = Variable(name="seismic 3d var", data_type=ScalarType.FLOAT32, dimensions=[d1, d2, d3])
199-
assert _get_zarr_shape(v, all_named_dims=[d1, d2, d3]) == (100, 200, 300)
216+
assert _get_zarr_shape(v1, all_named_dims) == (100, 200, 300)
217+
assert _get_zarr_shape(v2, all_named_dims) == (100, 200, 300)
200218

201219

202220
def test__get_zarr_chunks() -> None:
@@ -341,7 +359,6 @@ def test__convert_compressor() -> None:
341359
# Test 5: mdio_ZFP without zfpy installed - should raise ImportError
342360
with pytest.raises(ImportError) as exc_info:
343361
_convert_compressor(zfp_compressor)
344-
345362
error_message = str(exc_info.value)
346363
assert "zfpy and numcodecs are required to use ZFP compression" in error_message
347364

0 commit comments

Comments
 (0)