MCPcopy
hub / github.com/pydantic/pydantic / test_root_validator

Function test_root_validator

tests/test_deprecated.py:235–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233
234@pytest.mark.filterwarnings('ignore:Pydantic V1 style `@root_validator` validators are deprecated.*:DeprecationWarning')
235def test_root_validator():
236 validator_value = None
237
238 class TestCls:
239 x = 1
240 y = 2
241
242 class Model(BaseModel):
243 model_config = ConfigDict(from_attributes=True)
244 x: int
245 y: int
246 z: int
247
248 @root_validator(pre=True)
249 def change_input_data(cls, value):
250 nonlocal validator_value
251 validator_value = value
252 return {'x': value.x, 'y': value.y, 'z': value.x + value.y}
253
254 model = deprecated_from_orm(Model, TestCls())
255 assert model.model_dump() == {'x': 1, 'y': 2, 'z': 3}
256 # assert isinstance(validator_value, GetterDict)
257 assert isinstance(validator_value, TestCls)
258
259
260def test_nested_orm():

Callers

nothing calls this directly

Calls 3

deprecated_from_ormFunction · 0.85
TestClsClass · 0.85
model_dumpMethod · 0.45

Tested by

no test coverage detected