Skip to content

Commit a0cd8d9

Browse files
committed
chore: Add unit test coverage.
1 parent cbd1a7c commit a0cd8d9

File tree

1 file changed

+141
-9
lines changed

1 file changed

+141
-9
lines changed

packages/toolbox-core/tests/test_client.py

Lines changed: 141 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ async def test_load_toolset_success(self, tool_name, client):
435435
assert "argB" in res
436436

437437
@pytest.mark.asyncio
438-
async def test_bind_param_success(self, tool_name, client):
439-
"""Tests 'bind_param' with a bound parameter specified."""
438+
async def test_bind_params_success(self, tool_name, client):
439+
"""Tests 'bind_params' with a bound parameter specified."""
440440
tool = await client.load_tool(tool_name)
441441

442442
assert len(tool.__signature__.parameters) == 2
@@ -451,8 +451,8 @@ async def test_bind_param_success(self, tool_name, client):
451451
assert "argA" in res
452452

453453
@pytest.mark.asyncio
454-
async def test_bind_callable_param_success(self, tool_name, client):
455-
"""Tests 'bind_param' with a bound parameter specified."""
454+
async def test_bind_callable_params_success(self, tool_name, client):
455+
"""Tests 'bind_params' with a bound parameter specified."""
456456
tool = await client.load_tool(tool_name)
457457

458458
assert len(tool.__signature__.parameters) == 2
@@ -467,7 +467,7 @@ async def test_bind_callable_param_success(self, tool_name, client):
467467
assert "argA" in res
468468

469469
@pytest.mark.asyncio
470-
async def test_bind_param_fail(self, tool_name, client):
470+
async def test_bind_params_fail(self, tool_name, client):
471471
"""Tests 'bind_params' with a bound parameter that doesn't exist."""
472472
tool = await client.load_tool(tool_name)
473473

@@ -479,7 +479,7 @@ async def test_bind_param_fail(self, tool_name, client):
479479
assert "unable to bind parameters: no parameter named argC" in str(e.value)
480480

