Skip to content

Commit

Permalink
Python - type() fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Oct 16, 2023
1 parent ef16ce5 commit 22a287c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
10 changes: 5 additions & 5 deletions python/python/pybushka/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ def to_protobuf_slot_type(slot_type: SlotType) -> ProtoSlotTypes.ValueType:
def set_protobuf_route(request: RedisRequest, route: Optional[Route]) -> None:
if route is None:
return
elif type(route) == AllNodes:
elif isinstance(route, AllNodes):
request.route.simple_routes = SimpleRoutes.AllNodes
elif type(route) == AllPrimaries:
elif isinstance(route, AllPrimaries):
request.route.simple_routes = SimpleRoutes.AllPrimaries
elif type(route) == RandomNode:
elif isinstance(route, RandomNode):
request.route.simple_routes = SimpleRoutes.Random
elif type(route) == SlotKeyRoute:
elif isinstance(route, SlotKeyRoute):
request.route.slot_key_route.slot_type = to_protobuf_slot_type(route.slot_type)
request.route.slot_key_route.slot_key = route.slot_key
elif type(route) == SlotIdRoute:
elif isinstance(route, SlotIdRoute):
request.route.slot_id_route.slot_type = to_protobuf_slot_type(route.slot_type)
request.route.slot_id_route.slot_id = route.slot_id
else:
Expand Down
2 changes: 1 addition & 1 deletion python/python/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_convert_to_protobuf():
read_from_replica=ReadFromReplica.ROUND_ROBIN,
)
request = config._create_a_protobuf_conn_request()
assert type(request) == ConnectionRequest
assert isinstance(request, ConnectionRequest)
assert request.addresses[0].host == "127.0.0.1"
assert request.addresses[0].port == 6379
assert request.tls_mode is TlsMode.SecureTls
Expand Down
20 changes: 14 additions & 6 deletions python/python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class TestTransaction:
@pytest.mark.parametrize("cluster_mode", [True])
async def test_transaction_with_different_slots(self, redis_client: TRedisClient):
transaction = (
Transaction() if type(redis_client) == RedisClient else ClusterTransaction()
Transaction()
if isinstance(redis_client, RedisClient)
else ClusterTransaction()
)
transaction.set("key1", "value1")
transaction.set("key2", "value2")
Expand All @@ -84,7 +86,9 @@ async def test_transaction_with_different_slots(self, redis_client: TRedisClient
async def test_transaction_custom_command(self, redis_client: TRedisClient):
key = get_random_string(10)
transaction = (
Transaction() if type(redis_client) == RedisClient else ClusterTransaction()
Transaction()
if isinstance(redis_client, RedisClient)
else ClusterTransaction()
)
transaction.custom_command(["HSET", key, "foo", "bar"])
transaction.custom_command(["HGET", key, "foo"])
Expand All @@ -97,7 +101,9 @@ async def test_transaction_custom_unsupported_command(
):
key = get_random_string(10)
transaction = (
Transaction() if type(redis_client) == RedisClient else ClusterTransaction()
Transaction()
if isinstance(redis_client, RedisClient)
else ClusterTransaction()
)
transaction.custom_command(["WATCH", key])
with pytest.raises(Exception) as e:
Expand All @@ -111,7 +117,9 @@ async def test_transaction_discard_command(self, redis_client: TRedisClient):
key = get_random_string(10)
await redis_client.set(key, "1")
transaction = (
Transaction() if type(redis_client) == RedisClient else ClusterTransaction()
Transaction()
if isinstance(redis_client, RedisClient)
else ClusterTransaction()
)

transaction.custom_command(["INCR", key])
Expand Down Expand Up @@ -140,7 +148,7 @@ async def test_cluster_transaction(self, redis_client: RedisClusterClient):
transaction.info()
expected = transaction_test(transaction, keyslot)
result = await redis_client.exec(transaction)
assert type(result[0]) == str
assert isinstance(result[0], str)
assert "# Memory" in result[0]
assert result[1:] == expected

Expand All @@ -158,7 +166,7 @@ async def test_standalone_transaction(self, redis_client: RedisClient):
transaction.get(key)
expected = transaction_test(transaction, keyslot)
result = await redis_client.exec(transaction)
assert type(result[0]) == str
assert isinstance(result[0], str)
assert "# Memory" in result[0]
assert result[1:6] == [OK, OK, value, OK, None]
assert result[6:] == expected
Expand Down

0 comments on commit 22a287c

Please sign in to comment.