Skip to content

Commit 69d9606

Browse files
authored
Add missing asserts in json tests (#3261)
Fix some some statements with missing asserts.
1 parent 93ae56a commit 69d9606

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

tests/test_asyncio/test_json.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def test_jsonsetexistentialmodifiersshouldsucceed(decoded_r: redis.Redis):
103103
assert await decoded_r.json().set("obj", Path("foo"), "baz", xx=True)
104104
assert await decoded_r.json().set("obj", Path("qaz"), "baz", nx=True)
105105

106-
# Test that flags are mutually exlusive
106+
# Test that flags are mutually exclusive
107107
with pytest.raises(Exception):
108108
await decoded_r.json().set("obj", Path("foo"), "baz", nx=True, xx=True)
109109

@@ -483,7 +483,7 @@ async def test_json_mget_dollar(decoded_r: redis.Redis):
483483
)
484484

485485
# Test mget with single path
486-
await decoded_r.json().mget("doc1", "$..a") == [1, 3, None]
486+
assert await decoded_r.json().mget(["doc1"], "$..a") == [[1, 3, None]]
487487
# Test mget with multi path
488488
res = await decoded_r.json().mget(["doc1", "doc2"], "$..a")
489489
assert res == [[1, 3, None], [4, 6, [None]]]
@@ -539,15 +539,15 @@ async def test_numby_commands_dollar(decoded_r: redis.Redis):
539539
await decoded_r.json().set(
540540
"doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}
541541
)
542-
await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5
542+
assert await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5
543543

544544
# Test legacy NUMMULTBY
545545
await decoded_r.json().set(
546546
"doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}
547547
)
548548

549549
with pytest.deprecated_call():
550-
await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6
550+
assert await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6
551551

552552

553553
@pytest.mark.redismod
@@ -556,13 +556,13 @@ async def test_strappend_dollar(decoded_r: redis.Redis):
556556
"doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}
557557
)
558558
# Test multi
559-
await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
559+
assert await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
560560

561561
res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
562562
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])
563563

564564
# Test single
565-
await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11]
565+
assert await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11]
566566

567567
res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
568568
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])
@@ -572,7 +572,7 @@ async def test_strappend_dollar(decoded_r: redis.Redis):
572572
await decoded_r.json().strappend("non_existing_doc", "$..a", "err")
573573

574574
# Test multi
575-
await decoded_r.json().strappend("doc1", "bar", ".*.a") == 8
575+
assert await decoded_r.json().strappend("doc1", "bar", ".*.a") == 14
576576
res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}]
577577
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])
578578

@@ -594,8 +594,8 @@ async def test_strlen_dollar(decoded_r: redis.Redis):
594594
assert res1 == res2
595595

596596
# Test single
597-
await decoded_r.json().strlen("doc1", "$.nested1.a") == [8]
598-
await decoded_r.json().strlen("doc1", "$.nested2.a") == [None]
597+
assert await decoded_r.json().strlen("doc1", "$.nested1.a") == [8]
598+
assert await decoded_r.json().strlen("doc1", "$.nested2.a") == [None]
599599

600600
# Test missing key
601601
with pytest.raises(exceptions.ResponseError):
@@ -614,7 +614,8 @@ async def test_arrappend_dollar(decoded_r: redis.Redis):
614614
},
615615
)
616616
# Test multi
617-
await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
617+
res = [3, 5, None]
618+
assert await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == res
618619
res = [
619620
{
620621
"a": ["foo", "bar", "racuda"],
@@ -794,7 +795,7 @@ async def test_arrpop_dollar(decoded_r: redis.Redis):
794795
},
795796
)
796797
# Test multi (all paths are updated, but return result of last path)
797-
await decoded_r.json().arrpop("doc1", "..a", "1") is None
798+
assert await decoded_r.json().arrpop("doc1", "..a", "1") == "null"
798799
res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}]
799800
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])
800801

tests/test_json.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_jsonsetexistentialmodifiersshouldsucceed(client):
104104
assert client.json().set("obj", Path("foo"), "baz", xx=True)
105105
assert client.json().set("obj", Path("qaz"), "baz", nx=True)
106106

107-
# Test that flags are mutually exlusive
107+
# Test that flags are mutually exclusive
108108
with pytest.raises(Exception):
109109
client.json().set("obj", Path("foo"), "baz", nx=True, xx=True)
110110

