@@ -699,6 +699,138 @@ async def test_bind_param_async_callable_value_success(self, tool_name, client):
699
699
bound_async_callable .assert_awaited_once ()
700
700
701
701
702
+ @pytest .mark .asyncio
703
+ async def test_bind_param_success (self , tool_name , client ):
704
+ """Tests 'bind_param' with a bound parameter specified."""
705
+ tool = await client .load_tool (tool_name )
706
+
707
+ assert len (tool .__signature__ .parameters ) == 2
708
+ assert "argA" in tool .__signature__ .parameters
709
+
710
+ tool = tool .bind_param ("argA" , 5 )
711
+
712
+ assert len (tool .__signature__ .parameters ) == 1
713
+ assert "argA" not in tool .__signature__ .parameters
714
+
715
+ res = await tool (True )
716
+ assert "argA" in res
717
+
718
+ @pytest .mark .asyncio
719
+ async def test_bind_callable_param_success (self , tool_name , client ):
720
+ """Tests 'bind_param' with a bound parameter specified."""
721
+ tool = await client .load_tool (tool_name )
722
+
723
+ assert len (tool .__signature__ .parameters ) == 2
724
+ assert "argA" in tool .__signature__ .parameters
725
+
726
+ tool = tool .bind_param ("argA" , lambda : 5 )
727
+
728
+ assert len (tool .__signature__ .parameters ) == 1
729
+ assert "argA" not in tool .__signature__ .parameters
730
+
731
+ res = await tool (True )
732
+ assert "argA" in res
733
+
734
+ @pytest .mark .asyncio
735
+ async def test_bind_param_fail (self , tool_name , client ):
736
+ """Tests 'bind_param' with a bound parameter that doesn't exist."""
737
+ tool = await client .load_tool (tool_name )
738
+
739
+ assert len (tool .__signature__ .parameters ) == 2
740
+ assert "argA" in tool .__signature__ .parameters
741
+
742
+ with pytest .raises (Exception ) as e :
743
+ tool .bind_param ("argC" , lambda : 5 )
744
+ assert "unable to bind parameters: no parameter named argC" in str (e .value )
745
+
746
+ @pytest .mark .asyncio
747
+ async def test_rebind_param_fail (self , tool_name , client ):
748
+ """
749
+ Tests that 'bind_param' fails when attempting to re-bind a
750
+ parameter that has already been bound.
751
+ """
752
+ tool = await client .load_tool (tool_name )
753
+
754
+ assert len (tool .__signature__ .parameters ) == 2
755
+ assert "argA" in tool .__signature__ .parameters
756
+
757
+ tool_with_bound_param = tool .bind_param ("argA" , lambda : 10 )
758
+
759
+ assert len (tool_with_bound_param .__signature__ .parameters ) == 1
760
+ assert "argA" not in tool_with_bound_param .__signature__ .parameters
761
+
762
+ with pytest .raises (ValueError ) as e :
763
+ tool_with_bound_param .bind_param ("argA" , lambda : 20 )
764
+
765
+ assert "cannot re-bind parameter: parameter 'argA' is already bound" in str (
766
+ e .value
767
+ )
768
+
769
+ @pytest .mark .asyncio
770
+ async def test_bind_param_static_value_success (self , tool_name , client ):
771
+ """
772
+ Tests bind_param method with a static value.
773
+ """
774
+
775
+ bound_value = "Test value"
776
+
777
+ tool = await client .load_tool (tool_name )
778
+ bound_tool = tool .bind_param ("argB" , bound_value )
779
+
780
+ assert bound_tool is not tool
781
+ assert "argB" not in bound_tool .__signature__ .parameters
782
+ assert "argA" in bound_tool .__signature__ .parameters
783
+
784
+ passed_value_a = 42
785
+ res_payload = await bound_tool (argA = passed_value_a )
786
+
787
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value }
788
+
789
+ @pytest .mark .asyncio
790
+ async def test_bind_param_sync_callable_value_success (self , tool_name , client ):
791
+ """
792
+ Tests bind_param method with a sync callable value.
793
+ """
794
+
795
+ bound_value_result = True
796
+ bound_sync_callable = Mock (return_value = bound_value_result )
797
+
798
+ tool = await client .load_tool (tool_name )
799
+ bound_tool = tool .bind_param ("argB" , bound_sync_callable )
800
+
801
+ assert bound_tool is not tool
802
+ assert "argB" not in bound_tool .__signature__ .parameters
803
+ assert "argA" in bound_tool .__signature__ .parameters
804
+
805
+ passed_value_a = 42
806
+ res_payload = await bound_tool (argA = passed_value_a )
807
+
808
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value_result }
809
+ bound_sync_callable .assert_called_once ()
810
+
811
+ @pytest .mark .asyncio
812
+ async def test_bind_param_async_callable_value_success (self , tool_name , client ):
813
+ """
814
+ Tests bind_param method with an async callable value.
815
+ """
816
+
817
+ bound_value_result = True
818
+ bound_async_callable = AsyncMock (return_value = bound_value_result )
819
+
820
+ tool = await client .load_tool (tool_name )
821
+ bound_tool = tool .bind_param ("argB" , bound_async_callable )
822
+
823
+ assert bound_tool is not tool
824
+ assert "argB" not in bound_tool .__signature__ .parameters
825
+ assert "argA" in bound_tool .__signature__ .parameters
826
+
827
+ passed_value_a = 42
828
+ res_payload = await bound_tool (argA = passed_value_a )
829
+
830
+ assert res_payload == {"argA" : passed_value_a , "argB" : bound_value_result }
831
+ bound_async_callable .assert_awaited_once ()
832
+
833
+
702
834
class TestUnusedParameterValidation :
703
835
"""
704
836
Tests for validation errors related to unused auth tokens or bound
0 commit comments