|
26 | 26 | from toolbox_core.protocol import ManifestSchema, ParameterSchema, ToolSchema
|
27 | 27 | from toolbox_core.sync_client import ToolboxSyncClient
|
28 | 28 | from toolbox_core.sync_tool import ToolboxSyncTool
|
| 29 | +from toolbox_core.tool import ToolboxTool |
29 | 30 |
|
30 | 31 | TEST_BASE_URL = "http://toolbox.example.com"
|
31 | 32 |
|
@@ -237,6 +238,41 @@ def test_sync_load_toolset_success(
|
237 | 238 | assert result1 == f"{TOOL1_NAME}_ok"
|
238 | 239 |
|
239 | 240 |
|
| 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 | + |
240 | 276 | def test_sync_invoke_tool_server_error(aioresponses, test_tool_str_schema, sync_client):
|
241 | 277 | TOOL_NAME = "sync_server_error_tool"
|
242 | 278 | ERROR_MESSAGE = "Simulated Server Error for Sync Client"
|
|
0 commit comments