MCPcopy
hub / github.com/pydantic/pydantic / test_json_bytes_hex_round_trip

Function test_json_bytes_hex_round_trip

tests/test_json.py:560–576  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

558
559
560def test_json_bytes_hex_round_trip():
561 class R(RootModel[bytes]):
562 model_config = ConfigDict(ser_json_bytes='hex', val_json_bytes='hex')
563
564 r = R(b'hello')
565 r_encoded = '"68656c6c6f"'
566 assert r.model_dump_json() == r_encoded
567 assert R.model_validate_json(r_encoded) == r
568
569 class M(BaseModel):
570 key: bytes
571 model_config = R.model_config
572
573 m = M(key=b'hello')
574 m_encoded = f'{{"key":{r_encoded}}}'
575 assert m.model_dump_json() == m_encoded
576 assert M.model_validate_json(m_encoded) == m
577
578
579# Complete tests exist in pydantic-core:

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