()
| 172 | |
| 173 | |
| 174 | def test_object_with_getattr(): |
| 175 | class FooGetAttr: |
| 176 | def __getattr__(self, key: str): |
| 177 | if key == 'foo': |
| 178 | return 'Foo' |
| 179 | else: |
| 180 | raise AttributeError |
| 181 | |
| 182 | class Model(BaseModel): |
| 183 | model_config = ConfigDict(from_attributes=True) |
| 184 | foo: str |
| 185 | bar: int = 1 |
| 186 | |
| 187 | class ModelInvalid(BaseModel): |
| 188 | model_config = ConfigDict(from_attributes=True) |
| 189 | foo: str |
| 190 | bar: int |
| 191 | |
| 192 | foo = FooGetAttr() |
| 193 | model = deprecated_from_orm(Model, foo) |
| 194 | assert model.foo == 'Foo' |
| 195 | assert model.bar == 1 |
| 196 | assert model.model_dump(exclude_unset=True) == {'foo': 'Foo'} |
| 197 | with pytest.raises(ValidationError): |
| 198 | deprecated_from_orm(ModelInvalid, foo) |
| 199 | |
| 200 | |
| 201 | def test_properties(): |
nothing calls this directly
no test coverage detected