Skip to content

Commit 566dffb

Browse files
increase coverage
1 parent 214caf3 commit 566dffb

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

redis/commands/helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def delist(x):
3737
def parse_to_list(response):
3838
"""Optimistically parse the response to a list."""
3939
res = []
40+
41+
if response is None:
42+
return res
43+
4044
for item in response:
4145
try:
4246
res.append(int(item))

redis/commands/search/commands.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,9 @@ def profile(self, query, limited=False):
450450
elif isinstance(query, Query):
451451
cmd[2] = "SEARCH"
452452
cmd += query.get_args()
453-
elif isinstance(query, str):
454-
cmd[2] = "SEARCH"
455-
cmd.append(query)
456453
else:
457-
raise ValueError("Must provide AggregateRequest object, "
458-
"Query object or str.")
454+
raise ValueError("Must provide AggregateRequest object or "
455+
"Query object.")
459456

460457
res = self.execute_command(*cmd)
461458

tests/test_helpers.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
nativestr,
66
parse_to_list,
77
quote_string,
8-
random_string
8+
random_string, parse_to_dict
99
)
1010

1111

@@ -19,11 +19,34 @@ def test_list_or_args():
1919

2020

2121
def test_parse_to_list():
22+
assert parse_to_list(None) == []
2223
r = ["hello", b"my name", "45", "555.55", "is simon!", None]
2324
assert parse_to_list(r) == \
2425
["hello", "my name", 45, 555.55, "is simon!", None]
2526

2627

28+
def test_parse_to_dict():
29+
assert parse_to_dict(None) == {}
30+
r = [['Some number', '1.0345'],
31+
['Some string', 'hello'],
32+
['Child iterators',
33+
['Time', '0.2089', 'Counter', 3, 'Child iterators',
34+
['Type', 'bar', 'Time', '0.0729', 'Counter', 3],
35+
['Type', 'barbar', 'Time', '0.058', 'Counter', 3]]]]
36+
assert parse_to_dict(r) == {
37+
'Child iterators': {
38+
'Child iterators': [
39+
{'Counter': 3.0, 'Time': 0.0729, 'Type': 'bar'},
40+
{'Counter': 3.0, 'Time': 0.058, 'Type': 'barbar'}
41+
],
42+
'Counter': 3.0,
43+
'Time': 0.2089
44+
},
45+
'Some number': 1.0345,
46+
'Some string': 'hello'
47+
}
48+
49+
2750
def test_nativestr():
2851
assert nativestr('teststr') == 'teststr'
2952
assert nativestr(b'teststr') == 'teststr'

tests/test_search.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,3 +1338,21 @@ def test_profile(client):
13381338
assert det['Iterators profile']['Type'] == 'WILDCARD'
13391339
assert det['Parsing time'] < 0.3
13401340
assert len(res.rows) == 2 # check also the search result
1341+
1342+
1343+
@pytest.mark.redismod
1344+
def test_profile_limited(client):
1345+
client.ft().create_index((TextField('t'),))
1346+
client.ft().client.hset('1', 't', 'hello')
1347+
client.ft().client.hset('2', 't', 'hell')
1348+
client.ft().client.hset('3', 't', 'help')
1349+
client.ft().client.hset('4', 't', 'helowa')
1350+
1351+
q = Query('%hell% hel*')
1352+
res, det = client.ft().profile(q, limited=True)
1353+
assert det['Iterators profile']['Child iterators'][0]['Child iterators'] \
1354+
== 'The number of iterators in the union is 3'
1355+
assert det['Iterators profile']['Child iterators'][1]['Child iterators'] \
1356+
== 'The number of iterators in the union is 4'
1357+
assert det['Iterators profile']['Type'] == 'INTERSECT'
1358+
assert len(res.docs) == 3 # check also the search result

0 commit comments

Comments
 (0)