()
| 210 | |
| 211 | |
| 212 | def test_custom_encoder(): |
| 213 | class Model(BaseModel): |
| 214 | x: timedelta |
| 215 | y: Decimal |
| 216 | z: date |
| 217 | |
| 218 | @field_serializer('x') |
| 219 | def serialize_x(self, v: timedelta, _info): |
| 220 | return f'{v.total_seconds():0.3f}s' |
| 221 | |
| 222 | @field_serializer('y') |
| 223 | def serialize_y(self, v: Decimal, _info): |
| 224 | return 'a decimal' |
| 225 | |
| 226 | assert Model(x=123, y=5, z='2032-06-01').model_dump_json() == '{"x":"123.000s","y":"a decimal","z":"2032-06-01"}' |
| 227 | |
| 228 | |
| 229 | def test_iso_timedelta_simple(): |
nothing calls this directly
no test coverage detected