summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-11-10 15:09:09 +0200
committerGitHub <noreply@github.com>2021-11-10 15:09:09 +0200
commite07bd9464d6ce226e3db9a5eaf95bc2ecfe8e034 (patch)
tree1bfe0071f4da21893bec18fe98208f175d8122e9
parent939fead8d375cdc90c205ebd81b26d986d6d0dc3 (diff)
downloadredis-py-e07bd9464d6ce226e3db9a5eaf95bc2ecfe8e034.tar.gz
Response parsing occasionally fails to parse floats (#1692)
-rw-r--r--redis/commands/helpers.py5
-rw-r--r--tests/test_helpers.py49
2 files changed, 53 insertions, 1 deletions
diff --git a/redis/commands/helpers.py b/redis/commands/helpers.py
index 22cb622..46eb83d 100644
--- a/redis/commands/helpers.py
+++ b/redis/commands/helpers.py
@@ -42,7 +42,10 @@ def parse_to_list(response):
try:
res.append(int(item))
except ValueError:
- res.append(nativestr(item))
+ try:
+ res.append(float(item))
+ except ValueError:
+ res.append(nativestr(item))
except TypeError:
res.append(None)
return res
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
new file mode 100644
index 0000000..467e00c
--- /dev/null
+++ b/tests/test_helpers.py
@@ -0,0 +1,49 @@
+import string
+from redis.commands.helpers import (
+ delist,
+ list_or_args,
+ nativestr,
+ parse_to_list,
+ quote_string,
+ random_string
+)
+
+
+def test_list_or_args():
+ k = ["hello, world"]
+ a = ["some", "argument", "list"]
+ assert list_or_args(k, a) == k+a
+
+ for i in ["banana", b"banana"]:
+ assert list_or_args(i, a) == [i] + a
+
+
+def test_parse_to_list():
+ r = ["hello", b"my name", "45", "555.55", "is simon!", None]
+ assert parse_to_list(r) == \
+ ["hello", "my name", 45, 555.55, "is simon!", None]
+
+
+def test_nativestr():
+ assert nativestr('teststr') == 'teststr'
+ assert nativestr(b'teststr') == 'teststr'
+ assert nativestr('null') is None
+
+
+def test_delist():
+ assert delist(None) is None
+ assert delist([b'hello', 'world', b'banana']) == \
+ ['hello', 'world', 'banana']
+
+
+def test_random_string():
+ assert len(random_string()) == 10
+ assert len(random_string(15)) == 15
+ for a in random_string():
+ assert a in string.ascii_lowercase
+
+
+def test_quote_string():
+ assert quote_string("hello world!") == '"hello world!"'
+ assert quote_string('') == '""'
+ assert quote_string('hello world!') == '"hello world!"'