Skip to content

Commit

Permalink
Test to validate custom JSON decoders (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored Nov 10, 2021
1 parent f5160f5 commit 2d7ceb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

0 comments on commit 2d7ceb0

Please sign in to comment.