MCPcopy
hub / github.com/openai/openai-agents-python / test_varargs_function

Function test_varargs_function

tests/test_function_schema.py:99–134  ·  view source on GitHub ↗

Test a function that uses *args and **kwargs.

()

Source from the content-addressed store, hash-verified

97
98
99def test_varargs_function():
100 """Test a function that uses *args and **kwargs."""
101
102 func_schema = function_schema(varargs_function, strict_json_schema=False)
103 # Check JSON schema structure
104 assert isinstance(func_schema.params_json_schema, dict)
105 assert func_schema.params_json_schema.get("title") == "varargs_function_args"
106
107 # Valid input including *args in 'numbers' and **kwargs in 'kwargs'
108 valid_input = {
109 "x": 10,
110 "numbers": [1.1, 2.2, 3.3],
111 "flag": True,
112 "kwargs": {"extra1": "hello", "extra2": 42},
113 }
114 parsed = func_schema.params_pydantic_model(**valid_input)
115 args, kwargs_dict = func_schema.to_call_args(parsed)
116
117 result = varargs_function(*args, **kwargs_dict)
118 # result should be (10, (1.1, 2.2, 3.3), True, {"extra1": "hello", "extra2": 42})
119 assert result[0] == 10
120 assert result[1] == (1.1, 2.2, 3.3)
121 assert result[2] is True
122 assert result[3] == {"extra1": "hello", "extra2": 42}
123
124 # Missing 'x' should raise error
125 with pytest.raises(ValidationError):
126 func_schema.params_pydantic_model(**{"numbers": [1.1, 2.2]})
127
128 # 'flag' can be omitted because it has a default
129 valid_input_no_flag = {"x": 7, "numbers": [9.9], "kwargs": {"some_key": "some_value"}}
130 parsed2 = func_schema.params_pydantic_model(**valid_input_no_flag)
131 args2, kwargs_dict2 = func_schema.to_call_args(parsed2)
132 result2 = varargs_function(*args2, **kwargs_dict2)
133 # result2 should be (7, (9.9,), False, {'some_key': 'some_value'})
134 assert result2 == (7, (9.9,), False, {"some_key": "some_value"})
135
136
137class Foo(TypedDict):

Callers

nothing calls this directly

Calls 4

function_schemaFunction · 0.90
varargs_functionFunction · 0.85
to_call_argsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected