Skip to content

Commit 080706c

Browse files
committed
chore: Add unit test coverage for internal properties
1 parent a80d94d commit 080706c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/toolbox-core/tests/test_sync_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from toolbox_core.protocol import ManifestSchema, ParameterSchema, ToolSchema
2727
from toolbox_core.sync_client import ToolboxSyncClient
2828
from toolbox_core.sync_tool import ToolboxSyncTool
29+
from toolbox_core.tool import ToolboxTool
2930

3031
TEST_BASE_URL = "http://toolbox.example.com"
3132

@@ -234,6 +235,41 @@ def test_sync_load_toolset_success(
234235
assert result1 == f"{TOOL1_NAME}_ok"
235236

236237

238+
def test_sync_tool_internal_properties(aioresponses, tool_schema_minimal, sync_client):
239+
"""
240+
Tests that the internal properties _async_tool, _loop, and _thread
241+
of a ToolboxSyncTool instance are correctly initialized and accessible.
242+
This directly covers the respective @property methods in ToolboxSyncTool.
243+
"""
244+
TOOL_NAME = "test_tool_for_internal_properties"
245+
mock_tool_load(aioresponses, TOOL_NAME, tool_schema_minimal)
246+
247+
loaded_sync_tool = sync_client.load_tool(TOOL_NAME)
248+
249+
assert isinstance(loaded_sync_tool, ToolboxSyncTool)
250+
251+
# 1. Test the _async_tool property
252+
internal_async_tool = loaded_sync_tool._async_tool
253+
assert isinstance(internal_async_tool, ToolboxTool)
254+
assert internal_async_tool.__name__ == TOOL_NAME
255+
256+
# 2. Test the _loop property
257+
internal_loop = loaded_sync_tool._loop
258+
assert isinstance(internal_loop, AbstractEventLoop)
259+
assert internal_loop is sync_client._ToolboxSyncClient__loop
260+
assert (
261+
internal_loop.is_running()
262+
), "The event loop used by ToolboxSyncTool should be running."
263+
264+
# 3. Test the _thread property
265+
internal_thread = loaded_sync_tool._thread
266+
assert isinstance(internal_thread, Thread)
267+
assert internal_thread is sync_client._ToolboxSyncClient__thread
268+
assert (
269+
internal_thread.is_alive()
270+
), "The thread used by ToolboxSyncTool should be alive."
271+
272+
237273
def test_sync_invoke_tool_server_error(aioresponses, test_tool_str_schema, sync_client):
238274
TOOL_NAME = "sync_server_error_tool"
239275
ERROR_MESSAGE = "Simulated Server Error for Sync Client"

0 commit comments

Comments
 (0)