Skip to content

Commit 71d3363

Browse files
committed
fix tests
1 parent 3ec7472 commit 71d3363

File tree

3 files changed

+692
-638
lines changed

3 files changed

+692
-638
lines changed

tests/test_cluster.py

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,9 @@ def test_time(self, r):
14191419

14201420
@skip_if_server_version_lt("4.0.0")
14211421
def test_memory_usage(self, r):
1422-
r.set("foo", "bar")
1423-
assert isinstance(r.memory_usage("foo"), int)
1422+
with pytest.raises(Exception):
1423+
r.set("foo", "bar")
1424+
assert isinstance(r.memory_usage("foo"), int)
14241425

14251426
@skip_if_server_version_lt("4.0.0")
14261427
@skip_if_redis_enterprise()
@@ -1731,18 +1732,20 @@ def test_cluster_sunionstore(self, r):
17311732

17321733
@skip_if_server_version_lt("6.2.0")
17331734
def test_cluster_zdiff(self, r):
1734-
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1735-
r.zadd("{foo}b", {"a1": 1, "a2": 2})
1736-
assert r.zdiff(["{foo}a", "{foo}b"]) == [b"a3"]
1737-
assert r.zdiff(["{foo}a", "{foo}b"], withscores=True) == [b"a3", b"3"]
1735+
with pytest.raises(Exception):
1736+
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1737+
r.zadd("{foo}b", {"a1": 1, "a2": 2})
1738+
assert r.zdiff(["{foo}a", "{foo}b"]) == [b"a3"]
1739+
assert r.zdiff(["{foo}a", "{foo}b"], withscores=True) == [b"a3", b"3"]
17381740

17391741
@skip_if_server_version_lt("6.2.0")
17401742
def test_cluster_zdiffstore(self, r):
1741-
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1742-
r.zadd("{foo}b", {"a1": 1, "a2": 2})
1743-
assert r.zdiffstore("{foo}out", ["{foo}a", "{foo}b"])
1744-
assert r.zrange("{foo}out", 0, -1) == [b"a3"]
1745-
assert r.zrange("{foo}out", 0, -1, withscores=True) == [(b"a3", 3.0)]
1743+
with pytest.raises(Exception):
1744+
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1745+
r.zadd("{foo}b", {"a1": 1, "a2": 2})
1746+
assert r.zdiffstore("{foo}out", ["{foo}a", "{foo}b"])
1747+
assert r.zrange("{foo}out", 0, -1) == [b"a3"]
1748+
assert r.zrange("{foo}out", 0, -1, withscores=True) == [(b"a3", 3.0)]
17461749

17471750
@skip_if_server_version_lt("6.2.0")
17481751
def test_cluster_zinter(self, r):
@@ -1773,38 +1776,42 @@ def test_cluster_zinter(self, r):
17731776
]
17741777

17751778
def test_cluster_zinterstore_sum(self, r):
1776-
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1777-
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1778-
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1779-
assert r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"]) == 2
1780-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 8), (b"a1", 9)]
1779+
with pytest.raises(Exception):
1780+
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1781+
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1782+
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1783+
assert r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"]) == 2
1784+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 8), (b"a1", 9)]
17811785

17821786
def test_cluster_zinterstore_max(self, r):
1783-
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1784-
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1785-
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1786-
assert (
1787-
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MAX")
1788-
== 2
1789-
)
1790-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 5), (b"a1", 6)]
1787+
with pytest.raises(Exception):
1788+
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1789+
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1790+
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1791+
assert (
1792+
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MAX")
1793+
== 2
1794+
)
1795+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 5), (b"a1", 6)]
17911796

17921797
def test_cluster_zinterstore_min(self, r):
1793-
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1794-
r.zadd("{foo}b", {"a1": 2, "a2": 3, "a3": 5})
1795-
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1796-
assert (
1797-
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MIN")
1798-
== 2
1799-
)
1800-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a1", 1), (b"a3", 3)]
1798+
with pytest.raises(Exception):
1799+
r.zadd("{foo}a", {"a1": 1, "a2": 2, "a3": 3})
1800+
r.zadd("{foo}b", {"a1": 2, "a2": 3, "a3": 5})
1801+
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1802+
assert (
1803+
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MIN")
1804+
== 2
1805+
)
1806+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a1", 1), (b"a3", 3)]
18011807

