MCPcopy
hub / github.com/pydantic/pydantic / test_json_bytes_base64_round_trip

Function test_json_bytes_base64_round_trip

tests/test_json.py:541–557  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

539
540
541def test_json_bytes_base64_round_trip():
542 class R(RootModel[bytes]):
543 model_config = ConfigDict(ser_json_bytes='base64', val_json_bytes='base64')
544
545 r = R(b'hello')
546 r_encoded = '"aGVsbG8="'
547 assert r.model_dump_json() == r_encoded
548 assert R.model_validate_json(r_encoded) == r
549
550 class M(BaseModel):
551 key: bytes
552 model_config = R.model_config
553
554 m = M(key=b'hello')
555 m_encoded = f'{{"key":{r_encoded}}}'
556 assert m.model_dump_json() == m_encoded
557 assert M.model_validate_json(m_encoded) == m
558
559
560def test_json_bytes_hex_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