481481
@pytest.mark.asyncio
482-
async def test_rebind_param_fail(self, tool_name, client):
482+
async def test_rebind_params_fail(self, tool_name, client):
483483
"""
484484
Tests that 'bind_params' fails when attempting to re-bind a
485485
parameter that has already been bound.
@@ -502,7 +502,7 @@ async def test_rebind_param_fail(self, tool_name, client):
502502
)
503503

504504
@pytest.mark.asyncio
505-
async def test_bind_param_static_value_success(self, tool_name, client):
505+
async def test_bind_params_static_value_success(self, tool_name, client):
506506
"""
507507
Tests bind_params method with a static value.
508508
"""
@@ -522,7 +522,7 @@ async def test_bind_param_static_value_success(self, tool_name, client):
522522
assert res_payload == {"argA": passed_value_a, "argB": bound_value}
523523

524524
@pytest.mark.asyncio
525-
async def test_bind_param_sync_callable_value_success(self, tool_name, client):
525+
async def test_bind_params_sync_callable_value_success(self, tool_name, client):
526526
"""
527527
Tests bind_params method with a sync callable value.
528528
"""
@@ -544,7 +544,7 @@ async def test_bind_param_sync_callable_value_success(self, tool_name, client):
544544
bound_sync_callable.assert_called_once()
545545

546546
@pytest.mark.asyncio
547-
async def test_bind_param_async_callable_value_success(self, tool_name, client):
547+
async def test_bind_params_async_callable_value_success(self, tool_name, client):
548548
"""
549549
Tests bind_params method with an async callable value.
550550
"""
@@ -566,6 +566,138 @@ async def test_bind_param_async_callable_value_success(self, tool_name, client):
566566
bound_async_callable.assert_awaited_once()
567567

568568

569+
@pytest.mark.asyncio
570+
async def test_bind_param_success(self, tool_name, client):
571+
"""Tests 'bind_param' with a bound parameter specified."""
572+
tool = await client.load_tool(tool_name)
573+
574+
assert len(tool.__signature__.parameters) == 2
575+
assert "argA" in tool.__signature__.parameters
576+
577+
tool = tool.bind_param("argA", 5)
578+
579+
assert len(tool.__signature__.parameters) == 1
580+
assert "argA" not in tool.__signature__.parameters
581+
582+
res = await tool(True)
583+
assert "argA" in res
584+
585+
@pytest.mark.asyncio
586+
async def test_bind_callable_param_success(self, tool_name, client):
587+
"""Tests 'bind_param' with a bound parameter specified."""
588+
tool = await client.load_tool(tool_name)
589+
590+
assert len(tool.__signature__.parameters) == 2
591+
assert "argA" in tool.__signature__.parameters
592+
593+
tool = tool.bind_param("argA", lambda: 5)
594+
595+
assert len(tool.__signature__.parameters) == 1
596+
assert "argA" not in tool.__signature__.parameters
597+
598+
res = await tool(True)
599+
assert "argA" in res
600+
601+
@pytest.mark.asyncio
602+
async def test_bind_param_fail(self, tool_name, client):
603+
"""Tests 'bind_param' with a bound parameter that doesn't exist."""
604+
tool = await client.load_tool(tool_name)
605+
606+
assert len(tool.__signature__.parameters) == 2
607+
assert "argA" in tool.__signature__.parameters
608+
609+
with pytest.raises(Exception) as e:
610+
tool.bind_param("argC", lambda: 5)
611+
assert "unable to bind parameters: no parameter named argC" in str(e.value)
612+
613+
@pytest.mark.asyncio
614+
async def test_rebind_param_fail(self, tool_name, client):
615+
"""
616+
Tests that 'bind_param' fails when attempting to re-bind a
617+
parameter that has already been bound.
618+
"""
619+
tool = await client.load_tool(tool_name)
620+
621+
assert len(tool.__signature__.parameters) == 2
622+
assert "argA" in tool.__signature__.parameters
623+
624+
tool_with_bound_param = tool.bind_param("argA", lambda: 10)
625+
626+
assert len(tool_with_bound_param.__signature__.parameters) == 1
627+
assert "argA" not in tool_with_bound_param.__signature__.parameters
628+
629+
with pytest.raises(ValueError) as e:
630+
tool_with_bound_param.bind_param("argA", lambda: 20)
631+
632+
assert "cannot re-bind parameter: parameter 'argA' is already bound" in str(
633+
e.value
634+
)
635+
636+
@pytest.mark.asyncio
637+
async def test_bind_param_static_value_success(self, tool_name, client):
638+
"""
639+
Tests bind_param method with a static value.
640+
"""
641+
642+
bound_value = "Test value"
643+
644+
tool = await client.load_tool(tool_name)
645+
bound_tool = tool.bind_param("argB", bound_value)
646+
647+
assert bound_tool is not tool
648+
assert "argB" not in bound_tool.__signature__.parameters
649+
assert "argA" in bound_tool.__signature__.parameters
650+
651+
passed_value_a = 42
652+
res_payload = await bound_tool(argA=passed_value_a)
653+
654+
assert res_payload == {"argA": passed_value_a, "argB": bound_value}
655+
656+
@pytest.mark.asyncio
657+
async def test_bind_param_sync_callable_value_success(self, tool_name, client):
658+
"""
659+
Tests bind_param method with a sync callable value.
660+
"""
661+
662+
bound_value_result = True
663+
bound_sync_callable = Mock(return_value=bound_value_result)
664+
665+
tool = await client.load_tool(tool_name)
666+
bound_tool = tool.bind_param("argB", bound_sync_callable)
667+
668+
assert bound_tool is not tool
669+
assert "argB" not in bound_tool.__signature__.parameters
670+
assert "argA" in bound_tool.__signature__.parameters
671+
672+
passed_value_a = 42
673+
res_payload = await bound_tool(argA=passed_value_a)
674+
675+
assert res_payload == {"argA": passed_value_a, "argB": bound_value_result}
676+
bound_sync_callable.assert_called_once()
677+
678+
@pytest.mark.asyncio
679+
async def test_bind_param_async_callable_value_success(self, tool_name, client):
680+
"""
681+
Tests bind_param method with an async callable value.
682+
"""
683+
684+
bound_value_result = True
685+
bound_async_callable = AsyncMock(return_value=bound_value_result)
686+
687+
tool = await client.load_tool(tool_name)
688+
bound_tool = tool.bind_param("argB", bound_async_callable)
689+
690+
assert bound_tool is not tool
691+
assert "argB" not in bound_tool.__signature__.parameters
692+
assert "argA" in bound_tool.__signature__.parameters
693+
694+
passed_value_a = 42
695+
res_payload = await bound_tool(argA=passed_value_a)
696+
697+
assert res_payload == {"argA": passed_value_a, "argB": bound_value_result}
698+
bound_async_callable.assert_awaited_once()
699+
700+
569701
class TestUnusedParameterValidation:
570702
"""
571703
Tests for validation errors related to unused auth tokens or bound

0 commit comments

Comments
 (0)