Skip to content

Commit f678753

Browse files
test(functions): cover typed dictionary argument validation
Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
1 parent 62f0f42 commit f678753

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎python/tests/unit/functions/test_kernel_function_from_method.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,40 @@ def test_function_model_dump_json(get_custom_type_function_pydantic):
885885
assert "metadata" in model_dump
886886

887887

888+
async def test_function_invoke_accepts_valid_typed_dict_argument(kernel: Kernel):
889+
@kernel_function
890+
def typed_dict_function(value: dict[str, int]) -> dict[str, int]:
891+
return value
892+
893+
function = KernelFunction.from_method(typed_dict_function, "test")
894+
result = await function.invoke(kernel=kernel, arguments=KernelArguments(value={"first": 1, "second": 2}))
895+
896+
assert result.value == {"first": 1, "second": 2}
897+
898+
899+
async def test_function_invoke_rejects_invalid_typed_dict_argument(kernel: Kernel):
900+
invoked = False
901+
902+
@kernel_function
903+
def typed_dict_function(value: dict[str, int]) -> dict[str, int]:
904+
nonlocal invoked
905+
invoked = True
906+
return value
907+
908+
function = KernelFunction.from_method(typed_dict_function, "test")
909+
910+
with pytest.raises(
911+
FunctionExecutionException,
912+
match=r"Parameter value is expected to be parsed to .* but is not\.",
913+
):
914+
await function.invoke(
915+
kernel=kernel,
916+
arguments=KernelArguments(value={"first": "not-an-integer"}),
917+
)
918+
919+
assert not invoked
920+
921+
888922
async def test_function_invoke_rejects_invalid_union_argument(kernel: Kernel):
889923
invoked = False
890924

0 commit comments

Comments
 (0)