Skip to content

Commit 3560344

Browse files
committed
chore: Fix unit tests
1 parent 099b142 commit 3560344

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

packages/toolbox-llamaindex/tests/test_async_tools.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919
import pytest_asyncio
20+
from llama_index.core.tools.types import ToolOutput
2021
from pydantic import ValidationError
2122
from toolbox_core.protocol import ParameterSchema as CoreParameterSchema
2223
from toolbox_core.tool import ToolboxTool as ToolboxCoreTool
@@ -261,7 +262,14 @@ async def test_toolbox_tool_call_requires_auth_strict(self, auth_toolbox_tool):
261262

262263
async def test_toolbox_tool_call(self, toolbox_tool):
263264
result = await toolbox_tool.acall(param1="test-value", param2=123)
264-
assert result == "test-result"
265+
assert result == ToolOutput(
266+
content="test-result",
267+
tool_name="test_tool",
268+
raw_input={"param1": "test-value", "param2": 123},
269+
raw_output="test-result",
270+
is_error=False,
271+
)
272+
265273
core_tool = toolbox_tool._AsyncToolboxTool__core_tool
266274
core_tool._ToolboxTool__session.post.assert_called_once_with(
267275
"http://test_url/api/tool/test_tool/invoke",
@@ -281,7 +289,13 @@ async def test_toolbox_tool_call_with_bound_params(
281289
):
282290
tool = toolbox_tool.bind_params(bound_param_map)
283291
result = await tool.acall(param2=123)
284-
assert result == "test-result"
292+
assert result == ToolOutput(
293+
content="test-result",
294+
tool_name="test_tool",
295+
raw_input={"param2": 123},
296+
raw_output="test-result",
297+
is_error=False,
298+
)
285299
core_tool = tool._AsyncToolboxTool__core_tool
286300
core_tool._ToolboxTool__session.post.assert_called_once_with(
287301
"http://test_url/api/tool/test_tool/invoke",
@@ -294,7 +308,14 @@ async def test_toolbox_tool_call_with_auth_tokens(self, auth_toolbox_tool):
294308
{"test-auth-source": lambda: "test-token"}
295309
)
296310
result = await tool.acall(param2=123)
297-
assert result == "test-result"
311+
assert result == ToolOutput(
312+
content="test-result",
313+
tool_name="test_tool",
314+
raw_input={"param2": 123},
315+
raw_output="test-result",
316+
is_error=False,
317+
)
318+
298319
core_tool = tool._AsyncToolboxTool__core_tool
299320
core_tool._ToolboxTool__session.post.assert_called_once_with(
300321
"https://test-url/api/tool/test_tool/invoke",
@@ -325,7 +346,13 @@ async def test_toolbox_tool_call_with_auth_tokens_insecure(
325346
{"test-auth-source": lambda: "test-token"}
326347
)
327348
result = await tool_with_getter.acall(param2=123)
328-
assert result == "test-result"
349+
assert result == ToolOutput(
350+
content="test-result",
351+
tool_name="test_tool",
352+
raw_input={"param2": 123},
353+
raw_output="test-result",
354+
is_error=False,
355+
)
329356

330357
modified_core_tool_in_new_tool = tool_with_getter._AsyncToolboxTool__core_tool
331358
assert (

packages/toolbox-llamaindex/tests/test_tools.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from unittest.mock import AsyncMock, Mock, call, patch
1717

1818
import pytest
19+
from llama_index.core.tools.types import ToolOutput
1920
from pydantic import BaseModel
2021
from toolbox_core.protocol import ParameterSchema as CoreParameterSchema
2122
from toolbox_core.sync_tool import ToolboxSyncTool as ToolboxCoreSyncTool
@@ -271,8 +272,14 @@ def test_toolbox_tool_add_auth_token_getter(
271272

272273
def test_toolbox_tool_run(self, toolbox_tool, mock_core_tool):
273274
kwargs_to_run = {"param1": "run_value1", "param2": 100}
274-
expected_result = "sync_run_output"
275-
mock_core_tool.return_value = expected_result
275+
expected_result = ToolOutput(
276+
content="sync_run_output",
277+
tool_name="test_tool_name_for_llamaindex",
278+
raw_input=kwargs_to_run,
279+
raw_output="sync_run_output",
280+
is_error=False,
281+
)
282+
mock_core_tool.return_value = "sync_run_output"
276283

277284
result = toolbox_tool.call(**kwargs_to_run)
278285

@@ -286,9 +293,15 @@ async def test_toolbox_tool_arun(
286293
self, mock_to_thread_in_tools, toolbox_tool, mock_core_tool
287294
):
288295
kwargs_to_run = {"param1": "arun_value1", "param2": 200}
289-
expected_result = "async_run_output"
296+
expected_result = ToolOutput(
297+
content="async_run_output",
298+
tool_name="test_tool_name_for_llamaindex",
299+
raw_input=kwargs_to_run,
300+
raw_output="async_run_output",
301+
is_error=False,
302+
)
290303

291-
mock_core_tool.return_value = expected_result
304+
mock_core_tool.return_value = "async_run_output"
292305

293306
async def to_thread_side_effect(func, *args, **kwargs_for_func):
294307
return func(**kwargs_for_func)

0 commit comments

Comments
 (0)