MCPcopy
hub / github.com/pydantic/pydantic / test_con_decimal_encode

Function test_con_decimal_encode

tests/test_json.py:239–251  ·  view source on GitHub ↗

Makes sure a decimal with decimal_places = 0, as well as one with places can handle a encode/decode roundtrip.

()

Source from the content-addressed store, hash-verified

237
238
239def test_con_decimal_encode() -> None:
240 """
241 Makes sure a decimal with decimal_places = 0, as well as one with places
242 can handle a encode/decode roundtrip.
243 """
244
245 class Obj(BaseModel):
246 id: condecimal(gt=0, max_digits=22, decimal_places=0)
247 price: Decimal = Decimal('0.01')
248
249 json_data = '{"id":"1","price":"0.01"}'
250 assert Obj(id=1).model_dump_json() == json_data
251 assert Obj.model_validate_json(json_data) == Obj(id=1)
252
253
254def test_json_encoder_simple_inheritance():

Callers

nothing calls this directly

Calls 3

model_dump_jsonMethod · 0.80
model_validate_jsonMethod · 0.80
ObjClass · 0.70

Tested by

no test coverage detected