@@ -828,6 +828,138 @@ async def test_bind_param_async_callable_value_success(self, tool_name, client):
828
828
bound_async_callable .assert_awaited_once ()
829
829
830
830
831
+ @pytest .mark .asyncio
832
+ async def test_bind_param_success (self , tool_name , client ):
833
+ """Tests 'bind_param' with a bound parameter specified."""
834
+ tool = await client .load_tool (tool_name )
835
+
836
+ assert len (tool .__signature__ .parameters ) == 2
837
+ assert "argA" in tool .__signature__ .parameters
838
+
839
+ tool = tool .bind_param ("argA" , 5 )
840
+
841
+ assert len (tool .__signature__ .parameters ) == 1
842
+ assert "argA" not in tool .__signature__ .parameters
843
+
844
+ res = await tool (True )
845
+ assert "argA" in res
846
+
847
+ @pytest .mark .asyncio
848
+ async def test_bind_callable_param_success (self , tool_name , client ):
849
+ """Tests 'bind_param' with a bound parameter specified."""
850
+ tool = await client .load_tool (tool_name )
851
+
852
+ assert len (tool .__signature__ .parameters ) == 2
853
+ assert "argA" in tool .__signature__ .parameters
854
+
855
+ tool = tool .bind_param ("argA" , lambda : 5 )
856
+
857
+ assert len (tool .__signature__ .parameters ) == 1
858
+ assert "argA" not in tool .__signature__ .parameters
859
+
860
+ res = await tool (True )
861
+ assert "argA" in res
862
+
863
+ @pytest .mark .asyncio
864
+ async def test_bind_param_fail (self , tool_name , client ):
865
+ """Tests 'bind_param' with a bound parameter that doesn't exist."""
866
+ tool = await client .load_tool (tool_name )
867
+
868
+ assert len (tool .__signature__ .parameters ) == 2
869
+ assert "argA" in tool .__signature__ .parameters
870
+
871
+ with pytest .raises (Exception ) as e :
872
+ tool .bind_param ("argC" , lambda : 5 )
873
+ assert "unable to bind parameters: no parameter named argC" in str (e .value )
874
+
875
+ @pytest .mark .asyncio
876
+ async def test_rebind_param_fail (self , tool_name , client ):
877
+ """
878
+ Tests that 'bind_param' fails when attempting to re-bind a
879
+ parameter that has already been bound.
880
+ """
881
+ tool = await client .load_tool (tool_name )
882
+
883
+ assert len (tool .__signature__ .parameters ) == 2
884
+ assert "argA" in tool .__signature__ .parameters
885
+
886
+ tool_with_bound_param = tool .bind_param ("argA" , lambda : 10 )
887
+
888
+ assert len (tool_with_bound_param .__signature__ .parameters ) == 1
889
+ assert "argA" not in tool_with_bound_param .__signature__ .parameters
890
+
891
+ with pytest .raises (ValueError ) as e :
892
+ tool_with_bound_param .bind_param ("argA" , lambda : 20 )
893
+
894
+ assert "cannot re-bind parameter: parameter 'argA' is already bound" in str (
895
+ e .value
896
+ )
897
+
898
+ @pytest .mark .asyncio
899
+ async def test_bind_param_static_value_success (self , tool_name , client ):
900
+ """
901
+ Tests bind_param method with a static value.
902
+ """
903
+
904
+ bound_value = "Test value"
905
+
906
+ tool = await client .load_tool (tool_name )
907
+ bound_tool = tool .bind_param ("argB" , bound_value )
908
+
909
+ assert bound_tool is not tool
910
+ assert "argB" not in bound_tool .__signature__ .parameters
911
+ assert "argA" in bound_tool .__signature__ .parameters
912
+
913
+ passed_value_a = 42
914
+ res_payload = await bound_tool (argA = passed_value_a )
915
+
916
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value }
917
+
918
+ @pytest .mark .asyncio
919
+ async def test_bind_param_sync_callable_value_success (self , tool_name , client ):
920
+ """
921
+ Tests bind_param method with a sync callable value.
922
+ """
923
+
924
+ bound_value_result = True
925
+ bound_sync_callable = Mock (return_value = bound_value_result )
926
+
927
+ tool = await client .load_tool (tool_name )
928
+ bound_tool = tool .bind_param ("argB" , bound_sync_callable )
929
+
930
+ assert bound_tool is not tool
931
+ assert "argB" not in bound_tool .__signature__ .parameters
932
+ assert "argA" in bound_tool .__signature__ .parameters
933
+
934
+ passed_value_a = 42
935
+ res_payload = await bound_tool (argA = passed_value_a )
936
+
937
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value_result }
938
+ bound_sync_callable .assert_called_once ()
939
+
940
+ @pytest .mark .asyncio
941
+ async def test_bind_param_async_callable_value_success (self , tool_name , client ):
942
+ """
943
+ Tests bind_param method with an async callable value.
944
+ """
945
+
946
+ bound_value_result = True
947
+ bound_async_callable = AsyncMock (return_value = bound_value_result )
948
+
949
+ tool = await client .load_tool (tool_name )
950
+ bound_tool = tool .bind_param ("argB" , bound_async_callable )
951
+
952
+ assert bound_tool is not tool
953
+ assert "argB" not in bound_tool .__signature__ .parameters
954
+ assert "argA" in bound_tool .__signature__ .parameters
955
+
956
+ passed_value_a = 42
957
+ res_payload = await bound_tool (argA = passed_value_a )
958
+
959
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value_result }
960
+ bound_async_callable .assert_awaited_once ()
961
+
962
+
831
963
class TestUnusedParameterValidation :
832
964
"""
833
965
Tests for validation errors related to unused auth tokens or bound
0 commit comments