Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 05c881a

Browse files
committedApr 10, 2025·
chore: Add unit test cases
1 parent f36b618 commit 05c881a

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed
 

‎packages/toolbox-core/tests/test_tools.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
from typing import AsyncGenerator
17+
from unittest.mock import AsyncMock, Mock
1718

1819
import pytest
1920
import pytest_asyncio
@@ -22,7 +23,7 @@
2223
from pydantic import ValidationError
2324

2425
from toolbox_core.protocol import ParameterSchema
25-
from toolbox_core.tool import ToolboxTool, create_docstring
26+
from toolbox_core.tool import ToolboxTool, create_docstring, resolve_value
2627

2728
TEST_BASE_URL = "http://toolbox.example.com"
2829
TEST_TOOL_NAME = "sample_tool"
@@ -223,3 +224,64 @@ async def test_tool_run_with_pydantic_validation_error(
223224
in str(exc_info.value)
224225
)
225226
m.assert_not_called()
227+
228+
229+
@pytest.mark.asyncio
230+
@pytest.mark.parametrize(
231+
"non_callable_source",
232+
[
233+
"a simple string",
234+
12345,
235+
True,
236+
False,
237+
None,
238+
[1, "two", 3.0],
239+
{"key": "value", "number": 100},
240+
object(),
241+
],
242+
ids=[
243+
"string",
244+
"integer",
245+
"bool_true",
246+
"bool_false",
247+
"none",
248+
"list",
249+
"dict",
250+
"object",
251+
],
252+
)
253+
async def test_resolve_value_non_callable(non_callable_source):
254+
"""
255+
Tests resolve_value when the source is not callable.
256+
"""
257+
resolved = await resolve_value(non_callable_source)
258+
259+
assert resolved is non_callable_source
260+
261+
262+
@pytest.mark.asyncio
263+
async def test_resolve_value_sync_callable():
264+
"""
265+
Tests resolve_value with a synchronous callable.
266+
"""
267+
expected_value = "sync result"
268+
sync_callable = Mock(return_value=expected_value)
269+
270+
resolved = await resolve_value(sync_callable)
271+
272+
sync_callable.assert_called_once()
273+
assert resolved == expected_value
274+
275+
276+
@pytest.mark.asyncio
277+
async def test_resolve_value_async_callable():
278+
"""
279+
Tests resolve_value with an asynchronous callable (coroutine function).
280+
"""
281+
expected_value = "async result"
282+
async_callable = AsyncMock(return_value=expected_value)
283+
284+
resolved = await resolve_value(async_callable)
285+
286+
async_callable.assert_awaited_once()
287+
assert resolved == expected_value

0 commit comments

Comments
 (0)
Please sign in to comment.