Skip to content

Commit e26e5c0

Browse files
linters
1 parent ba44296 commit e26e5c0

File tree

1 file changed

+67
-117
lines changed

1 file changed

+67
-117
lines changed

tests/test_search.py

Lines changed: 67 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def getClient():
6161
def createIndex(client, num_docs=100, definition=None):
6262
try:
6363
client.create_index(
64-
(TextField("play", weight=5.0),
65-
TextField("txt"),
66-
NumericField("chapter")),
64+
(TextField("play", weight=5.0), TextField("txt"), NumericField("chapter")),
6765
definition=definition,
6866
)
6967
except redis.ResponseError:
@@ -286,17 +284,8 @@ def test_stopwords(client):
286284

287285
@pytest.mark.redismod
288286
def test_filters(client):
289-
client.ft().create_index(
290-
(TextField("txt"),
291-
NumericField("num"),
292-
GeoField("loc"))
293-
)
294-
client.ft().add_document(
295-
"doc1",
296-
txt="foo bar",
297-
num=3.141,
298-
loc="-0.441,51.458"
299-
)
287+
client.ft().create_index((TextField("txt"), NumericField("num"), GeoField("loc")))
288+
client.ft().add_document("doc1", txt="foo bar", num=3.141, loc="-0.441,51.458")
300289
client.ft().add_document("doc2", txt="foo baz", num=2, loc="-0.1,51.2")
301290

302291
waitForIndex(client, "idx")
@@ -342,10 +331,7 @@ def test_payloads_with_no_content(client):
342331

343332
@pytest.mark.redismod
344333
def test_sort_by(client):
345-
client.ft().create_index(
346-
(TextField("txt"),
347-
NumericField("num", sortable=True))
348-
)
334+
client.ft().create_index((TextField("txt"), NumericField("num", sortable=True)))
349335
client.ft().add_document("doc1", txt="foo bar", num=1)
350336
client.ft().add_document("doc2", txt="foo baz", num=2)
351337
client.ft().add_document("doc3", txt="foo qux", num=3)
@@ -387,10 +373,7 @@ def test_drop_index():
387373
@pytest.mark.redismod
388374
def test_example(client):
389375
# Creating the index definition and schema
390-
client.ft().create_index(
391-
(TextField("title", weight=5.0),
392-
TextField("body"))
393-
)
376+
client.ft().create_index((TextField("title", weight=5.0), TextField("body")))
394377

395378
# Indexing a document
396379
client.ft().add_document(
@@ -510,11 +493,7 @@ def test_no_index(client):
510493

511494
@pytest.mark.redismod
512495
def test_partial(client):
513-
client.ft().create_index(
514-
(TextField("f1"),
515-
TextField("f2"),
516-
TextField("f3"))
517-
)
496+
client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
518497
client.ft().add_document("doc1", f1="f1_val", f2="f2_val")
519498
client.ft().add_document("doc2", f1="f1_val", f2="f2_val")
520499
client.ft().add_document("doc1", f3="f3_val", partial=True)
@@ -532,11 +511,7 @@ def test_partial(client):
532511

533512
@pytest.mark.redismod
534513
def test_no_create(client):
535-
client.ft().create_index(
536-
(TextField("f1"),
537-
TextField("f2"),
538-
TextField("f3"))
539-
)
514+
client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
540515
client.ft().add_document("doc1", f1="f1_val", f2="f2_val")
541516
client.ft().add_document("doc2", f1="f1_val", f2="f2_val")
542517
client.ft().add_document("doc1", f3="f3_val", no_create=True)
@@ -557,11 +532,7 @@ def test_no_create(client):
557532

558533
@pytest.mark.redismod
559534
def test_explain(client):
560-
client.ft().create_index(
561-
(TextField("f1"),
562-
TextField("f2"),
563-
TextField("f3"))
564-
)
535+
client.ft().create_index((TextField("f1"), TextField("f2"), TextField("f3")))
565536
res = client.ft().explain("@f3:f3_val @f2:f2_val @f1:f1_val")
566537
assert res
567538

@@ -584,17 +555,17 @@ def test_summarize(client):
584555
doc = sorted(client.ft().search(q).docs)[0]
585556
assert "<b>Henry</b> IV" == doc.play
586557
assert (
587-
"ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
588-
== doc.txt
558+
"ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
559+
== doc.txt
589560
)
590561

591562
q = Query("king henry").paging(0, 1).summarize().highlight()
592563

593564
doc = sorted(client.ft().search(q).docs)[0]
594565
assert "<b>Henry</b> ... " == doc.play
595566
assert (
596-
"ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
597-
== doc.txt
567+
"ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
568+
== doc.txt
598569
)
599570

600571

@@ -763,10 +734,10 @@ def test_spell_check(client):
763734
res = client.ft().spellcheck("lorm", include="dict")
764735
assert len(res["lorm"]) == 3
765736
assert (
766-
res["lorm"][0]["suggestion"],
767-
res["lorm"][1]["suggestion"],
768-
res["lorm"][2]["suggestion"],
769-
) == ("lorem", "lore", "lorm")
737+
res["lorm"][0]["suggestion"],
738+
res["lorm"][1]["suggestion"],
739+
res["lorm"][2]["suggestion"],
740+
) == ("lorem", "lore", "lorm")
770741
assert (res["lorm"][0]["score"], res["lorm"][1]["score"]) == ("0.5", "0")
771742

