MCPcopy
hub / github.com/pydantic/pydantic / test_optional_dict

Function test_optional_dict

tests/test_json_schema.py:2312–2329  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2310
2311
2312def test_optional_dict():
2313 class Model(BaseModel):
2314 something: Optional[dict[str, Any]] = None
2315
2316 assert Model.model_json_schema() == {
2317 'title': 'Model',
2318 'type': 'object',
2319 'properties': {
2320 'something': {
2321 'anyOf': [{'type': 'object', 'additionalProperties': True}, {'type': 'null'}],
2322 'default': None,
2323 'title': 'Something',
2324 }
2325 },
2326 }
2327
2328 assert Model().model_dump() == {'something': None}
2329 assert Model(something={'foo': 'Bar'}).model_dump() == {'something': {'foo': 'Bar'}}
2330
2331
2332def test_optional_validator():

Callers

nothing calls this directly

Calls 3

ModelClass · 0.70
model_json_schemaMethod · 0.45
model_dumpMethod · 0.45

Tested by

no test coverage detected