MCPcopy
hub / github.com/pydantic/pydantic / test_bytes_base64

Function test_bytes_base64

pydantic-core/tests/serializers/test_bytes.py:106–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104
105
106def test_bytes_base64():
107 s = SchemaSerializer(core_schema.bytes_schema(), {'ser_json_bytes': 'base64'})
108 assert s.to_python(b'foobar') == b'foobar'
109
110 assert s.to_json(b'foobar') == b'"Zm9vYmFy"'
111 assert s.to_python(b'foobar', mode='json') == 'Zm9vYmFy'
112 assert base64.b64decode(s.to_python(b'foobar', mode='json').encode()) == b'foobar'
113
114 # with padding
115 assert s.to_json(b'foo bar') == b'"Zm9vIGJhcg=="'
116 assert s.to_python(b'foo bar', mode='json') == 'Zm9vIGJhcg=='
117 assert base64.b64decode(s.to_python(b'foo bar', mode='json').encode()) == b'foo bar'
118
119
120def test_bytes_hex():

Callers

nothing calls this directly

Calls 2

bytes_schemaMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected