MCPcopy
hub / github.com/pydantic/pydantic / test_validate_float_inf_nan_python

Function test_validate_float_inf_nan_python

tests/test_annotated.py:368–381  ·  tests/test_annotated.py::test_validate_float_inf_nan_python
()

Source from the content-addressed store, hash-verified

366
367
368def test_validate_float_inf_nan_python() -> None:
369 ta = TypeAdapter(Annotated[float, AfterValidator(lambda x: x * 3), Field(allow_inf_nan=False)])
370 assert ta.validate_python(2.0) == 6.0
371
372 ta = TypeAdapter(Annotated[float, AfterValidator(lambda _: float(&class="cm">#x27;nan')), Field(allow_inf_nan=False)])
373
374 with pytest.raises(ValidationError) as exc_info:
375 ta.validate_python(1.0)
376
377 class="cm"># insert_assert(exc_info.value.errors(include_url=False))
378 class="cm"># TODO: input should be float(class="st">'nan'), this seems like a subtle bug in pydantic-core
379 assert exc_info.value.errors(include_url=False) == [
380 {&class="cm">#x27;typeclass="st">': 'finite_numberclass="st">', 'locclass="st">': (), 'msgclass="st">': 'Input should be a finite numberclass="st">', 'input': 1.0}
381 ]
382
383
384def test_predicate_success_python() -> None:

Callers

nothing calls this directly

Calls 5

validate_pythonMethod · 0.95
TypeAdapterClass · 0.90
AfterValidatorClass · 0.90
FieldFunction · 0.90
errorsMethod · 0.45

Tested by

no test coverage detected