From 9ec73e8dab9428ca45a33b96e5b5c3bbbe1a8605 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Wed, 16 Mar 2022 13:28:55 +0200 Subject: [PATCH 1/2] mark tests for redis-stack --- tests/test_bloom.py | 9 ++++ tests/test_commands.py | 112 ++++++++++++++++++++-------------------- tests/test_scripting.py | 24 ++++----- tox.ini | 2 + 4 files changed, 80 insertions(+), 67 deletions(-) diff --git a/tests/test_bloom.py b/tests/test_bloom.py index a3e9e158f4..ff2d1d4a17 100644 --- a/tests/test_bloom.py +++ b/tests/test_bloom.py @@ -34,6 +34,10 @@ def test_create(client): assert client.cms().initbydim("cmsDim", 100, 5) assert client.cms().initbyprob("cmsProb", 0.01, 0.01) assert client.topk().reserve("topk", 5, 100, 5, 0.9) + +@pytest.mark.redismod +@pytest.mark.experimental +def test_tdigest_create(client): assert client.tdigest().create("tDigest", 100) @@ -306,6 +310,7 @@ def test_topk_incrby(client): # region Test T-Digest @pytest.mark.redismod +@pytest.mark.experimental def test_tdigest_reset(client): assert client.tdigest().create("tDigest", 10) # reset on empty histogram @@ -319,6 +324,7 @@ def test_tdigest_reset(client): @pytest.mark.redismod +@pytest.mark.experimental def test_tdigest_merge(client): assert client.tdigest().create("to-tDigest", 10) assert client.tdigest().create("from-tDigest", 10) @@ -334,6 +340,7 @@ def test_tdigest_merge(client): @pytest.mark.redismod +@pytest.mark.experimental def test_tdigest_min_and_max(client): assert client.tdigest().create("tDigest", 100) # insert data-points into sketch @@ -344,6 +351,7 @@ def test_tdigest_min_and_max(client): @pytest.mark.redismod +@pytest.mark.experimental def test_tdigest_quantile(client): assert client.tdigest().create("tDigest", 500) # insert data-points into sketch @@ -359,6 +367,7 @@ def test_tdigest_quantile(client): @pytest.mark.redismod +@pytest.mark.experimental def test_tdigest_cdf(client): assert client.tdigest().create("tDigest", 100) # insert data-points into sketch diff --git a/tests/test_commands.py b/tests/test_commands.py index a73541ef10..6447e09685 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -626,11 +626,11 @@ def test_client_unpause(self, r): assert r.client_unpause() == b"OK" @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_client_no_evict(self, unstable_r): - assert unstable_r.client_no_evict("ON") == "OK" + @skip_if_server_version_lt("7.0.0") + def test_client_no_evict(self, r): + assert r.client_no_evict("ON") == "OK" with pytest.raises(TypeError): - unstable_r.client_no_evict() + r.client_no_evict() @pytest.mark.onlynoncluster @skip_if_server_version_lt("3.2.0") @@ -998,15 +998,15 @@ def test_unlink_with_multiple_keys(self, r): assert r.get("b") is None @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_lcs(self, unstable_r): - unstable_r.mset({"foo": "ohmytext", "bar": "mynewtext"}) - assert unstable_r.lcs("foo", "bar") == "mytext" - assert unstable_r.lcs("foo", "bar", len=True) == 6 + @skip_if_server_version_lt("7.0.0") + def test_lcs(self, r): + r.mset({"foo": "ohmytext", "bar": "mynewtext"}) + assert r.lcs("foo", "bar") == "mytext" + assert r.lcs("foo", "bar", len=True) == 6 result = ["matches", [[[4, 7], [5, 8]]], "len", 6] - assert unstable_r.lcs("foo", "bar", idx=True, minmatchlen=3) == result + assert r.lcs("foo", "bar", idx=True, minmatchlen=3) == result with pytest.raises(redis.ResponseError): - assert unstable_r.lcs("foo", "bar", len=True, idx=True) + assert r.lcs("foo", "bar", len=True, idx=True) @skip_if_server_version_lt("2.6.0") def test_dump_and_restore(self, r): @@ -1547,27 +1547,27 @@ def test_brpoplpush_empty_string(self, r): assert r.brpoplpush("a", "b") == b"" @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_blmpop(self, unstable_r): - unstable_r.rpush("a", "1", "2", "3", "4", "5") + @skip_if_server_version_lt("7.0.0") + def test_blmpop(self, r): + r.rpush("a", "1", "2", "3", "4", "5") res = ["a", ["1", "2"]] - assert unstable_r.blmpop(1, "2", "b", "a", direction="LEFT", count=2) == res + assert r.blmpop(1, "2", "b", "a", direction="LEFT", count=2) == res with pytest.raises(TypeError): - unstable_r.blmpop(1, "2", "b", "a", count=2) - unstable_r.rpush("b", "6", "7", "8", "9") - assert unstable_r.blmpop(0, "2", "b", "a", direction="LEFT") == ["b", ["6"]] - assert unstable_r.blmpop(1, "2", "foo", "bar", direction="RIGHT") is None + r.blmpop(1, "2", "b", "a", count=2) + r.rpush("b", "6", "7", "8", "9") + assert r.blmpop(0, "2", "b", "a", direction="LEFT") == ["b", ["6"]] + assert r.blmpop(1, "2", "foo", "bar", direction="RIGHT") is None @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_lmpop(self, unstable_r): - unstable_r.rpush("foo", "1", "2", "3", "4", "5") + @skip_if_server_version_lt("7.0.0") + def test_lmpop(self, r): + r.rpush("foo", "1", "2", "3", "4", "5") result = ["foo", ["1", "2"]] - assert unstable_r.lmpop("2", "bar", "foo", direction="LEFT", count=2) == result + assert r.lmpop("2", "bar", "foo", direction="LEFT", count=2) == result with pytest.raises(redis.ResponseError): - unstable_r.lmpop("2", "bar", "foo", direction="up", count=2) - unstable_r.rpush("bar", "a", "b", "c", "d") - assert unstable_r.lmpop("2", "bar", "foo", direction="LEFT") == ["bar", ["a"]] + r.lmpop("2", "bar", "foo", direction="up", count=2) + r.rpush("bar", "a", "b", "c", "d") + assert r.lmpop("2", "bar", "foo", direction="LEFT") == ["bar", ["a"]] def test_lindex(self, r): r.rpush("a", "1", "2", "3") @@ -1838,13 +1838,13 @@ def test_sinter(self, r): assert r.sinter("a", "b") == {b"2", b"3"} @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_sintercard(self, unstable_r): - unstable_r.sadd("a", 1, 2, 3) - unstable_r.sadd("b", 1, 2, 3) - unstable_r.sadd("c", 1, 3, 4) - assert unstable_r.sintercard(3, ["a", "b", "c"]) == 2 - assert unstable_r.sintercard(3, ["a", "b", "c"], limit=1) == 1 + @skip_if_server_version_lt("7.0.0") + def test_sintercard(self, r): + r.sadd("a", 1, 2, 3) + r.sadd("b", 1, 2, 3) + r.sadd("c", 1, 3, 4) + assert r.sintercard(3, ["a", "b", "c"]) == 2 + assert r.sintercard(3, ["a", "b", "c"], limit=1) == 1 @pytest.mark.onlynoncluster def test_sinterstore(self, r): @@ -2078,13 +2078,13 @@ def test_zinter(self, r): ] @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_zintercard(self, unstable_r): - unstable_r.zadd("a", {"a1": 1, "a2": 2, "a3": 1}) - unstable_r.zadd("b", {"a1": 2, "a2": 2, "a3": 2}) - unstable_r.zadd("c", {"a1": 6, "a3": 5, "a4": 4}) - assert unstable_r.zintercard(3, ["a", "b", "c"]) == 2 - assert unstable_r.zintercard(3, ["a", "b", "c"], limit=1) == 1 + @skip_if_server_version_lt("7.0.0") + def test_zintercard(self, r): + r.zadd("a", {"a1": 1, "a2": 2, "a3": 1}) + r.zadd("b", {"a1": 2, "a2": 2, "a3": 2}) + r.zadd("c", {"a1": 6, "a3": 5, "a4": 4}) + assert r.zintercard(3, ["a", "b", "c"]) == 2 + assert r.zintercard(3, ["a", "b", "c"], limit=1) == 1 @pytest.mark.onlynoncluster def test_zinterstore_sum(self, r): @@ -2173,28 +2173,28 @@ def test_bzpopmin(self, r): assert r.bzpopmin("c", timeout=1) == (b"c", b"c1", 100) @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_zmpop(self, unstable_r): - unstable_r.zadd("a", {"a1": 1, "a2": 2, "a3": 3}) + @skip_if_server_version_lt("7.0.0") + def test_zmpop(self, r): + r.zadd("a", {"a1": 1, "a2": 2, "a3": 3}) res = ["a", [["a1", "1"], ["a2", "2"]]] - assert unstable_r.zmpop("2", ["b", "a"], min=True, count=2) == res + assert r.zmpop("2", ["b", "a"], min=True, count=2) == res with pytest.raises(redis.DataError): - unstable_r.zmpop("2", ["b", "a"], count=2) - unstable_r.zadd("b", {"b1": 10, "ab": 9, "b3": 8}) - assert unstable_r.zmpop("2", ["b", "a"], max=True) == ["b", [["b1", "10"]]] + r.zmpop("2", ["b", "a"], count=2) + r.zadd("b", {"b1": 10, "ab": 9, "b3": 8}) + assert r.zmpop("2", ["b", "a"], max=True) == ["b", [["b1", "10"]]] @pytest.mark.onlynoncluster - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release - def test_bzmpop(self, unstable_r): - unstable_r.zadd("a", {"a1": 1, "a2": 2, "a3": 3}) + @skip_if_server_version_lt("7.0.0") + def test_bzmpop(self, r): + r.zadd("a", {"a1": 1, "a2": 2, "a3": 3}) res = ["a", [["a1", "1"], ["a2", "2"]]] - assert unstable_r.bzmpop(1, "2", ["b", "a"], min=True, count=2) == res + assert r.bzmpop(1, "2", ["b", "a"], min=True, count=2) == res with pytest.raises(redis.DataError): - unstable_r.bzmpop(1, "2", ["b", "a"], count=2) - unstable_r.zadd("b", {"b1": 10, "ab": 9, "b3": 8}) + r.bzmpop(1, "2", ["b", "a"], count=2) + r.zadd("b", {"b1": 10, "ab": 9, "b3": 8}) res = ["b", [["b1", "10"]]] - assert unstable_r.bzmpop(0, "2", ["b", "a"], max=True) == res - assert unstable_r.bzmpop(1, "2", ["foo", "bar"], max=True) is None + assert r.bzmpop(0, "2", ["b", "a"], max=True) == res + assert r.bzmpop(1, "2", ["foo", "bar"], max=True) is None def test_zrange(self, r): r.zadd("a", {"a1": 1, "a2": 2, "a3": 3}) @@ -4347,12 +4347,14 @@ def test_replicaof(self, r): assert r.replicaof("NO ONE") assert r.replicaof("NO", "ONE") + @pytest.mark.replica @skip_if_server_version_lt("2.8.0") def test_sync(self, r): r2 = redis.Redis(port=6380, decode_responses=False) res = r2.sync() assert b"REDIS" in res + @pytest.mark.replica @skip_if_server_version_lt("2.8.0") def test_psync(self, r): r2 = redis.Redis(port=6380, decode_responses=False) diff --git a/tests/test_scripting.py b/tests/test_scripting.py index 4635f9572d..8f6a24cdae 100644 --- a/tests/test_scripting.py +++ b/tests/test_scripting.py @@ -65,13 +65,13 @@ def test_eval_multiply(self, r): # 2 * 3 == 6 assert r.eval(multiply_script, 1, "a", 3) == 6 - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release + @skip_if_server_version_lt("7.0.0") @pytest.mark.onlynoncluster - def test_eval_ro(self, unstable_r): - unstable_r.set("a", "b") - assert unstable_r.eval_ro("return redis.call('GET', KEYS[1])", 1, "a") == "b" + def test_eval_ro(self, r): + r.set("a", "b") + assert r.eval_ro("return redis.call('GET', KEYS[1])", 1, "a") == "b" with pytest.raises(redis.ResponseError): - unstable_r.eval_ro("return redis.call('DEL', KEYS[1])", 1, "a") + r.eval_ro("return redis.call('DEL', KEYS[1])", 1, "a") def test_eval_msgpack(self, r): msgpack_message_dumped = b"\x81\xa4name\xa3Joe" @@ -154,15 +154,15 @@ def test_evalsha(self, r): # 2 * 3 == 6 assert r.evalsha(sha, 1, "a", 3) == 6 - # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release + @skip_if_server_version_lt("7.0.0") @pytest.mark.onlynoncluster - def test_evalsha_ro(self, unstable_r): - unstable_r.set("a", "b") - get_sha = unstable_r.script_load("return redis.call('GET', KEYS[1])") - del_sha = unstable_r.script_load("return redis.call('DEL', KEYS[1])") - assert unstable_r.evalsha_ro(get_sha, 1, "a") == "b" + def test_evalsha_ro(self, r): + r.set("a", "b") + get_sha = r.script_load("return redis.call('GET', KEYS[1])") + del_sha = r.script_load("return redis.call('DEL', KEYS[1])") + assert r.evalsha_ro(get_sha, 1, "a") == "b" with pytest.raises(redis.ResponseError): - unstable_r.evalsha_ro(del_sha, 1, "a") + r.evalsha_ro(del_sha, 1, "a") def test_evalsha_script_not_loaded(self, r): r.set("a", 2) diff --git a/tox.ini b/tox.ini index e9174a66c5..1a3450bdaa 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,8 @@ markers = onlycluster: marks tests to be run only with cluster mode redis onlynoncluster: marks tests to be run only with standalone redis ssl: marker for only the ssl tests + replica: replica tests + experimental: run only experimental tests [tox] minversion = 3.2.0 From a73fb9e00c3e6fcce92fa482a6b9b5f9dc173ad7 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Wed, 16 Mar 2022 13:36:59 +0200 Subject: [PATCH 2/2] linters --- tests/test_bloom.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_bloom.py b/tests/test_bloom.py index ff2d1d4a17..4c6779bbd0 100644 --- a/tests/test_bloom.py +++ b/tests/test_bloom.py @@ -35,6 +35,7 @@ def test_create(client): assert client.cms().initbyprob("cmsProb", 0.01, 0.01) assert client.topk().reserve("topk", 5, 100, 5, 0.9) + @pytest.mark.redismod @pytest.mark.experimental def test_tdigest_create(client):