MCPcopy
hub / github.com/pydantic/pydantic / test_bytes

Function test_bytes

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

Source from the content-addressed store, hash-verified

8
9
10def test_bytes():
11 s = SchemaSerializer(core_schema.bytes_schema())
12 assert s.to_python(b'foobar') == b'foobar'
13 assert s.to_python('emoji 💩'.encode()) == 'emoji 💩'.encode()
14 assert s.to_json(b'foobar') == b'"foobar"'
15 assert s.to_python(b'foobar', mode='json') == 'foobar'
16
17 json_emoji = s.to_json('emoji 💩'.encode())
18 # note! serde_json serializes unicode characters differently
19 assert json_emoji == b'"emoji \xf0\x9f\x92\xa9"'
20 assert json.loads(json_emoji) == 'emoji 💩'
21
22
23def test_bytes_invalid_all():

Callers

nothing calls this directly

Calls 2

bytes_schemaMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected