Skip to content

Commit 2150481

Browse files
committed
test_suggestion_list: improve readability
Replicates graphql/graphql-js@7a4cbbb
1 parent 50f339c commit 2150481

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

tests/pyutils/test_suggesion_list.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1+
from typing import List
2+
13
from graphql.pyutils import suggestion_list
24

35

6+
def expect_suggestions(input: str, options: List[str], expected: List[str]) -> None:
7+
assert suggestion_list(input, options) == expected
8+
9+
410
def describe_suggestion_list():
511
def returns_results_when_input_is_empty():
6-
assert suggestion_list("", ["a"]) == ["a"]
12+
expect_suggestions("", ["a"], ["a"])
713

814
def returns_empty_array_when_there_are_no_options():
9-
assert suggestion_list("input", []) == []
15+
expect_suggestions("input", [], [])
1016

1117
def returns_options_with_small_lexical_distance():
12-
assert suggestion_list("greenish", ["green"]) == ["green"]
13-
assert suggestion_list("green", ["greenish"]) == ["greenish"]
18+
expect_suggestions("greenish", ["green"], ["green"])
19+
expect_suggestions("green", ["greenish"], ["greenish"])
1420

1521
def returns_options_with_different_case():
16-
assert suggestion_list("verylongstring", ["VERYLONGSTRING"]) == [
17-
"VERYLONGSTRING"
18-
]
22+
expect_suggestions("verylongstring", ["VERYLONGSTRING"], ["VERYLONGSTRING"])
1923

20-
assert suggestion_list("VERYLONGSTRING", ["verylongstring"]) == [
21-
"verylongstring"
22-
]
24+
expect_suggestions("VERYLONGSTRING", ["verylongstring"], ["verylongstring"])
2325

24-
assert suggestion_list("VERYLONGSTRING", ["VeryLongString"]) == [
25-
"VeryLongString"
26-
]
26+
expect_suggestions("VERYLONGSTRING", ["VeryLongString"], ["VeryLongString"])
2727

2828
def returns_options_with_transpositions():
29-
assert suggestion_list("agr", ["arg"]) == ["arg"]
29+
expect_suggestions("agr", ["arg"], ["arg"])
3030

31-
assert suggestion_list("214365879", ["123456789"]) == ["123456789"]
31+
expect_suggestions("214365879", ["123456789"], ["123456789"])
3232

3333
def returns_options_sorted_based_on_lexical_distance():
34-
assert suggestion_list("abc", ["a", "ab", "abc"]) == ["abc", "ab"]
34+
expect_suggestions("abc", ["a", "ab", "abc"], ["abc", "ab"])
3535

36-
assert suggestion_list(
37-
"GraphQl", ["graphics", "SQL", "GraphQL", "quarks", "mark"]
38-
) == ["GraphQL", "graphics"]
36+
expect_suggestions(
37+
"GraphQl",
38+
["graphics", "SQL", "GraphQL", "quarks", "mark"],
39+
["GraphQL", "graphics"],
40+
)
3941

4042
def returns_options_with_the_same_lexical_distance_sorted_lexicographically():
41-
assert suggestion_list("a", ["az", "ax", "ay"]) == ["ax", "ay", "az"]
43+
expect_suggestions("a", ["az", "ax", "ay"], ["ax", "ay", "az"])
4244

43-
assert suggestion_list("boo", ["moo", "foo", "zoo"]) == ["foo", "moo", "zoo"]
45+
expect_suggestions("boo", ["moo", "foo", "zoo"], ["foo", "moo", "zoo"])
4446

4547
def returns_options_sorted_first_by_lexical_distance_then_lexicographically():
46-
assert suggestion_list(
47-
"csutomer", ["store", "customer", "stomer", "some", "more"]
48-
) == ["customer", "stomer", "some", "store"]
48+
expect_suggestions(
49+
"csutomer",
50+
["store", "customer", "stomer", "some", "more"],
51+
["customer", "stomer", "some", "store"],
52+
)

0 commit comments

Comments
 (0)