MCPcopy Create free account
hub / github.com/openai/openai-python / test_forwards_compat_model_dump_method

Function test_forwards_compat_model_dump_method

tests/test_models.py:540–565  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

538
539
540def test_forwards_compat_model_dump_method() -> None:
541 class Model(BaseModel):
542 foo: Optional[str] = Field(alias="FOO", default=None)
543
544 m = Model(FOO="hello")
545 assert m.model_dump() == {"foo": "hello"}
546 assert m.model_dump(include={"bar"}) == {}
547 assert m.model_dump(exclude={"foo"}) == {}
548 assert m.model_dump(by_alias=True) == {"FOO": "hello"}
549
550 m2 = Model()
551 assert m2.model_dump() == {"foo": None}
552 assert m2.model_dump(exclude_unset=True) == {}
553 assert m2.model_dump(exclude_none=True) == {}
554 assert m2.model_dump(exclude_defaults=True) == {}
555
556 m3 = Model(FOO=None)
557 assert m3.model_dump() == {"foo": None}
558 assert m3.model_dump(exclude_none=True) == {}
559
560 if PYDANTIC_V1:
561 with pytest.raises(ValueError, match="round_trip is only supported in Pydantic v2"):
562 m.model_dump(round_trip=True)
563
564 with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
565 m.model_dump(warnings=False)
566
567
568def test_compat_method_no_error_for_warnings() -> None:

Callers

nothing calls this directly

Calls 2

model_dumpMethod · 0.80
ModelClass · 0.70

Tested by

no test coverage detected