@@ -453,6 +453,7 @@ def test_json_forget_with_dollar(client):
453453
client.json().forget("not_a_document", "..a")
454454

455455

456+
@pytest.mark.onlynoncluster
456457
@pytest.mark.redismod
457458
def test_json_mget_dollar(client):
458459
# Test mget with multi paths
@@ -473,14 +474,14 @@ def test_json_mget_dollar(client):
473474
assert_resp_response(client, client.json().get("doc2", "$..a"), res, [res])
474475

475476
# Test mget with single path
476-
client.json().mget("doc1", "$..a") == [1, 3, None]
477+
assert client.json().mget(["doc1"], "$..a") == [[1, 3, None]]
477478
# Test mget with multi path
478-
client.json().mget(["doc1", "doc2"], "$..a") == [[1, 3, None], [4, 6, [None]]]
479+
res = [[1, 3, None], [4, 6, [None]]]
480+
assert client.json().mget(["doc1", "doc2"], "$..a") == res
479481

480482
# Test missing key
481-
client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None]
482-
res = client.json().mget(["missing_doc1", "missing_doc2"], "$..a")
483-
assert res == [None, None]
483+
assert client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None]
484+
assert client.json().mget(["missing_doc1", "missing_doc2"], "$..a") == [None, None]
484485

485486

486487
@pytest.mark.redismod
@@ -518,13 +519,13 @@ def test_numby_commands_dollar(client):
518519

519520
# Test legacy NUMINCRBY
520521
client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]})
521-
client.json().numincrby("doc1", ".b[0].a", 3) == 5
522+
assert client.json().numincrby("doc1", ".b[0].a", 3) == 5
522523

523524
# Test legacy NUMMULTBY
524525
client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]})
525526

526527
with pytest.deprecated_call():
527-
client.json().nummultby("doc1", ".b[0].a", 3) == 6
528+
assert client.json().nummultby("doc1", ".b[0].a", 3) == 6
528529

529530

530531
@pytest.mark.redismod
@@ -533,25 +534,25 @@ def test_strappend_dollar(client):
533534
"doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}
534535
)
535536
# Test multi
536-
client.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
537+
assert client.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
537538

538-
# res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
539-
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
539+
res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
540+
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
540541

541542
# Test single
542-
client.json().strappend("doc1", "baz", "$.nested1.a") == [11]
543+
assert client.json().strappend("doc1", "baz", "$.nested1.a") == [11]
543544

544-
# res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
545-
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
545+
res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
546+
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
546547

547548
# Test missing key
548549
with pytest.raises(exceptions.ResponseError):
549550
client.json().strappend("non_existing_doc", "$..a", "err")
550551

551552
# Test multi
552-
client.json().strappend("doc1", "bar", ".*.a") == 8
553-
# res = [{"a": "foo", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
554-
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
553+
assert client.json().strappend("doc1", "bar", ".*.a") == 14
554+
res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}]
555+
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
555556

556557
# Test missing path
557558
with pytest.raises(exceptions.ResponseError):
@@ -571,8 +572,8 @@ def test_strlen_dollar(client):
571572
assert res1 == res2
572573

573574
# Test single
574-
client.json().strlen("doc1", "$.nested1.a") == [8]
575-
client.json().strlen("doc1", "$.nested2.a") == [None]
575+
assert client.json().strlen("doc1", "$.nested1.a") == [8]
576+
assert client.json().strlen("doc1", "$.nested2.a") == [None]
576577

577578
# Test missing key
578579
with pytest.raises(exceptions.ResponseError):
@@ -591,7 +592,7 @@ def test_arrappend_dollar(client):
591592
},
592593
)
593594
# Test multi
594-
client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
595+
assert client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
595596
res = [
596597
{
597598
"a": ["foo", "bar", "racuda"],
@@ -775,7 +776,7 @@ def test_arrpop_dollar(client):
775776
},
776777
)
777778
# Test multi (all paths are updated, but return result of last path)
778-
client.json().arrpop("doc1", "..a", "1") is None
779+
assert client.json().arrpop("doc1", "..a", "1") == "null"
779780
res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}]
780781
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
781782

0 commit comments

Comments
 (0)