MCPcopy
hub / github.com/pydantic/pydantic / test_schema_class

Function test_schema_class

tests/test_json_schema.py:223–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

221
222
223def test_schema_class():
224 class Model(BaseModel):
225 foo: int = Field(4, title='Foo is Great')
226 bar: str = Field(description='this description of bar')
227
228 with pytest.raises(ValidationError):
229 Model()
230
231 m = Model(bar='123')
232 assert m.model_dump() == {'foo': 4, 'bar': '123'}
233
234 assert Model.model_json_schema() == {
235 'type': 'object',
236 'title': 'Model',
237 'properties': {
238 'foo': {'type': 'integer', 'title': 'Foo is Great', 'default': 4},
239 'bar': {'type': 'string', 'title': 'Bar', 'description': 'this description of bar'},
240 },
241 'required': ['bar'],
242 }
243
244
245def test_schema_repr():

Callers

nothing calls this directly

Calls 3

ModelClass · 0.70
model_dumpMethod · 0.45
model_json_schemaMethod · 0.45

Tested by

no test coverage detected