MCPcopy
hub / github.com/pydantic/pydantic / test_copy_advanced_exclude

Function test_copy_advanced_exclude

tests/test_construction.py:217–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

215
216@pytest.mark.thread_unsafe(reason='`pytest.warns()` is thread unsafe')
217def test_copy_advanced_exclude():
218 class SubSubModel(BaseModel):
219 a: str
220 b: str
221
222 class SubModel(BaseModel):
223 c: str
224 d: list[SubSubModel]
225
226 class Model(BaseModel):
227 e: str
228 f: SubModel
229
230 m = Model(e='e', f=SubModel(c='foo', d=[SubSubModel(a='a', b='b'), SubSubModel(a='c', b='e')]))
231 m2 = deprecated_copy(m, exclude={'f': {'c': ..., 'd': {-1: {'a'}}}})
232 assert hasattr(m.f, 'c')
233 assert not hasattr(m2.f, 'c')
234
235 assert m2.model_dump() == {'e': 'e', 'f': {'d': [{'a': 'a', 'b': 'b'}, {'b': 'e'}]}}
236 m2 = deprecated_copy(m, exclude={'e': ..., 'f': {'d'}})
237 assert m2.model_dump() == {'f': {'c': 'foo'}}
238
239
240@pytest.mark.thread_unsafe(reason='`pytest.warns()` is thread unsafe')

Callers

nothing calls this directly

Calls 5

deprecated_copyFunction · 0.85
ModelClass · 0.70
SubModelClass · 0.70
SubSubModelClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected