MCPcopy
hub / github.com/pydantic/pydantic / test_copy_update

Function test_copy_update

tests/test_construction.py:283–296  ·  view source on GitHub ↗
(ModelTwo, copy_method)

Source from the content-addressed store, hash-verified

281
282
283def test_copy_update(ModelTwo, copy_method):
284 m = ModelTwo(a=24, d=Model(a='12'))
285 m2 = copy_method(m, update={'a': 'different'})
286
287 assert m.a == 24
288 assert m2.a == 'different'
289 m_keys = m.model_dump().keys()
290 with pytest.warns(
291 UserWarning,
292 match=r"Expected `float` - serialized value may not be as expected \[field_name='a', input_value='different', input_type=str\]",
293 ):
294 m2_keys = m2.model_dump().keys()
295 assert set(m_keys) == set(m2_keys) == {'a', 'b', 'c', 'd'}
296 assert m != m2
297
298
299def test_copy_update_unset(copy_method):

Callers

nothing calls this directly

Calls 5

copy_methodFunction · 0.85
keysMethod · 0.80
ModelTwoClass · 0.70
ModelClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected