Skip to content

Commit e07bd94

Browse files
authored
Response parsing occasionally fails to parse floats (#1692)
1 parent 939fead commit e07bd94

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

redis/commands/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def parse_to_list(response):
4242
try:
4343
res.append(int(item))
4444
except ValueError:
45-
res.append(nativestr(item))
45+
try:
46+
res.append(float(item))
47+
except ValueError:
48+
res.append(nativestr(item))
4649
except TypeError:
4750
res.append(None)
4851
return res

tests/test_helpers.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import string
2+
from redis.commands.helpers import (
3+
delist,
4+
list_or_args,
5+
nativestr,
6+
parse_to_list,
7+
quote_string,
8+
random_string
9+
)
10+
11+
12+
def test_list_or_args():
13+
k = ["hello, world"]
14+
a = ["some", "argument", "list"]
15+
assert list_or_args(k, a) == k+a
16+
17+
for i in ["banana", b"banana"]:
18+
assert list_or_args(i, a) == [i] + a
19+
20+
21+
def test_parse_to_list():
22+
r = ["hello", b"my name", "45", "555.55", "is simon!", None]
23+
assert parse_to_list(r) == \
24+
["hello", "my name", 45, 555.55, "is simon!", None]
25+
26+
27+
def test_nativestr():
28+
assert nativestr('teststr') == 'teststr'
29+
assert nativestr(b'teststr') == 'teststr'
30+
assert nativestr('null') is None
31+
32+
33+
def test_delist():
34+
assert delist(None) is None
35+
assert delist([b'hello', 'world', b'banana']) == \
36+
['hello', 'world', 'banana']
37+
38+
39+
def test_random_string():
40+
assert len(random_string()) == 10
41+
assert len(random_string(15)) == 15
42+
for a in random_string():
43+
assert a in string.ascii_lowercase
44+
45+
46+
def test_quote_string():
47+
assert quote_string("hello world!") == '"hello world!"'
48+
assert quote_string('') == '""'
49+
assert quote_string('hello world!') == '"hello world!"'

0 commit comments

Comments
 (0)