|
14 | 14 |
|
15 | 15 |
|
16 | 16 | from typing import AsyncGenerator
|
| 17 | +from unittest.mock import AsyncMock, Mock |
17 | 18 |
|
18 | 19 | import pytest
|
19 | 20 | import pytest_asyncio
|
|
22 | 23 | from pydantic import ValidationError
|
23 | 24 |
|
24 | 25 | 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 |
26 | 27 |
|
27 | 28 | TEST_BASE_URL = "http://toolbox.example.com"
|
28 | 29 | TEST_TOOL_NAME = "sample_tool"
|
@@ -223,3 +224,64 @@ async def test_tool_run_with_pydantic_validation_error(
|
223 | 224 | in str(exc_info.value)
|
224 | 225 | )
|
225 | 226 | 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