From abcef703afd78802f776c616f74820127810f6b5 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Sun, 30 Jun 2024 17:08:17 -0700 Subject: [PATCH] Fixed tests and addressed comments --- python/python/glide/async_commands/core.py | 6 +- .../glide/async_commands/transaction.py | 2 +- python/python/tests/test_async_client.py | 55 +++++++++++++------ python/python/tests/test_transaction.py | 2 +- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 41862c37f6..799e0175d8 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -5611,7 +5611,7 @@ async def zscan( `String` pairs, where the value is at even indices and the score is at odd indices. Examples: - # Assume "key" contains a sorted set with 200 members + # Assume "key" contains a sorted set with multiple members >>> result_cursor = "0" >>> while True: ... result = await redis_client.zscan("key", "0", match="*", count=5) @@ -5647,7 +5647,7 @@ async def hscan( count: Optional[int] = None, ) -> List[Union[str, List[str]]]: """ - Iterates incrementally over a sorted set. + Iterates incrementally over a hash. See https://valkey.io/commands/hscan for more details. @@ -5672,7 +5672,7 @@ async def hscan( where the value is at even indices and the score is at odd indices. Examples: - # Assume "key" contains a sorted set with 200 members + # Assume "key" contains a hash with multiple members >>> result_cursor = "0" >>> while True: ... result = await redis_client.hscan("key", "0", match="*", count=3) diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 0eafe39929..631f2003fa 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -4084,7 +4084,7 @@ def hscan( count: Optional[int] = None, ) -> TTransaction: """ - Iterates incrementally over a sorted set. + Iterates incrementally over a hash. See https://valkey.io/commands/hscan for more details. diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index c3f3828001..08cdcaf58c 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -8230,16 +8230,14 @@ async def test_zscan(self, redis_client: GlideClusterClient): num_map_with_str_scores = {} for i in range(50000): # Use large dataset to force an iterative cursor. num_map.update({"value " + str(i): i}) - num_map_with_str_scores.update( - {b"value " + str(i).encode(): str(i).encode()} - ) + num_map_with_str_scores.update({"value " + str(i): str(i)}) char_map = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4} char_map_with_str_scores = { - b"a": b"0", - b"b": b"1", - b"c": b"2", - b"d": b"3", - b"e": b"4", + "a": "0", + "b": "1", + "c": "2", + "d": "3", + "e": "4", } convert_list_to_dict = lambda list: { @@ -8262,7 +8260,9 @@ async def test_zscan(self, redis_client: GlideClusterClient): result_collection = result[result_collection_index] assert result[result_cursor_index] == initial_cursor.encode() assert len(result_collection) == len(char_map) * 2 - assert convert_list_to_dict(result_collection) == char_map_with_str_scores + assert convert_list_to_dict(result_collection) == cast( + list, convert_string_to_bytes_object(char_map_with_str_scores) + ) result = await redis_client.zscan(key1, initial_cursor, match="a") result_collection = result[result_collection_index] @@ -8272,16 +8272,26 @@ async def test_zscan(self, redis_client: GlideClusterClient): # Result contains a subset of the key assert await redis_client.zadd(key1, num_map) == len(num_map) full_result_map = {} - result = await redis_client.zscan(key1, initial_cursor) - result_cursor = result[result_cursor_index] + result = result = cast( + list, + convert_bytes_to_string_object( + await redis_client.zscan(key1, initial_cursor) + ), + ) + result_cursor = str(result[result_cursor_index]) result_iteration_collection: dict[str, str] = convert_list_to_dict( result[result_collection_index] ) full_result_map.update(result_iteration_collection) # 0 is returned for the cursor of the last iteration. - while result_cursor != b"0": - next_result = await redis_client.zscan(key1, result_cursor.decode("utf-8")) + while result_cursor != "0": + next_result = cast( + list, + convert_bytes_to_string_object( + await redis_client.zscan(key1, result_cursor) + ), + ) next_result_cursor = next_result[result_cursor_index] assert next_result_cursor != result_cursor @@ -8373,18 +8383,27 @@ async def test_hscan(self, redis_client: GlideClusterClient): # Result contains a subset of the key assert await redis_client.hset(key1, num_map) == len(num_map) - result_cursor = "0" full_result_map = {} - result = await redis_client.hscan(key1, result_cursor) - result_cursor = result[result_cursor_index] + result = result = cast( + list, + convert_bytes_to_string_object( + await redis_client.hscan(key1, initial_cursor) + ), + ) + result_cursor = str(result[result_cursor_index]) result_iteration_collection: dict[str, str] = convert_list_to_dict( result[result_collection_index] ) full_result_map.update(result_iteration_collection) # 0 is returned for the cursor of the last iteration. - while result_cursor != b"0": - next_result = await redis_client.hscan(key1, result_cursor.decode("utf-8")) + while result_cursor != "0": + next_result = cast( + list, + convert_bytes_to_string_object( + await redis_client.hscan(key1, result_cursor) + ), + ) next_result_cursor = next_result[result_cursor_index] assert next_result_cursor != result_cursor diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 5a746df0ae..c7cf93638a 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -240,7 +240,7 @@ async def transaction_test( transaction.hscan(key4, "0") args.append([b"0", [key3.encode(), b"10.5"]]) transaction.hscan(key4, "0", match="*", count=10) - args.append([b"0", [key3, b"10.5"]]) + args.append([b"0", [key3.encode(), b"10.5"]]) transaction.hrandfield(key4) args.append(key3_bytes) transaction.hrandfield_count(key4, 1)