()
| 121 | |
| 122 | |
| 123 | def test_model_encoding(): |
| 124 | class ModelA(BaseModel): |
| 125 | x: int |
| 126 | y: str |
| 127 | |
| 128 | class Model(BaseModel): |
| 129 | a: float |
| 130 | b: bytes |
| 131 | c: Decimal |
| 132 | d: ModelA |
| 133 | |
| 134 | m = Model(a=10.2, b='foobar', c='10.2', d={'x': 123, 'y': '123'}) |
| 135 | assert m.model_dump() == {'a': 10.2, 'b': b'foobar', 'c': Decimal('10.2'), 'd': {'x': 123, 'y': '123'}} |
| 136 | assert m.model_dump_json() == '{"a":10.2,"b":"foobar","c":"10.2","d":{"x":123,"y":"123"}}' |
| 137 | assert m.model_dump_json(exclude={'b'}) == '{"a":10.2,"c":"10.2","d":{"x":123,"y":"123"}}' |
| 138 | |
| 139 | |
| 140 | def test_subclass_encoding(): |
nothing calls this directly
no test coverage detected