Skip to content

Commit 60f7615

Browse files
committed
chore: Add toolbox tool unit test cases
1 parent 9e843dc commit 60f7615

File tree

2 files changed

+98
-4
lines changed

2 files changed

+98
-4
lines changed

packages/toolbox-core/tests/test_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ async def test_load_tool_not_found_in_manifest(aioresponses, test_tool_str):
413413
REQUESTED_TOOL_NAME = "non_existent_tool_xyz"
414414

415415
manifest = ManifestSchema(
416-
serverVersion="0.0.0",
417-
tools={ACTUAL_TOOL_IN_MANIFEST: test_tool_str}
416+
serverVersion="0.0.0", tools={ACTUAL_TOOL_IN_MANIFEST: test_tool_str}
418417
)
419418

420419
aioresponses.get(
@@ -428,5 +427,5 @@ async def test_load_tool_not_found_in_manifest(aioresponses, test_tool_str):
428427
await client.load_tool(REQUESTED_TOOL_NAME)
429428

430429
aioresponses.assert_called_once_with(
431-
f"{TEST_BASE_URL}/api/tool/{REQUESTED_TOOL_NAME}", method='GET'
432-
)
430+
f"{TEST_BASE_URL}/api/tool/{REQUESTED_TOOL_NAME}", method="GET"
431+
)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
from unittest.mock import AsyncMock, Mock
17+
18+
import pytest
19+
20+
from toolbox_core.tool import create_docstring, resolve_value
21+
22+
23+
def test_create_docstring_no_params():
24+
"""
25+
Tests create_docstring when the params list is empty.
26+
"""
27+
description = "This is a tool description."
28+
params = []
29+
30+
result_docstring = create_docstring(description, params)
31+
32+
assert result_docstring == description
33+
assert "\n\nArgs:" not in result_docstring
34+
35+
36+
@pytest.mark.asyncio
37+
@pytest.mark.parametrize(
38+
"non_callable_source",
39+
[
40+
"a simple string",
41+
12345,
42+
True,
43+
False,
44+
None,
45+
[1, "two", 3.0],
46+
{"key": "value", "number": 100},
47+
object(),
48+
],
49+
ids=[
50+
"string",
51+
"integer",
52+
"bool_true",
53+
"bool_false",
54+
"none",
55+
"list",
56+
"dict",
57+
"object",
58+
],
59+
)
60+
async def test_resolve_value_non_callable(non_callable_source):
61+
"""
62+
Tests resolve_value when the source is not callable.
63+
"""
64+
resolved = await resolve_value(non_callable_source)
65+
66+
assert resolved is non_callable_source
67+
68+
69+
@pytest.mark.asyncio
70+
async def test_resolve_value_sync_callable():
71+
"""
72+
Tests resolve_value with a synchronous callable.
73+
"""
74+
expected_value = "sync result"
75+
sync_callable = Mock(return_value=expected_value)
76+
77+
# Call the async function
78+
resolved = await resolve_value(sync_callable)
79+
80+
sync_callable.assert_called_once()
81+
assert resolved == expected_value
82+
83+
84+
@pytest.mark.asyncio
85+
async def test_resolve_value_async_callable():
86+
"""
87+
Tests resolve_value with an asynchronous callable (coroutine function).
88+
"""
89+
expected_value = "async result"
90+
async_callable = AsyncMock(return_value=expected_value)
91+
92+
resolved = await resolve_value(async_callable)
93+
94+
async_callable.assert_awaited_once()
95+
assert resolved == expected_value

0 commit comments

Comments
 (0)