@@ -47,10 +47,10 @@ def func1(a: int, b: str, c: float = 1.0):
4747 assert (
4848 schema ["parameters" ]["properties" ]["c" ]["default" ] == 1.0
4949 ), "c should have a default value of 1.0"
50- assert schema [ "parameters" ][ "required" ] == [
51- "a" ,
52- "b" ,
53- ] , "parameters with no default value should be required"
50+ assert (
51+ "a" in schema [ "parameters" ][ "required" ]
52+ and "b" in schema [ "parameters" ][ "required" ]
53+ ) , "parameters with no default value should be required"
5454
5555
5656def test_annotated_function ():
@@ -78,10 +78,10 @@ def func1(
7878 schema ["parameters" ]["properties" ]["b" ]["description" ] == "A string parameter"
7979 ), "parameter b should have a description"
8080
81- assert schema [ "parameters" ][ "required" ] == [
82- "a" ,
83- "b" ,
84- ] , "parameters with no default value should be required"
81+ assert (
82+ "a" in schema [ "parameters" ][ "required" ]
83+ and "b" in schema [ "parameters" ][ "required" ]
84+ ) , "parameters with no default value should be required"
8585
8686
8787def test_annotated_function_with_enum ():
@@ -116,7 +116,6 @@ def func1(animal: Annotated[Literal["Cat", "Dog"], "The animal you want to pet"]
116116 ...
117117
118118 schema = get_function_schema (func1 )
119- print (schema )
120119 assert (
121120 schema ["parameters" ]["properties" ]["animal" ]["type" ] == "string"
122121 ), "parameter animal should be a string"
@@ -138,3 +137,37 @@ def func2(animal: Literal["Cat", "Dog"]):
138137 "Cat" ,
139138 "Dog" ,
140139 ], "parameter animal should have an enum"
140+
141+ assert "animal" in schema ["parameters" ]["required" ], "animal is required"
142+
143+ def func3 (animal : Literal ["Cat" , "Dog" , 1 ]):
144+ """My function"""
145+ ...
146+
147+ schema = get_function_schema (func3 )
148+ assert schema ["parameters" ]["properties" ]["animal" ]["type" ] == [
149+ "string" ,
150+ "integer" ,
151+ ], "parameter animal should be a string"
152+
153+ def func4 (animal : Literal ["Cat" , "Dog" , 1 , None ]):
154+ """My function"""
155+ ...
156+
157+ schema = get_function_schema (func4 )
158+
159+ assert schema ["parameters" ]["properties" ]["animal" ]["type" ] == [
160+ "string" ,
161+ "integer" ,
162+ ], "parameter animal should be a string"
163+
164+ assert schema ["parameters" ]["properties" ]["animal" ]["enum" ] == [
165+ "Cat" ,
166+ "Dog" ,
167+ 1 ,
168+ ], "parameter animal should have an enum"
169+
170+ assert (
171+ schema ["parameters" ].get ("required" ) is None
172+ or "animal" not in schema ["parameters" ]["required" ]
173+ ), "animal should not be required"
0 commit comments