Skip to content

Commit 2d7ceb0

Browse files
authored
Test to validate custom JSON decoders (redis#1681)
1 parent f5160f5 commit 2d7ceb0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

dev_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ tox-docker==3.1.0
66
invoke==1.6.0
77
pytest-cov>=3.0.0
88
vulture>=2.3.0
9+
ujson>=4.2.0
910
wheel>=0.30.0

tests/test_json.py

+17
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ def test_debug_dollar(client):
10031003
assert client.json().debug("MEMORY", "non_existing_doc", "$..a") == []
10041004

10051005

1006+
@pytest.mark.redismod
10061007
def test_resp_dollar(client):
10071008

10081009
data = {
@@ -1149,6 +1150,7 @@ def test_resp_dollar(client):
11491150
assert client.json().resp("non_existing_doc", "$..a") is None
11501151

11511152

1153+
@pytest.mark.redismod
11521154
def test_arrindex_dollar(client):
11531155

11541156
client.json().set(
@@ -1397,3 +1399,18 @@ def test_decoders_and_unstring():
13971399
assert decode_list(b"45.55") == 45.55
13981400
assert decode_list("45.55") == 45.55
13991401
assert decode_list(['hello', b'world']) == ['hello', 'world']
1402+
1403+
1404+
@pytest.mark.redismod
1405+
def test_custom_decoder(client):
1406+
import ujson
1407+
import json
1408+
1409+
cj = client.json(encoder=ujson, decoder=ujson)
1410+
assert cj.set("foo", Path.rootPath(), "bar")
1411+
assert "bar" == cj.get("foo")
1412+
assert cj.get("baz") is None
1413+
assert 1 == cj.delete("foo")
1414+
assert client.exists("foo") == 0
1415+
assert not isinstance(cj.__encoder__, json.JSONEncoder)
1416+
assert not isinstance(cj.__decoder__, json.JSONDecoder)

0 commit comments

Comments
 (0)