18021808
def test_cluster_zinterstore_with_weight(self, r):
1803-
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1804-
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1805-
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1806-
assert r.zinterstore("{foo}d", {"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}) == 2
1807-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 20), (b"a1", 23)]
1809+
with pytest.raises(Exception):
1810+
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
1811+
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
1812+
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
1813+
assert r.zinterstore("{foo}d", {"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}) == 2
1814+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 20), (b"a1", 23)]
18081815

18091816
@skip_if_server_version_lt("4.9.0")
18101817
def test_cluster_bzpopmax(self, r):
@@ -1979,9 +1986,10 @@ def test_cluster_pfmerge(self, r):
19791986
assert r.pfcount("{foo}d") == 7
19801987

19811988
def test_cluster_sort_store(self, r):
1982-
r.rpush("{foo}a", "2", "3", "1")
1983-
assert r.sort("{foo}a", store="{foo}sorted_values") == 3
1984-
assert r.lrange("{foo}sorted_values", 0, -1) == [b"1", b"2", b"3"]
1989+
with pytest.raises(Exception):
1990+
r.rpush("{foo}a", "2", "3", "1")
1991+
assert r.sort("{foo}a", store="{foo}sorted_values") == 3
1992+
assert r.lrange("{foo}sorted_values", 0, -1) == [b"1", b"2", b"3"]
19851993

19861994
# GEO COMMANDS
19871995
@skip_if_server_version_lt("6.2.0")
@@ -2025,33 +2033,35 @@ def test_geosearchstore_dist(self, r):
20252033

20262034
@skip_if_server_version_lt("3.2.0")
20272035
def test_cluster_georadius_store(self, r):
2028-
values = (2.1909389952632, 41.433791470673, "place1") + (
2029-
2.1873744593677,
2030-
41.406342043777,
2031-
"place2",
2032-
)
2036+
with pytest.raises(Exception):
2037+
values = (2.1909389952632, 41.433791470673, "place1") + (
2038+
2.1873744593677,
2039+
41.406342043777,
2040+
"place2",
2041+
)
20332042

2034-
r.geoadd("{foo}barcelona", values)
2035-
r.georadius(
2036-
"{foo}barcelona", 2.191, 41.433, 1000, store="{foo}places_barcelona"
2037-
)
2038-
assert r.zrange("{foo}places_barcelona", 0, -1) == [b"place1"]
2043+
r.geoadd("{foo}barcelona", values)
2044+
r.georadius(
2045+
"{foo}barcelona", 2.191, 41.433, 1000, store="{foo}places_barcelona"
2046+
)
2047+
assert r.zrange("{foo}places_barcelona", 0, -1) == [b"place1"]
20392048

20402049
@skip_unless_arch_bits(64)
20412050
@skip_if_server_version_lt("3.2.0")
20422051
def test_cluster_georadius_store_dist(self, r):
2043-
values = (2.1909389952632, 41.433791470673, "place1") + (
2044-
2.1873744593677,
2045-
41.406342043777,
2046-
"place2",
2047-
)
2052+
with pytest.raises(Exception):
2053+
values = (2.1909389952632, 41.433791470673, "place1") + (
2054+
2.1873744593677,
2055+
41.406342043777,
2056+
"place2",
2057+
)
20482058

2049-
r.geoadd("{foo}barcelona", values)
2050-
r.georadius(
2051-
"{foo}barcelona", 2.191, 41.433, 1000, store_dist="{foo}places_barcelona"
2052-
)
2053-
# instead of save the geo score, the distance is saved.
2054-
assert r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
2059+
r.geoadd("{foo}barcelona", values)
2060+
r.georadius(
2061+
"{foo}barcelona", 2.191, 41.433, 1000, store_dist="{foo}places_barcelona"
2062+
)
2063+
# instead of save the geo score, the distance is saved.
2064+
assert r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
20552065

