MCPcopy
hub / github.com/pydantic/pydantic / test_json_inf_nan_allow

Function test_json_inf_nan_allow

tests/test_json.py:516–538  ·  view source on GitHub ↗
(float_value, encoded_str)

Source from the content-addressed store, hash-verified

514 ],
515)
516def test_json_inf_nan_allow(float_value, encoded_str):
517 class R(RootModel[float]):
518 model_config = ConfigDict(ser_json_inf_nan='strings')
519
520 r = R(float_value)
521 r_encoded = f'"{encoded_str}"'
522 assert r.model_dump_json() == r_encoded
523 if math.isnan(float_value):
524 assert math.isnan(R.model_validate_json(r_encoded).root)
525 else:
526 assert R.model_validate_json(r_encoded) == r
527
528 class M(BaseModel):
529 f: float
530 model_config = R.model_config
531
532 m = M(f=float_value)
533 m_encoded = f'{{"f":{r_encoded}}}'
534 assert m.model_dump_json() == m_encoded
535 if math.isnan(float_value):
536 assert math.isnan(M.model_validate_json(m_encoded).f)
537 else:
538 assert M.model_validate_json(m_encoded) == m
539
540
541def test_json_bytes_base64_round_trip():

Callers

nothing calls this directly

Calls 4

model_dump_jsonMethod · 0.80
model_validate_jsonMethod · 0.80
RClass · 0.70
MClass · 0.70

Tested by

no test coverage detected