File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 1- "Metadata tests"
1+ """ Metadata tests"" "
22
33import json
44import 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 ()
You can’t perform that action at this time.
0 commit comments