MCPcopy
hub / github.com/pydantic/pydantic / test_to_string

Function test_to_string

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

Source from the content-addressed store, hash-verified

115
116
117def test_to_string():
118 s = SchemaSerializer(core_schema.any_schema(serialization={'type': 'to-string'}))
119 assert s.to_python(123, mode='json') == '123'
120 assert s.to_python(None, mode='json') is None
121 uuid = UUID('ebcdab58-6eb8-46fb-a190-d07a33e9eac8')
122 assert s.to_python(uuid, mode='json') == str(uuid)
123 assert s.to_json(uuid) == b'"%s"' % str(uuid).encode('utf-8')
124 with pytest.raises(ValueError, match='broken'):
125 s.to_python(BrokenToString(), mode='json')

Callers

nothing calls this directly

Calls 3

BrokenToStringClass · 0.85
any_schemaMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected