Skip to content

Commit 2497754

Browse files
committed
Add tests for invalid metric type
1 parent 5fcee74 commit 2497754

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/test_metadata.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"Metadata tests"
1+
"""Metadata tests"""
22

33
import json
44
import math
@@ -308,3 +308,32 @@ def test_from_json_pathlike(self) -> None:
308308
assert metric.metric_type == "unit_e"
309309
finally:
310310
temp_path.unlink()
311+
312+
def test_invalid_metric_type_raises_error(self) -> None:
313+
with pytest.raises(ValidationError):
314+
MetricInfo(
315+
stepsize=0.5,
316+
metric_type="not_a_metric", # type: ignore
317+
inv_metric=[1.0], # type: ignore
318+
)
319+
320+
def test_from_json_invalid_metric_type_raises_error(self) -> None:
321+
with tempfile.NamedTemporaryFile(
322+
mode='w', suffix='.json', delete=False
323+
) as f:
324+
json.dump(
325+
{
326+
'stepsize': 0.5,
327+
'metric_type': 'not_a_metric',
328+
'inv_metric': [1.0, 2.0, 3.0],
329+
},
330+
f,
331+
)
332+
temp_path = f.name
333+
334+
try:
335+
with pytest.raises(ValidationError):
336+
with open(temp_path) as fh:
337+
MetricInfo.model_validate_json(fh.read())
338+
finally:
339+
Path(temp_path).unlink()

0 commit comments

Comments
 (0)