MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_pydantic_default_field

Function test_pydantic_default_field

tests/test_transform.py:340–357  ·  view source on GitHub ↗
(use_async: bool)

Source from the content-addressed store, hash-verified

338@parametrize
339@pytest.mark.asyncio
340async def test_pydantic_default_field(use_async: bool) -> None:
341 # should be excluded when defaults are used
342 model = ModelWithDefaultField.construct()
343 assert model.with_none_default is None
344 assert model.with_str_default == "foo"
345 assert cast(Any, await transform(model, Any, use_async)) == {}
346
347 # should be included when the default value is explicitly given
348 model = ModelWithDefaultField.construct(with_none_default=None, with_str_default="foo")
349 assert model.with_none_default is None
350 assert model.with_str_default == "foo"
351 assert cast(Any, await transform(model, Any, use_async)) == {"with_none_default": None, "with_str_default": "foo"}
352
353 # should be included when a non-default value is explicitly given
354 model = ModelWithDefaultField.construct(with_none_default="bar", with_str_default="baz")
355 assert model.with_none_default == "bar"
356 assert model.with_str_default == "baz"
357 assert cast(Any, await transform(model, Any, use_async)) == {"with_none_default": "bar", "with_str_default": "baz"}
358
359
360class TypedDictIterableUnion(TypedDict):

Callers

nothing calls this directly

Calls 2

transformFunction · 0.70
constructMethod · 0.45

Tested by

no test coverage detected