Skip to content

Commit e99a561

Browse files
committed
Update tests for RedisVL 0.4.0
1 parent c8b9571 commit e99a561

File tree

4 files changed

+75
-24
lines changed

4 files changed

+75
-24
lines changed

tests/test_async.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,26 @@ async def test_from_conn_string_errors() -> None:
287287
with pytest.raises(
288288
ValueError, match="Either redis_url or redis_client must be provided"
289289
):
290-
async with AsyncRedisSaver.from_conn_string() as _:
291-
pass
290+
async with AsyncRedisSaver.from_conn_string() as saver:
291+
await saver.asetup()
292292

293293
# Test with empty URL - should fail
294294
with pytest.raises(ValueError, match="REDIS_URL env var not set"):
295-
async with AsyncRedisSaver.from_conn_string("") as _:
296-
pass
295+
async with AsyncRedisSaver.from_conn_string("") as saver:
296+
await saver.asetup()
297297

298298
# Test with invalid connection URL
299299
with pytest.raises(RedisConnectionError):
300-
async with AsyncRedisSaver.from_conn_string("redis://nonexistent:6379") as _:
301-
await _.asetup() # Force connection attempt
300+
async with AsyncRedisSaver.from_conn_string(
301+
"redis://nonexistent:6379"
302+
) as saver:
303+
await saver.asetup()
302304

303305
# Test with non-functional client
304306
client = Redis.from_url("redis://nonexistent:6379")
305307
with pytest.raises(RedisConnectionError):
306-
async with AsyncRedisSaver.from_conn_string(redis_client=client) as _:
307-
await _.asetup() # Force connection attempt
308+
async with AsyncRedisSaver.from_conn_string(redis_client=client) as saver:
309+
await saver.asetup()
308310

309311

310312
@pytest.mark.asyncio

tests/test_shallow_async.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Any, AsyncGenerator, Dict
22

33
import pytest
4+
from redis.asyncio import Redis
5+
from redis.exceptions import ConnectionError as RedisConnectionError
46
from langchain_core.runnables import RunnableConfig
57
from langgraph.checkpoint.base import (
68
Checkpoint,
@@ -208,3 +210,50 @@ async def test_sequential_writes(
208210
assert result.pending_writes is not None
209211
assert len(result.pending_writes) == 1
210212
assert result.pending_writes[0] == ("task1", "channel2", "value2")
213+
214+
215+
@pytest.mark.asyncio
216+
async def test_from_conn_string_errors(redis_url: str) -> None:
217+
"""Test proper cleanup of Redis connections."""
218+
async with AsyncShallowRedisSaver.from_conn_string(redis_url) as s:
219+
saver_redis = s._redis
220+
assert await saver_redis.ping()
221+
222+
client = Redis.from_url(redis_url)
223+
try:
224+
async with AsyncShallowRedisSaver.from_conn_string(
225+
redis_client=client
226+
) as saver:
227+
assert saver._redis is client
228+
assert await saver._redis.ping()
229+
assert await client.ping()
230+
finally:
231+
await client.close()
232+
233+
"""Test error conditions for from_conn_string."""
234+
# Test with neither URL nor client provided
235+
with pytest.raises(
236+
ValueError, match="Either redis_url or redis_client must be provided"
237+
):
238+
async with AsyncShallowRedisSaver.from_conn_string() as saver:
239+
await saver.asetup()
240+
241+
# Test with invalid connection URL
242+
with pytest.raises(RedisConnectionError):
243+
async with AsyncShallowRedisSaver.from_conn_string(
244+
"redis://nonexistent:6379"
245+
) as saver:
246+
await saver.asetup()
247+
248+
# Test with non-responding client
249+
client = Redis(host="nonexistent", port=6379)
250+
with pytest.raises(RedisConnectionError):
251+
async with AsyncShallowRedisSaver.from_conn_string(
252+
redis_client=client
253+
) as saver:
254+
await saver.asetup()
255+
256+
# Test with empty URL
257+
with pytest.raises(ValueError, match="REDIS_URL env var not set"):
258+
async with AsyncShallowRedisSaver.from_conn_string("") as saver:
259+
await saver.asetup()

tests/test_shallow_sync.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,21 @@ def test_from_conn_string_errors(redis_url: str) -> None:
254254
with pytest.raises(
255255
ValueError, match="Either redis_url or redis_client must be provided"
256256
):
257-
with ShallowRedisSaver.from_conn_string() as _:
258-
pass
257+
with ShallowRedisSaver.from_conn_string() as saver:
258+
saver.setup()
259259

260260
# Test with invalid connection URL
261261
with pytest.raises(RedisConnectionError):
262-
with ShallowRedisSaver.from_conn_string("redis://nonexistent:6379") as _:
263-
pass
262+
with ShallowRedisSaver.from_conn_string("redis://nonexistent:6379") as saver:
263+
saver.setup()
264264

265265
# Test with non-responding client
266266
client = Redis(host="nonexistent", port=6379)
267267
with pytest.raises(RedisConnectionError):
268-
with ShallowRedisSaver.from_conn_string(redis_client=client) as _:
269-
pass
268+
with ShallowRedisSaver.from_conn_string(redis_client=client) as saver:
269+
saver.setup()
270270

271271
# Test with empty URL
272272
with pytest.raises(ValueError, match="REDIS_URL env var not set"):
273-
with ShallowRedisSaver.from_conn_string("") as _:
274-
pass
273+
with ShallowRedisSaver.from_conn_string("") as saver:
274+
saver.setup()

tests/test_sync.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,24 +337,24 @@ def test_from_conn_string_errors() -> None:
337337
with pytest.raises(
338338
ValueError, match="Either redis_url or redis_client must be provided"
339339
):
340-
with RedisSaver.from_conn_string() as _:
341-
pass
340+
with RedisSaver.from_conn_string() as saver:
341+
saver.setup()
342342

343343
# Test with empty URL
344344
with pytest.raises(ValueError, match="REDIS_URL env var not set"):
345-
with RedisSaver.from_conn_string("") as _:
346-
pass
345+
with RedisSaver.from_conn_string("") as saver:
346+
saver.setup()
347347

348348
# Test with invalid connection URL
349349
with pytest.raises(RedisConnectionError):
350-
with RedisSaver.from_conn_string("redis://nonexistent:6379") as _:
351-
pass
350+
with RedisSaver.from_conn_string("redis://nonexistent:6379") as saver:
351+
saver.setup()
352352

353353
# Test with non-responding client
354354
client = Redis(host="nonexistent", port=6379)
355355
with pytest.raises(RedisConnectionError):
356-
with RedisSaver.from_conn_string(redis_client=client) as _:
357-
pass
356+
with RedisSaver.from_conn_string(redis_client=client) as saver:
357+
saver.setup()
358358

359359

360360
def test_large_batches(test_data: dict[str, Any], redis_url: str) -> None:

0 commit comments

Comments
 (0)