Skip to content

Commit 3baf342

Browse files
majiayu000claude
andcommitted
Add tests for Script/AsyncScript with RedisCluster type hints
Add tests to verify that Script and AsyncScript classes accept RedisCluster as registered_client, validating the type hints fix for register_script to support RedisCluster. - test_script_with_cluster_client: Tests sync Script with RedisCluster - test_async_script_with_cluster_client: Tests AsyncScript with RedisCluster 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a70fa15 commit 3baf342

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/test_asyncio/test_scripting.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
22
import pytest_asyncio
33
from redis import exceptions
4+
from redis.asyncio.cluster import RedisCluster
5+
from redis.commands.core import AsyncScript
46
from tests.conftest import skip_if_server_version_lt
57

68
multiply_script = """
@@ -150,3 +152,25 @@ async def test_eval_msgpack_pipeline_error_in_lua(self, r):
150152
with pytest.raises(exceptions.ResponseError) as excinfo:
151153
await pipe.execute()
152154
assert excinfo.type == exceptions.ResponseError
155+
156+
157+
class TestAsyncScriptTypeHints:
158+
"""Tests for AsyncScript type hints with RedisCluster support."""
159+
160+
@pytest.mark.asyncio()
161+
async def test_async_script_with_cluster_client(self):
162+
"""Test that AsyncScript class accepts RedisCluster as registered_client.
163+
164+
This verifies the type hints fix for register_script to support RedisCluster.
165+
We use a mock-like approach since we don't need actual cluster connection.
166+
"""
167+
from unittest.mock import MagicMock
168+
169+
# Create a mock RedisCluster instance
170+
mock_cluster = MagicMock(spec=RedisCluster)
171+
test_script = "return 1"
172+
173+
# AsyncScript should accept RedisCluster without type errors
174+
script = AsyncScript(mock_cluster, test_script)
175+
assert script.registered_client is mock_cluster
176+
assert script.script == test_script

tests/test_scripting.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import redis
33
from redis import exceptions
4+
from redis.cluster import RedisCluster
45
from redis.commands.core import Script
56
from tests.conftest import skip_if_redis_enterprise, skip_if_server_version_lt
67

@@ -53,6 +54,22 @@ def test_encoder(self, r, script_bytes):
5354
assert encoder is not None
5455
assert encoder.encode("fake-script") == b"fake-script"
5556

57+
def test_script_with_cluster_client(self, script_str):
58+
"""Test that Script class accepts RedisCluster as registered_client.
59+
60+
This verifies the type hints fix for register_script to support RedisCluster.
61+
We use a mock-like approach since we don't need actual cluster connection.
62+
"""
63+
from unittest.mock import MagicMock
64+
65+
# Create a mock RedisCluster instance
66+
mock_cluster = MagicMock(spec=RedisCluster)
67+
68+
# Script should accept RedisCluster without type errors
69+
script = Script(mock_cluster, script_str)
70+
assert script.registered_client is mock_cluster
71+
assert script.script == script_str
72+
5673

5774
class TestScripting:
5875
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)