Skip to content

Commit

Permalink
Fix lint warnings (valkey-io#1039)
Browse files Browse the repository at this point in the history
found with `flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics --exclude=python/glide/protobuf,.env/* --extend-ignore=E230`

1     E203 whitespace before ':'
4     E711 comparison to None should be 'if cond is None:'
5     E712 comparison to True should be 'if cond is True:' or 'if cond:'
1     F401 'typing.Set' imported but unused
1     F841 local variable 'e' is assigned to but never used

Co-authored-by: nihohit <[email protected]>
  • Loading branch information
shachlanAmazon and nihohit authored Feb 26, 2024
1 parent ade0377 commit 17961c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion python/python/glide/redis_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio
import threading
from typing import List, Optional, Set, Tuple, Union, cast
from typing import List, Optional, Tuple, Union, cast

import async_timeout
from glide.async_commands.cluster_commands import ClusterCommands
Expand Down
49 changes: 18 additions & 31 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,9 @@ async def test_hexist(self, redis_client: TRedisClient):
field_value_map = {field: "value", field2: "value2"}

assert await redis_client.hset(key, field_value_map) == 2
assert await redis_client.hexists(key, field) == True
assert await redis_client.hexists(key, "nonExistingField") == False
assert await redis_client.hexists("nonExistingKey", field2) == False
assert await redis_client.hexists(key, field)
assert not await redis_client.hexists(key, "nonExistingField")
assert not await redis_client.hexists("nonExistingKey", field2)

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
Expand Down Expand Up @@ -938,21 +938,15 @@ async def test_expire_pexpire_ttl_with_positive_timeout(
# set command clears the timeout.
assert await redis_client.set(key, "bar") == OK
if await check_if_server_version_lt(redis_client, "7.0.0"):
assert await redis_client.pexpire(key, 10000) == True
assert await redis_client.pexpire(key, 10000)
else:
assert (
await redis_client.pexpire(key, 10000, ExpireOptions.HasNoExpiry)
== True
)
assert await redis_client.pexpire(key, 10000, ExpireOptions.HasNoExpiry)
assert await redis_client.ttl(key) in range(11)

if await check_if_server_version_lt(redis_client, "7.0.0"):
assert await redis_client.expire(key, 15) == True
assert await redis_client.expire(key, 15)
else:
assert (
await redis_client.expire(key, 15, ExpireOptions.HasExistingExpiry)
== True
)
assert await redis_client.expire(key, 15, ExpireOptions.HasExistingExpiry)
assert await redis_client.ttl(key) in range(16)

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand Down Expand Up @@ -981,11 +975,8 @@ async def test_expireat_pexpireat_ttl_with_positive_timeout(
assert await redis_client.set(key, "bar") == OK
current_time_ms = int(time.time() * 1000)
if not await check_if_server_version_lt(redis_client, "7.0.0"):
assert (
await redis_client.pexpireat(
key, current_time_ms + 50000, ExpireOptions.HasExistingExpiry
)
== False
assert not await redis_client.pexpireat(
key, current_time_ms + 50000, ExpireOptions.HasExistingExpiry
)

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand All @@ -1001,17 +992,15 @@ async def test_expire_pexpire_expireat_pexpireat_past_or_negative_timeout(
assert await redis_client.ttl(key) == -2

assert await redis_client.set(key, "foo") == OK
assert await redis_client.pexpire(key, -10000) == True
assert await redis_client.pexpire(key, -10000)
assert await redis_client.ttl(key) == -2

assert await redis_client.set(key, "foo") == OK
assert await redis_client.expireat(key, int(time.time()) - 50) == 1
assert await redis_client.ttl(key) == -2

assert await redis_client.set(key, "foo") == OK
assert (
await redis_client.pexpireat(key, int(time.time() * 1000) - 50000) == True
)
assert await redis_client.pexpireat(key, int(time.time() * 1000) - 50000)
assert await redis_client.ttl(key) == -2

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand All @@ -1022,11 +1011,9 @@ async def test_expire_pexpire_expireAt_pexpireAt_ttl_non_existing_key(
key = get_random_string(10)

assert await redis_client.expire(key, 10) == 0
assert await redis_client.pexpire(key, 10000) == False
assert not await redis_client.pexpire(key, 10000)
assert await redis_client.expireat(key, int(time.time()) + 50) == 0
assert (
await redis_client.pexpireat(key, int(time.time() * 1000) + 50000) == False
)
assert not await redis_client.pexpireat(key, int(time.time() * 1000) + 50000)
assert await redis_client.ttl(key) == -2

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand Down Expand Up @@ -1066,7 +1053,7 @@ async def test_zadd_nx_xx(self, redis_client: TRedisClient):
increment=5.0,
existing_options=ConditionalChange.ONLY_IF_DOES_NOT_EXIST,
)
== None
is None
)

assert (
Expand Down Expand Up @@ -1123,7 +1110,7 @@ async def test_zadd_gt_lt(self, redis_client: TRedisClient):
increment=-3.0,
update_condition=UpdateOptions.GREATER_THAN,
)
== None
is None
)

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand Down Expand Up @@ -1187,9 +1174,9 @@ async def test_zscore(self, redis_client: TRedisClient):
assert await redis_client.zadd(key, members_scores=members_scores) == 3
assert await redis_client.zscore(key, "one") == 1.0

assert await redis_client.zscore(key, "non_existing_member") == None
assert await redis_client.zscore(key, "non_existing_member") is None
assert (
await redis_client.zscore("non_existing_key", "non_existing_member") == None
await redis_client.zscore("non_existing_key", "non_existing_member") is None
)

@pytest.mark.parametrize("cluster_mode", [True, False])
Expand Down Expand Up @@ -1423,7 +1410,7 @@ class TestExceptions:
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_timeout_exception_with_blpop(self, redis_client: TRedisClient):
key = get_random_string(10)
with pytest.raises(TimeoutError) as e:
with pytest.raises(TimeoutError):
await redis_client.custom_command(["BLPOP", key, "1"])


Expand Down

0 comments on commit 17961c9

Please sign in to comment.