772743
# test spellcheck exclude
@@ -1010,7 +981,7 @@ def test_aggregations_groupby(client):
1010981
)
1011982

1012983
res = client.ft().aggregate(req).rows[0]
1013-
assert res == ['parent', 'redis', 'first', 'RediSearch']
984+
assert res == ["parent", "redis", "first", "RediSearch"]
1014985

1015986
req = aggregations.AggregateRequest("redis").group_by(
1016987
"@parent",
@@ -1033,35 +1004,33 @@ def test_aggregations_sort_by_and_limit(client):
10331004
)
10341005
)
10351006

1036-
client.ft().client.hset("doc1", mapping={'t1': 'a', 't2': 'b'})
1037-
client.ft().client.hset("doc2", mapping={'t1': 'b', 't2': 'a'})
1007+
client.ft().client.hset("doc1", mapping={"t1": "a", "t2": "b"})
1008+
client.ft().client.hset("doc2", mapping={"t1": "b", "t2": "a"})
10381009

10391010
# test sort_by using SortDirection
1040-
req = aggregations.AggregateRequest("*") \
1041-
.sort_by(aggregations.Asc("@t2"), aggregations.Desc("@t1"))
1011+
req = aggregations.AggregateRequest("*").sort_by(
1012+
aggregations.Asc("@t2"), aggregations.Desc("@t1")
1013+
)
10421014
res = client.ft().aggregate(req)
1043-
assert res.rows[0] == ['t2', 'a', 't1', 'b']
1044-
assert res.rows[1] == ['t2', 'b', 't1', 'a']
1015+
assert res.rows[0] == ["t2", "a", "t1", "b"]
1016+
assert res.rows[1] == ["t2", "b", "t1", "a"]
10451017

10461018
# test sort_by without SortDirection
1047-
req = aggregations.AggregateRequest("*") \
1048-
.sort_by("@t1")
1019+
req = aggregations.AggregateRequest("*").sort_by("@t1")
10491020
res = client.ft().aggregate(req)
1050-
assert res.rows[0] == ['t1', 'a']
1051-
assert res.rows[1] == ['t1', 'b']
1021+
assert res.rows[0] == ["t1", "a"]
1022+
assert res.rows[1] == ["t1", "b"]
10521023

10531024
# test sort_by with max
1054-
req = aggregations.AggregateRequest("*") \
1055-
.sort_by("@t1", max=1)
1025+
req = aggregations.AggregateRequest("*").sort_by("@t1", max=1)
10561026
res = client.ft().aggregate(req)
10571027
assert len(res.rows) == 1
10581028

10591029
# test limit
1060-
req = aggregations.AggregateRequest("*") \
1061-
.sort_by("@t1").limit(1, 1)
1030+
req = aggregations.AggregateRequest("*").sort_by("@t1").limit(1, 1)
10621031
res = client.ft().aggregate(req)
10631032
assert len(res.rows) == 1
1064-
assert res.rows[0] == ['t1', 'b']
1033+
assert res.rows[0] == ["t1", "b"]
10651034

10661035

10671036
@pytest.mark.redismod
@@ -1073,22 +1042,22 @@ def test_aggregations_load(client):
10731042
)
10741043
)
10751044

1076-
client.ft().client.hset("doc1", mapping={'t1': 'hello', 't2': 'world'})
1045+
client.ft().client.hset("doc1", mapping={"t1": "hello", "t2": "world"})
10771046

10781047
# load t1
10791048
req = aggregations.AggregateRequest("*").load("t1")
10801049
res = client.ft().aggregate(req)
1081-
assert res.rows[0] == ['t1', 'hello']
1050+
assert res.rows[0] == ["t1", "hello"]
10821051

10831052
# load t2
10841053
req = aggregations.AggregateRequest("*").load("t2")
10851054
res = client.ft().aggregate(req)
1086-
assert res.rows[0] == ['t2', 'world']
1055+
assert res.rows[0] == ["t2", "world"]
10871056

10881057
# load all
10891058
req = aggregations.AggregateRequest("*").load()
10901059
res = client.ft().aggregate(req)
1091-
assert res.rows[0] == ['t1', 'hello', 't2', 'world']
1060+
assert res.rows[0] == ["t1", "hello", "t2", "world"]
10921061

