MCPcopy
hub / github.com/pydantic/pydantic / test_copy_advanced_include

Function test_copy_advanced_include

tests/test_construction.py:241–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239
240@pytest.mark.thread_unsafe(reason='`pytest.warns()` is thread unsafe')
241def test_copy_advanced_include():
242 class SubSubModel(BaseModel):
243 a: str
244 b: str
245
246 class SubModel(BaseModel):
247 c: str
248 d: list[SubSubModel]
249
250 class Model(BaseModel):
251 e: str
252 f: SubModel
253
254 m = Model(e='e', f=SubModel(c='foo', d=[SubSubModel(a='a', b='b'), SubSubModel(a='c', b='e')]))
255 m2 = deprecated_copy(m, include={'f': {'c'}})
256 assert hasattr(m.f, 'c')
257 assert hasattr(m2.f, 'c')
258 assert m2.model_dump() == {'f': {'c': 'foo'}}
259
260 m2 = deprecated_copy(m, include={'e': ..., 'f': {'d': {-1}}})
261 assert m2.model_dump() == {'e': 'e', 'f': {'d': [{'a': 'c', 'b': 'e'}]}}
262
263
264@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