Skip to content

Commit 524e8f6

Browse files
committed
Mock LangCacheWrapper._create_client in tests to avoid SDK import and simplify setup
1 parent 5853a94 commit 524e8f6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tests/unit/test_langcache_wrapper.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010

1111
@pytest.fixture
1212
def mock_langcache_client():
13-
"""Create a mock LangCache client."""
14-
with patch(
15-
"redisvl.extensions.cache.llm.langcache.LangCacheClient"
16-
) as mock_client_class:
13+
"""Create a mock LangCache client via the wrapper factory method."""
14+
with patch.object(LangCacheWrapper, "_create_client") as mock_create_client:
1715
mock_client = MagicMock()
18-
mock_client_class.return_value = mock_client
16+
mock_create_client.return_value = mock_client
1917

2018
# Mock context manager
2119
mock_client.__enter__ = MagicMock(return_value=mock_client)
2220
mock_client.__exit__ = MagicMock(return_value=None)
2321
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
2422
mock_client.__aexit__ = AsyncMock(return_value=None)
2523

26-
yield mock_client_class, mock_client
24+
yield mock_create_client, mock_client
2725

2826

2927
@pytest.mark.skipif(
@@ -67,7 +65,7 @@ def test_init_requires_at_least_one_search_strategy(self):
6765

6866
def test_init_success(self, mock_langcache_client):
6967
"""Test successful initialization."""
70-
mock_client_class, _ = mock_langcache_client
68+
mock_create_client, _ = mock_langcache_client
7169

7270
cache = LangCacheWrapper(
7371
name="test_cache",
@@ -84,7 +82,7 @@ def test_init_success(self, mock_langcache_client):
8482
assert cache.ttl == 3600
8583

8684
# Verify client was initialized
87-
mock_client_class.assert_called_once()
85+
mock_create_client.assert_called_once()
8886

8987
def test_store(self, mock_langcache_client):
9088
"""Test storing a cache entry."""

0 commit comments

Comments
 (0)