Skip to content

Commit 0724e38

Browse files
committed
chore: Add unit test cases
1 parent 81ddf55 commit 0724e38

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

packages/toolbox-core/tests/test_tools.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
# limitations under the License.
1414

1515

16-
from toolbox_core.tool import create_docstring
16+
from unittest.mock import AsyncMock, Mock
17+
18+
import pytest
19+
20+
from toolbox_core.tool import create_docstring, resolve_value
1721

1822

1923
def test_create_docstring_no_params():
@@ -27,3 +31,64 @@ def test_create_docstring_no_params():
2731

2832
assert result_docstring == description
2933
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+
resolved = await resolve_value(sync_callable)
78+
79+
sync_callable.assert_called_once()
80+
assert resolved == expected_value
81+
82+
83+
@pytest.mark.asyncio
84+
async def test_resolve_value_async_callable():
85+
"""
86+
Tests resolve_value with an asynchronous callable (coroutine function).
87+
"""
88+
expected_value = "async result"
89+
async_callable = AsyncMock(return_value=expected_value)
90+
91+
resolved = await resolve_value(async_callable)
92+
93+
async_callable.assert_awaited_once()
94+
assert resolved == expected_value

0 commit comments

Comments
 (0)