Skip to content

Commit 897f627

Browse files
committed
chore: Add unit test coverage for internal properties
1 parent ceb3e9d commit 897f627

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

@@ -237,6 +238,41 @@ def test_sync_load_toolset_success(
237238
assert result1 == f"{TOOL1_NAME}_ok"
238239

239240

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

0 commit comments

Comments
 (0)