Skip to content

Commit

Permalink
skip more tests and fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
dvora-h committed May 1, 2024
1 parent b1b6dbb commit 1b40a31
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 29 deletions.
6 changes: 3 additions & 3 deletions redis/_parsers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ def string_keys_to_dict(key_string, callback):
),
"COMMAND": parse_command_resp3,
"CONFIG GET": lambda r: {
str_if_bytes(key) if key is not None else None: (
str_if_bytes(value) if value is not None else None
)
str_if_bytes(key)
if key is not None
else None: (str_if_bytes(value) if value is not None else None)
for key, value in r.items()
},
"MEMORY STATS": lambda r: {str_if_bytes(key): value for key, value in r.items()},
Expand Down
12 changes: 8 additions & 4 deletions redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@


class ResponseCallbackProtocol(Protocol):
def __call__(self, response: Any, **kwargs): ...
def __call__(self, response: Any, **kwargs):
...


class AsyncResponseCallbackProtocol(Protocol):
async def __call__(self, response: Any, **kwargs): ...
async def __call__(self, response: Any, **kwargs):
...


ResponseCallbackT = Union[ResponseCallbackProtocol, AsyncResponseCallbackProtocol]
Expand Down Expand Up @@ -1218,11 +1220,13 @@ async def run(


class PubsubWorkerExceptionHandler(Protocol):
def __call__(self, e: BaseException, pubsub: PubSub): ...
def __call__(self, e: BaseException, pubsub: PubSub):
...


class AsyncPubsubWorkerExceptionHandler(Protocol):
async def __call__(self, e: BaseException, pubsub: PubSub): ...
async def __call__(self, e: BaseException, pubsub: PubSub):
...


PSWorkerThreadExcHandlerT = Union[
Expand Down
14 changes: 7 additions & 7 deletions redis/asyncio/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ def __init__(
self.command_flags = self.__class__.COMMAND_FLAGS.copy()
self.response_callbacks = kwargs["response_callbacks"]
self.result_callbacks = self.__class__.RESULT_CALLBACKS.copy()
self.result_callbacks["CLUSTER SLOTS"] = (
lambda cmd, res, **kwargs: parse_cluster_slots(
list(res.values())[0], **kwargs
)
self.result_callbacks[
"CLUSTER SLOTS"
] = lambda cmd, res, **kwargs: parse_cluster_slots(
list(res.values())[0], **kwargs
)

self._initialize = True
Expand Down Expand Up @@ -1318,9 +1318,9 @@ async def initialize(self) -> None:
)
tmp_slots[i].append(target_replica_node)
# add this node to the nodes cache
tmp_nodes_cache[target_replica_node.name] = (
target_replica_node
)
tmp_nodes_cache[
target_replica_node.name
] = target_replica_node
else:
# Validate that 2 nodes want to use the same slot cache
# setup
Expand Down
6 changes: 4 additions & 2 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ class _Sentinel(enum.Enum):


class ConnectCallbackProtocol(Protocol):
def __call__(self, connection: "AbstractConnection"): ...
def __call__(self, connection: "AbstractConnection"):
...


class AsyncConnectCallbackProtocol(Protocol):
async def __call__(self, connection: "AbstractConnection"): ...
async def __call__(self, connection: "AbstractConnection"):
...


ConnectCallbackT = Union[ConnectCallbackProtocol, AsyncConnectCallbackProtocol]
Expand Down
6 changes: 3 additions & 3 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,9 +1582,9 @@ def initialize(self):
)
tmp_slots[i].append(target_replica_node)
# add this node to the nodes cache
tmp_nodes_cache[target_replica_node.name] = (
target_replica_node
)
tmp_nodes_cache[
target_replica_node.name
] = target_replica_node
else:
# Validate that 2 nodes want to use the same slot cache
# setup
Expand Down
4 changes: 3 additions & 1 deletion redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3399,7 +3399,9 @@ def smembers(self, name: str) -> Union[Awaitable[Set], Set]:
"""
return self.execute_command("SMEMBERS", name, keys=[name])

def smismember(self, name: str, values: List, *args: List) -> Union[
def smismember(
self, name: str, values: List, *args: List
) -> Union[
Awaitable[List[Union[Literal[0], Literal[1]]]],
List[Union[Literal[0], Literal[1]]],
]:
Expand Down
3 changes: 2 additions & 1 deletion redis/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ class SlotNotCoveredError(RedisClusterException):
pass


class MaxConnectionsError(ConnectionError): ...
class MaxConnectionsError(ConnectionError):
...
6 changes: 4 additions & 2 deletions redis/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
class CommandsProtocol(Protocol):
connection_pool: Union["AsyncConnectionPool", "ConnectionPool"]

def execute_command(self, *args, **options): ...
def execute_command(self, *args, **options):
...


class ClusterCommandsProtocol(CommandsProtocol, Protocol):
encoder: "Encoder"

def execute_command(self, *args, **options) -> Union[Any, Awaitable]: ...
def execute_command(self, *args, **options) -> Union[Any, Awaitable]:
...
1 change: 1 addition & 0 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,7 @@ async def test_xgroup_destroy(self, r: redis.Redis):
assert await r.xgroup_destroy(stream, group)

@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
async def test_xgroup_setid(self, r: redis.Redis):
stream = "stream"
group = "group"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_asyncio/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async def test_credential_provider_with_supplier(

assert await r2.ping() is True

@skip_if_redis_enterprise()
async def test_async_credential_provider_no_password_success(
self, r_acl_teardown, create_redis
):
Expand All @@ -188,6 +189,7 @@ async def test_async_credential_provider_no_password_success(
assert await r2.ping() is True

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_credential_provider_no_password_error(
self, r_acl_teardown, create_redis
):
Expand All @@ -204,6 +206,7 @@ async def test_credential_provider_no_password_error(
assert await r.acl_deluser(username)

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_password_and_username_together_with_cred_provider_raise_error(
self, r_acl_teardown, create_redis
):
Expand All @@ -227,6 +230,7 @@ async def test_password_and_username_together_with_cred_provider_raise_error(
)

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_change_username_password_on_existing_connection(
self, r_acl_teardown, create_redis
):
Expand All @@ -252,6 +256,7 @@ async def test_change_username_password_on_existing_connection(

@pytest.mark.asyncio
class TestUsernamePasswordCredentialProvider:
@skip_if_redis_enterprise()
async def test_user_pass_credential_provider_acl_user_and_pass(
self, r_acl_teardown, create_redis
):
Expand All @@ -266,6 +271,7 @@ async def test_user_pass_credential_provider_acl_user_and_pass(
r2 = await create_redis(flushdb=False, credential_provider=provider)
assert await r2.ping() is True

@skip_if_redis_enterprise()
async def test_user_pass_provider_only_password(
self, r_required_pass_teardown, create_redis
):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asyncio/test_cwe_404.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from redis.asyncio import Redis
from redis.asyncio.cluster import RedisCluster
from redis.asyncio.connection import async_timeout
from tests.conftest import skip_if_redis_enterprise


class DelayProxy:
Expand Down Expand Up @@ -141,6 +142,7 @@ async def op(r):


@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
@pytest.mark.parametrize("delay", argvalues=[0.05, 0.5, 1, 2])
async def test_standalone_pipeline(delay, master_host):
async with DelayProxy(addr=("127.0.0.1", 5380), redis_addr=master_host) as dp:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_asyncio/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import redis.asyncio as redis
from redis import exceptions
from redis.commands.json.path import Path
from tests.conftest import assert_resp_response, skip_ifmodversion_lt
from tests.conftest import (
assert_resp_response,
skip_if_redis_enterprise,
skip_ifmodversion_lt,
)


async def test_json_setbinarykey(decoded_r: redis.Redis):
Expand Down Expand Up @@ -95,6 +99,7 @@ async def test_jsonsetexistentialmodifiersshouldsucceed(decoded_r: redis.Redis):
await decoded_r.json().set("obj", Path("foo"), "baz", nx=True, xx=True)


@skip_if_redis_enterprise()
async def test_mgetshouldsucceed(decoded_r: redis.Redis):
await decoded_r.json().set("1", Path.root_path(), 1)
await decoded_r.json().set("2", Path.root_path(), 2)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_asyncio/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import redis
from tests.conftest import skip_if_server_version_lt
from tests.conftest import skip_if_redis_enterprise, skip_if_server_version_lt

from .compat import aclosing, mock
from .conftest import wait_for_command
Expand All @@ -12,6 +12,7 @@ async def test_pipeline_is_true(self, r):
async with r.pipeline() as pipe:
assert pipe

@skip_if_redis_enterprise()
async def test_pipeline(self, r):
async with r.pipeline() as pipe:
(
Expand All @@ -34,6 +35,7 @@ async def test_pipeline_memoryview(self, r):
(pipe.set("a", memoryview(b"a1")).get("a"))
assert await pipe.execute() == [True, b"a1"]

@skip_if_redis_enterprise()
async def test_pipeline_length(self, r):
async with r.pipeline() as pipe:
# Initially empty.
Expand Down Expand Up @@ -85,6 +87,7 @@ async def test_pipeline_no_transaction_watch_failure(self, r):

assert await r.get("a") == b"bad"

@skip_if_redis_enterprise()
async def test_exec_error_in_response(self, r):
"""
an invalid pipeline command at exec time adds the exception instance
Expand Down Expand Up @@ -191,6 +194,7 @@ async def test_parse_error_raised_transaction(self, r):
assert await r.get("z") == b"zzz"

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_watch_succeed(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand All @@ -209,6 +213,7 @@ async def test_watch_succeed(self, r):
assert not pipe.watching

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_watch_failure(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand All @@ -224,6 +229,7 @@ async def test_watch_failure(self, r):
assert not pipe.watching

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_watch_failure_in_empty_transaction(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand All @@ -238,6 +244,7 @@ async def test_watch_failure_in_empty_transaction(self, r):
assert not pipe.watching

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_unwatch(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand All @@ -251,6 +258,7 @@ async def test_unwatch(self, r):
assert await pipe.execute() == [b"1"]

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_watch_exec_no_unwatch(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand Down Expand Up @@ -305,6 +313,7 @@ async def test_aclosing(self, r):
pass

@pytest.mark.onlynoncluster
@skip_if_redis_enterprise()
async def test_transaction_callable(self, r):
await r.set("a", 1)
await r.set("b", 2)
Expand Down Expand Up @@ -368,6 +377,7 @@ async def test_exec_error_in_no_transaction_pipeline_unicode_command(self, r):

assert await r.get(key) == b"1"

@skip_if_redis_enterprise()
async def test_pipeline_with_bitfield(self, r):
async with r.pipeline() as pipe:
pipe.set("a", "1")
Expand All @@ -394,6 +404,7 @@ async def test_pipeline_get(self, r):

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.0.0")
@skip_if_redis_enterprise()
async def test_pipeline_discard(self, r):
# empty pipeline should raise an error
async with r.pipeline() as pipe:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_asyncio/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tests.conftest import (
assert_resp_response,
is_resp2_connection,
skip_if_redis_enterprise,
skip_ifmodversion_lt,
)

Expand Down Expand Up @@ -175,6 +176,7 @@ async def test_incrby_decrby(decoded_r: redis.Redis):
assert_resp_response(decoded_r, 128, info.get("chunk_size"), info.get("chunkSize"))


@skip_if_redis_enterprise()
async def test_create_and_delete_rule(decoded_r: redis.Redis):
# test rule creation
time = 100
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from .conftest import (
assert_resp_response,
is_resp2_connection,
skip_ifmodversion_lt,
skip_if_redis_enterprise,
skip_ifmodversion_lt,
)


Expand Down
2 changes: 2 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def test_config_get(self, r):
# # assert 'maxmemory' in data
# assert data['maxmemory'].isdigit()

@skip_if_redis_enterprise()
@skip_if_server_version_lt("7.0.0")
def test_config_get_multi_params(self, r: redis.Redis):
res = r.config_get("*max-*-entries*", "maxmemory")
Expand Down Expand Up @@ -4422,6 +4423,7 @@ def test_xgroup_destroy(self, r):
assert r.xgroup_destroy(stream, group)

@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
def test_xgroup_setid(self, r):
stream = "stream"
group = "group"
Expand Down
1 change: 1 addition & 0 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def test_read_only_error(self, r):
with pytest.raises(redis.ReadOnlyError):
r.execute_command("DEBUG", "ERROR", "READONLY blah blah")

@skip_if_redis_enterprise()
def test_oom_error(self, r):
"OOM errors get turned into OutOfMemoryError exceptions"
with pytest.raises(redis.OutOfMemoryError):
Expand Down
Loading

0 comments on commit 1b40a31

Please sign in to comment.