10931062

10941063
@pytest.mark.redismod
@@ -1102,24 +1071,19 @@ def test_aggregations_apply(client):
11021071

11031072
client.ft().client.hset(
11041073
"doc1",
1105-
mapping={
1106-
'PrimaryKey': '9::362330',
1107-
'CreatedDateTimeUTC': '637387878524969984'
1108-
}
1074+
mapping={"PrimaryKey": "9::362330", "CreatedDateTimeUTC": "637387878524969984"},
11091075
)
11101076
client.ft().client.hset(
11111077
"doc2",
1112-
mapping={
1113-
'PrimaryKey': '9::362329',
1114-
'CreatedDateTimeUTC': '637387875859270016'
1115-
}
1078+
mapping={"PrimaryKey": "9::362329", "CreatedDateTimeUTC": "637387875859270016"},
11161079
)
11171080

1118-
req = aggregations.AggregateRequest("*") \
1119-
.apply(CreatedDateTimeUTC='@CreatedDateTimeUTC * 10')
1081+
req = aggregations.AggregateRequest("*").apply(
1082+
CreatedDateTimeUTC = "@CreatedDateTimeUTC * 10"
1083+
)
11201084
res = client.ft().aggregate(req)
1121-
assert res.rows[0] == ['CreatedDateTimeUTC', '6373878785249699840']
1122-
assert res.rows[1] == ['CreatedDateTimeUTC', '6373878758592700416']
1085+
assert res.rows[0] == ["CreatedDateTimeUTC", "6373878785249699840"]
1086+
assert res.rows[1] == ["CreatedDateTimeUTC", "6373878758592700416"]
11231087

11241088

11251089
@pytest.mark.redismod
@@ -1131,33 +1095,19 @@ def test_aggregations_filter(client):
11311095
)
11321096
)
11331097

1134-
client.ft().client.hset(
1135-
"doc1",
1136-
mapping={
1137-
'name': 'bar',
1138-
'age': '25'
1139-
}
1140-
)
1141-
client.ft().client.hset(
1142-
"doc2",
1143-
mapping={
1144-
'name': 'foo',
1145-
'age': '19'
1146-
}
1147-
)
1098+
client.ft().client.hset("doc1", mapping={"name": "bar", "age": "25"})
1099+
client.ft().client.hset("doc2", mapping={"name": "foo", "age": "19"})
11481100

1149-
req = aggregations.AggregateRequest("*") \
1150-
.filter("@name=='foo' && @age < 20")
1101+
req = aggregations.AggregateRequest("*").filter("@name=='foo' && @age < 20")
11511102
res = client.ft().aggregate(req)
11521103
assert len(res.rows) == 1
1153-
assert res.rows[0] == ['name', 'foo', 'age', '19']
1104+
assert res.rows[0] == ["name", "foo", "age", "19"]
11541105

1155-
req = aggregations.AggregateRequest("*") \
1156-
.filter("@age > 15").sort_by("@age")
1106+
req = aggregations.AggregateRequest("*").filter("@age > 15").sort_by("@age")
11571107
res = client.ft().aggregate(req)
11581108
assert len(res.rows) == 2
1159-
assert res.rows[0] == ['age', '19']
1160-
assert res.rows[1] == ['age', '25']
1109+
assert res.rows[0] == ["age", "19"]
1110+
assert res.rows[1] == ["age", "25"]
11611111

11621112

11631113
@pytest.mark.redismod
@@ -1181,25 +1131,25 @@ def test_index_definition(client):
11811131
)
11821132

11831133
assert [
1184-
"ON",
1185-
"JSON",
1186-
"PREFIX",
1187-
2,
1188-
"hset:",
1189-
"henry",
1190-
"FILTER",
1191-
"@f1==32",
1192-
"LANGUAGE_FIELD",
1193-
"play",
1194-
"LANGUAGE",
1195-
"English",
1196-
"SCORE_FIELD",
1197-
"chapter",
1198-
"SCORE",
1199-
0.5,
1200-
"PAYLOAD_FIELD",
1201-
"txt",
1202-
] == definition.args
1134+
"ON",
1135+
"JSON",
1136+
"PREFIX",
1137+
2,
1138+
"hset:",
1139+
"henry",
1140+
"FILTER",
1141+
"@f1==32",
1142+
"LANGUAGE_FIELD",
1143+
"play",
1144+
"LANGUAGE",
1145+
"English",
1146+
"SCORE_FIELD",
1147+
"chapter",
1148+
"SCORE",
1149+
0.5,
1150+
"PAYLOAD_FIELD",
1151+
"txt",
1152+
] == definition.args
12031153

12041154
createIndex(client.ft(), num_docs=500, definition=definition)
12051155

0 commit comments

Comments
 (0)