From 848f32f065d09a7b3af589af3f3eaec752b95ded Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 3 Jun 2024 11:27:35 +0800 Subject: [PATCH] Add missing assert in json tests I found some statements missing assert. --- tests/test_asyncio/test_json.py | 23 +++++++++--------- tests/test_json.py | 43 +++++++++++++++++---------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/tests/test_asyncio/test_json.py b/tests/test_asyncio/test_json.py index 920ec71dce..889db8c8e0 100644 --- a/tests/test_asyncio/test_json.py +++ b/tests/test_asyncio/test_json.py @@ -90,7 +90,7 @@ async def test_jsonsetexistentialmodifiersshouldsucceed(decoded_r: redis.Redis): assert await decoded_r.json().set("obj", Path("foo"), "baz", xx=True) assert await decoded_r.json().set("obj", Path("qaz"), "baz", nx=True) - # Test that flags are mutually exlusive + # Test that flags are mutually exclusive with pytest.raises(Exception): await decoded_r.json().set("obj", Path("foo"), "baz", nx=True, xx=True) @@ -449,7 +449,7 @@ async def test_json_mget_dollar(decoded_r: redis.Redis): ) # Test mget with single path - await decoded_r.json().mget("doc1", "$..a") == [1, 3, None] + assert await decoded_r.json().mget(["doc1"], "$..a") == [[1, 3, None]] # Test mget with multi path res = await decoded_r.json().mget(["doc1", "doc2"], "$..a") assert res == [[1, 3, None], [4, 6, [None]]] @@ -504,7 +504,7 @@ async def test_numby_commands_dollar(decoded_r: redis.Redis): await decoded_r.json().set( "doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]} ) - await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5 + assert await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5 # Test legacy NUMMULTBY await decoded_r.json().set( @@ -512,7 +512,7 @@ async def test_numby_commands_dollar(decoded_r: redis.Redis): ) with pytest.deprecated_call(): - await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6 + assert await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6 async def test_strappend_dollar(decoded_r: redis.Redis): @@ -520,13 +520,13 @@ async def test_strappend_dollar(decoded_r: redis.Redis): "doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}} ) # Test multi - await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None] + assert await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None] res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}] assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res]) # Test single - await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11] + assert await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11] res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}] assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res]) @@ -536,7 +536,7 @@ async def test_strappend_dollar(decoded_r: redis.Redis): await decoded_r.json().strappend("non_existing_doc", "$..a", "err") # Test multi - await decoded_r.json().strappend("doc1", "bar", ".*.a") == 8 + assert await decoded_r.json().strappend("doc1", "bar", ".*.a") == 14 res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}] assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res]) @@ -557,8 +557,8 @@ async def test_strlen_dollar(decoded_r: redis.Redis): assert res1 == res2 # Test single - await decoded_r.json().strlen("doc1", "$.nested1.a") == [8] - await decoded_r.json().strlen("doc1", "$.nested2.a") == [None] + assert await decoded_r.json().strlen("doc1", "$.nested1.a") == [8] + assert await decoded_r.json().strlen("doc1", "$.nested2.a") == [None] # Test missing key with pytest.raises(exceptions.ResponseError): @@ -576,7 +576,8 @@ async def test_arrappend_dollar(decoded_r: redis.Redis): }, ) # Test multi - await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None] + res = [3, 5, None] + assert await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == res res = [ { "a": ["foo", "bar", "racuda"], @@ -753,7 +754,7 @@ async def test_arrpop_dollar(decoded_r: redis.Redis): }, ) # Test multi (all paths are updated, but return result of last path) - await decoded_r.json().arrpop("doc1", "..a", "1") is None + assert await decoded_r.json().arrpop("doc1", "..a", "1") == "null" res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}] assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res]) diff --git a/tests/test_json.py b/tests/test_json.py index 73d72b8cc9..b5e2c18b2d 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -97,7 +97,7 @@ def test_jsonsetexistentialmodifiersshouldsucceed(client): assert client.json().set("obj", Path("foo"), "baz", xx=True) assert client.json().set("obj", Path("qaz"), "baz", nx=True) - # Test that flags are mutually exlusive + # Test that flags are mutually exclusive with pytest.raises(Exception): client.json().set("obj", Path("foo"), "baz", nx=True, xx=True) @@ -434,6 +434,7 @@ def test_json_forget_with_dollar(client): client.json().forget("not_a_document", "..a") +@pytest.mark.onlynoncluster def test_json_mget_dollar(client): # Test mget with multi paths client.json().set( @@ -453,14 +454,14 @@ def test_json_mget_dollar(client): assert_resp_response(client, client.json().get("doc2", "$..a"), res, [res]) # Test mget with single path - client.json().mget("doc1", "$..a") == [1, 3, None] + assert client.json().mget(["doc1"], "$..a") == [[1, 3, None]] # Test mget with multi path - client.json().mget(["doc1", "doc2"], "$..a") == [[1, 3, None], [4, 6, [None]]] + res = [[1, 3, None], [4, 6, [None]]] + assert client.json().mget(["doc1", "doc2"], "$..a") == res # Test missing key - client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None] - res = client.json().mget(["missing_doc1", "missing_doc2"], "$..a") - assert res == [None, None] + assert client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None] + assert client.json().mget(["missing_doc1", "missing_doc2"], "$..a") == [None, None] def test_numby_commands_dollar(client): @@ -497,13 +498,13 @@ def test_numby_commands_dollar(client): # Test legacy NUMINCRBY client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}) - client.json().numincrby("doc1", ".b[0].a", 3) == 5 + assert client.json().numincrby("doc1", ".b[0].a", 3) == 5 # Test legacy NUMMULTBY client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}) with pytest.deprecated_call(): - client.json().nummultby("doc1", ".b[0].a", 3) == 6 + assert client.json().nummultby("doc1", ".b[0].a", 3) == 6 def test_strappend_dollar(client): @@ -511,25 +512,25 @@ def test_strappend_dollar(client): "doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}} ) # Test multi - client.json().strappend("doc1", "bar", "$..a") == [6, 8, None] + assert client.json().strappend("doc1", "bar", "$..a") == [6, 8, None] - # res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}] - # assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) + res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}] + assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) # Test single - client.json().strappend("doc1", "baz", "$.nested1.a") == [11] + assert client.json().strappend("doc1", "baz", "$.nested1.a") == [11] - # res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}] - # assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) + res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}] + assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) # Test missing key with pytest.raises(exceptions.ResponseError): client.json().strappend("non_existing_doc", "$..a", "err") # Test multi - client.json().strappend("doc1", "bar", ".*.a") == 8 - # res = [{"a": "foo", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}] - # assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) + assert client.json().strappend("doc1", "bar", ".*.a") == 14 + res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}] + assert_resp_response(client, client.json().get("doc1", "$"), res, [res]) # Test missing path with pytest.raises(exceptions.ResponseError): @@ -548,8 +549,8 @@ def test_strlen_dollar(client): assert res1 == res2 # Test single - client.json().strlen("doc1", "$.nested1.a") == [8] - client.json().strlen("doc1", "$.nested2.a") == [None] + assert client.json().strlen("doc1", "$.nested1.a") == [8] + assert client.json().strlen("doc1", "$.nested2.a") == [None] # Test missing key with pytest.raises(exceptions.ResponseError): @@ -567,7 +568,7 @@ def test_arrappend_dollar(client): }, ) # Test multi - client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None] + assert client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None] res = [ { "a": ["foo", "bar", "racuda"], @@ -748,7 +749,7 @@ def test_arrpop_dollar(client): }, ) # Test multi (all paths are updated, but return result of last path) - client.json().arrpop("doc1", "..a", "1") is None + assert client.json().arrpop("doc1", "..a", "1") == "null" res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}] assert_resp_response(client, client.json().get("doc1", "$"), res, [res])