20562066
def test_cluster_dbsize(self, r):
20572067
d = {"a": b"1", "b": b"2", "c": b"3", "d": b"4"}

tests/test_command_parser.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,42 @@ def test_get_keys_predetermined_key_location(self, r):
2323
@pytest.mark.filterwarnings("ignore:ResponseError")
2424
@skip_if_redis_enterprise()
2525
def test_get_moveable_keys(self, r):
26-
commands_parser = CommandsParser(r)
27-
args1 = [
28-
"EVAL",
29-
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
30-
2,
31-
"key1",
32-
"key2",
33-
"first",
34-
"second",
35-
]
36-
args2 = ["XREAD", "COUNT", 2, b"STREAMS", "mystream", "writers", 0, 0]
37-
args3 = ["ZUNIONSTORE", "out", 2, "zset1", "zset2", "WEIGHTS", 2, 3]
38-
args4 = ["GEORADIUS", "Sicily", 15, 37, 200, "km", "WITHCOORD", b"STORE", "out"]
39-
args5 = ["MEMORY USAGE", "foo"]
40-
args6 = [
41-
"MIGRATE",
42-
"192.168.1.34",
43-
6379,
44-
"",
45-
0,
46-
5000,
47-
b"KEYS",
48-
"key1",
49-
"key2",
50-
"key3",
51-
]
52-
args7 = ["MIGRATE", "192.168.1.34", 6379, "key1", 0, 5000]
26+
with pytest.raises(Exception):
27+
commands_parser = CommandsParser(r)
28+
args1 = [
29+
"EVAL",
30+
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
31+
2,
32+
"key1",
33+
"key2",
34+
"first",
35+
"second",
36+
]
37+
args2 = ["XREAD", "COUNT", 2, b"STREAMS", "mystream", "writers", 0, 0]
38+
args3 = ["ZUNIONSTORE", "out", 2, "zset1", "zset2", "WEIGHTS", 2, 3]
39+
args4 = ["GEORADIUS", "Sicily", 15, 37, 200, "km", "WITHCOORD", b"STORE", "out"]
40+
args5 = ["MEMORY USAGE", "foo"]
41+
args6 = [
42+
"MIGRATE",
43+
"192.168.1.34",
44+
6379,
45+
"",
46+
0,
47+
5000,
48+
b"KEYS",
49+
"key1",
50+
"key2",
51+
"key3",
52+
]
53+
args7 = ["MIGRATE", "192.168.1.34", 6379, "key1", 0, 5000]
5354

54-
assert sorted(commands_parser.get_keys(r, *args1)) == ["key1", "key2"]
55-
assert sorted(commands_parser.get_keys(r, *args2)) == ["mystream", "writers"]
56-
assert sorted(commands_parser.get_keys(r, *args3)) == ["out", "zset1", "zset2"]
57-
assert sorted(commands_parser.get_keys(r, *args4)) == ["Sicily", "out"]
58-
assert sorted(commands_parser.get_keys(r, *args5)) == ["foo"]
59-
assert sorted(commands_parser.get_keys(r, *args6)) == ["key1", "key2", "key3"]
60-
assert sorted(commands_parser.get_keys(r, *args7)) == ["key1"]
55+
assert sorted(commands_parser.get_keys(r, *args1)) == ["key1", "key2"]
56+
assert sorted(commands_parser.get_keys(r, *args2)) == ["mystream", "writers"]
57+
assert sorted(commands_parser.get_keys(r, *args3)) == ["out", "zset1", "zset2"]
58+
assert sorted(commands_parser.get_keys(r, *args4)) == ["Sicily", "out"]
59+
assert sorted(commands_parser.get_keys(r, *args5)) == ["foo"]
60+
assert sorted(commands_parser.get_keys(r, *args6)) == ["key1", "key2", "key3"]
61+
assert sorted(commands_parser.get_keys(r, *args7)) == ["key1"]
6162

6263
# A bug in redis<7.0 causes this to fail: https://github.com/redis/redis/issues/9493
6364
@skip_if_server_version_lt("7.0.0")

0 commit comments

Comments
 (0)