From 2d7ceb0b110212fe50b8fa296f99f32f9a622ea7 Mon Sep 17 00:00:00 2001 From: Chayim Date: Wed, 10 Nov 2021 10:35:45 +0200 Subject: Test to validate custom JSON decoders (#1681) --- dev_requirements.txt | 1 + tests/test_json.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/dev_requirements.txt b/dev_requirements.txt index 6ea5055..7f099cb 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -6,4 +6,5 @@ tox-docker==3.1.0 invoke==1.6.0 pytest-cov>=3.0.0 vulture>=2.3.0 +ujson>=4.2.0 wheel>=0.30.0 diff --git a/tests/test_json.py b/tests/test_json.py index b3f38f7..abc5776 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -1003,6 +1003,7 @@ def test_debug_dollar(client): assert client.json().debug("MEMORY", "non_existing_doc", "$..a") == [] +@pytest.mark.redismod def test_resp_dollar(client): data = { @@ -1149,6 +1150,7 @@ def test_resp_dollar(client): assert client.json().resp("non_existing_doc", "$..a") is None +@pytest.mark.redismod def test_arrindex_dollar(client): client.json().set( @@ -1397,3 +1399,18 @@ def test_decoders_and_unstring(): assert decode_list(b"45.55") == 45.55 assert decode_list("45.55") == 45.55 assert decode_list(['hello', b'world']) == ['hello', 'world'] + + +@pytest.mark.redismod +def test_custom_decoder(client): + import ujson + import json + + cj = client.json(encoder=ujson, decoder=ujson) + assert cj.set("foo", Path.rootPath(), "bar") + assert "bar" == cj.get("foo") + assert cj.get("baz") is None + assert 1 == cj.delete("foo") + assert client.exists("foo") == 0 + assert not isinstance(cj.__encoder__, json.JSONEncoder) + assert not isinstance(cj.__decoder__, json.JSONDecoder) -- cgit v1.2.1