Skip to content

Commit a80d94d

Browse files
committed
chore: Add test coverage for additional @Property methods
1 parent ee8185b commit a80d94d

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

packages/toolbox-core/tests/test_sync_client.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515

1616
import inspect
17-
from typing import Any, Callable, Mapping, Optional
17+
from asyncio import AbstractEventLoop
18+
from threading import Thread
19+
from typing import Any, Callable, Generator, Mapping, Optional
1820
from unittest.mock import AsyncMock, Mock, patch
1921

2022
import pytest
@@ -605,3 +607,53 @@ def test_constructor_getters_missing_fail(
605607
tool_name_auth,
606608
auth_token_getters={UNUSED_AUTH_SERVICE: lambda: "token"},
607609
)
610+
611+
612+
# --- Tests for @property methods of ToolboxSyncClient ---
613+
614+
615+
@pytest.fixture
616+
def sync_client_with_mocks() -> Generator[ToolboxSyncClient, Any, Any]:
617+
"""
618+
Fixture to create a ToolboxSyncClient with mocked internal async client
619+
without relying on actual network calls during init.
620+
"""
621+
with patch(
622+
"toolbox_core.sync_client.ToolboxClient", autospec=True
623+
) as MockToolboxClient:
624+
# Mock the async client's constructor to return an AsyncMock instance
625+
mock_async_client_instance = AsyncMock(spec=ToolboxClient)
626+
MockToolboxClient.return_value = mock_async_client_instance
627+
628+
# Mock the run_coroutine_threadsafe and its result()
629+
with patch("asyncio.run_coroutine_threadsafe") as mock_run_coroutine_threadsafe:
630+
mock_future = Mock()
631+
mock_future.result.return_value = mock_async_client_instance
632+
mock_run_coroutine_threadsafe.return_value = mock_future
633+
634+
client = ToolboxSyncClient(TEST_BASE_URL)
635+
yield client
636+
637+
638+
def test_sync_client_underscore_async_client_property(
639+
sync_client_with_mocks: ToolboxSyncClient,
640+
):
641+
"""Tests the _async_client property."""
642+
assert isinstance(sync_client_with_mocks._async_client, AsyncMock)
643+
644+
645+
def test_sync_client_underscore_loop_property(
646+
sync_client_with_mocks: ToolboxSyncClient,
647+
):
648+
"""Tests the _loop property."""
649+
assert sync_client_with_mocks._loop is not None
650+
assert isinstance(sync_client_with_mocks._loop, AbstractEventLoop)
651+
652+
653+
def test_sync_client_underscore_thread_property(
654+
sync_client_with_mocks: ToolboxSyncClient,
655+
):
656+
"""Tests the _thread property."""
657+
assert sync_client_with_mocks._thread is not None
658+
assert isinstance(sync_client_with_mocks._thread, Thread)
659+
assert sync_client_with_mocks._thread.is_alive()

0 commit comments

Comments
 (0)