MCPcopy
hub / github.com/pydantic/pydantic / test_decimal

Function test_decimal

pydantic-core/tests/serializers/test_decimal.py:8–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8def test_decimal():
9 v = SchemaSerializer(core_schema.decimal_schema())
10 assert v.to_python(Decimal('123.456')) == Decimal('123.456')
11
12 assert v.to_python(Decimal('123.456'), mode='json') == '123.456'
13 assert v.to_json(Decimal('123.456')) == b'"123.456"'
14
15 assert v.to_python(Decimal('123456789123456789123456789.123456789123456789123456789')) == Decimal(
16 '123456789123456789123456789.123456789123456789123456789'
17 )
18 assert (
19 v.to_json(Decimal('123456789123456789123456789.123456789123456789123456789'))
20 == b'"123456789123456789123456789.123456789123456789123456789"'
21 )
22
23 with pytest.warns(
24 UserWarning,
25 match=r'Expected `decimal` - serialized value may not be as expected \[input_value=123, input_type=int\]',
26 ):
27 assert v.to_python(123, mode='json') == 123
28
29 with pytest.warns(
30 UserWarning,
31 match=r'Expected `decimal` - serialized value may not be as expected \[input_value=123, input_type=int\]',
32 ):
33 assert v.to_json(123) == b'123'
34
35
36def test_decimal_key():

Callers

nothing calls this directly

Calls 1

decimal_schemaMethod · 0.80

Tested by

no test coverage detected