Skip to content

Commit

Permalink
Python: update map comparisons to use compare_maps function (valkey-i…
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored May 16, 2024
1 parent 0d674ba commit 65f9635
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,8 @@ async def test_zremrangebylex(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(key1, range) == {"a": 1.0, "d": 4.0}
zremrangebylex_res = await redis_client.zrange_withscores(key1, range)
assert compare_maps(zremrangebylex_res, {"a": 1.0, "d": 4.0}) is True

assert (
await redis_client.zremrangebylex(key1, LexBoundary("d"), InfBound.POS_INF)
Expand Down Expand Up @@ -2312,9 +2313,10 @@ async def test_zrangestore_by_index(self, redis_client: TRedisClient):
await redis_client.zrangestore(destination, source, RangeByIndex(0, -1))
== 3
)
assert await redis_client.zrange_withscores(
zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"one": 1.0, "two": 2.0, "three": 3.0}
)
assert compare_maps(zrange_res, {"one": 1.0, "two": 2.0, "three": 3.0}) is True

# range from rank 0 to 1, from highest to lowest score
assert (
Expand All @@ -2323,9 +2325,11 @@ async def test_zrangestore_by_index(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"three": 3.0, "two": 2.0}
)
assert compare_maps(zrange_res, {"two": 2.0, "three": 3.0}) is True

# incorrect range, as start > stop
assert (
Expand Down Expand Up @@ -2377,9 +2381,11 @@ async def test_zrangestore_by_score(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"one": 1.0, "two": 2.0}
)
assert compare_maps(zrange_res, {"one": 1.0, "two": 2.0}) is True

# range from 1 (inclusive) to positive infinity
assert (
Expand All @@ -2388,9 +2394,10 @@ async def test_zrangestore_by_score(self, redis_client: TRedisClient):
)
== 3
)
assert await redis_client.zrange_withscores(
zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"one": 1.0, "two": 2.0, "three": 3.0}
)
assert compare_maps(zrange_res, {"one": 1.0, "two": 2.0, "three": 3.0}) is True

# range from negative to positive infinity, limited to ranks 1 to 2
assert (
Expand All @@ -2401,9 +2408,10 @@ async def test_zrangestore_by_score(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(
zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"two": 2.0, "three": 3.0}
)
assert compare_maps(zrange_res, {"two": 2.0, "three": 3.0}) is True

# range from positive to negative infinity reversed, limited to ranks 1 to 2
assert (
Expand All @@ -2415,9 +2423,11 @@ async def test_zrangestore_by_score(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"two": 2.0, "one": 1.0}
)
assert compare_maps(zrange_res, {"one": 1.0, "two": 2.0}) is True

# incorrect range as start > stop
assert (
Expand Down Expand Up @@ -2482,9 +2492,11 @@ async def test_zrangestore_by_lex(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"a": 1.0, "b": 2.0}
)
assert compare_maps(zrange_res, {"a": 1.0, "b": 2.0}) is True

# range from "a" (inclusive) to positive infinity
assert (
Expand All @@ -2493,9 +2505,11 @@ async def test_zrangestore_by_lex(self, redis_client: TRedisClient):
)
== 3
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"a": 1.0, "b": 2.0, "c": 3.0}
)
assert compare_maps(zrange_res, {"a": 1.0, "b": 2.0, "c": 3.0}) is True

# range from negative to positive infinity, limited to ranks 1 to 2
assert (
Expand All @@ -2506,9 +2520,11 @@ async def test_zrangestore_by_lex(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"b": 2.0, "c": 3.0}
)
assert compare_maps(zrange_res, {"b": 2.0, "c": 3.0}) is True

# range from positive to negative infinity reversed, limited to ranks 1 to 2
assert (
Expand All @@ -2520,9 +2536,11 @@ async def test_zrangestore_by_lex(self, redis_client: TRedisClient):
)
== 2
)
assert await redis_client.zrange_withscores(

zrange_res = await redis_client.zrange_withscores(
destination, RangeByIndex(0, -1)
) == {"b": 2.0, "a": 1.0}
)
assert compare_maps(zrange_res, {"a": 1.0, "b": 2.0}) is True

# incorrect range as start > stop
assert (
Expand Down Expand Up @@ -2669,10 +2687,9 @@ async def test_zdiffstore(self, redis_client: TRedisClient):
assert await redis_client.zadd(key3, member_scores3) == 4

assert await redis_client.zdiffstore(key4, [key1, key2]) == 2
assert await redis_client.zrange_withscores(key4, RangeByIndex(0, -1)) == {
"one": 1.0,
"three": 3.0,
}

zrange_res = await redis_client.zrange_withscores(key4, RangeByIndex(0, -1))
assert compare_maps(zrange_res, {"one": 1.0, "three": 3.0}) is True

assert await redis_client.zdiffstore(key4, [key3, key2, key1]) == 1
assert await redis_client.zrange_withscores(key4, RangeByIndex(0, -1)) == {
Expand Down

0 comments on commit 65f9635

Please sign in to comment.