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  ·  view source on GitHub ↗
()

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('nan')), Field(allow_inf_nan=False)])
373
374 with pytest.raises(ValidationError) as exc_info:
375 ta.validate_python(1.0)
376
377 # insert_assert(exc_info.value.errors(include_url=False))
378 # TODO: input should be float('nan'), this seems like a subtle bug in pydantic-core
379 assert exc_info.value.errors(include_url=False) == [
380 {'type': 'finite_number', 'loc': (), 'msg': 'Input should be a finite number', '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

Used in the wild real call sites across dependent graphs

searching dependent graphs…