Skip to content

Commit aa1ce98

Browse files
committed
Better error messages in strip_ignored_characters tests
Replicates graphql/graphql-js@ebcc754
1 parent 32bf766 commit aa1ce98

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

tests/utilities/test_strip_ignored_characters.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
def lex_value(s: str) -> Optional[str]:
4343
lexer = Lexer(Source(s))
4444
value = lexer.advance().value
45-
assert lexer.advance().kind == TokenKind.EOF
45+
assert lexer.advance().kind == TokenKind.EOF, "Expected EOF"
4646
return value
4747

4848

@@ -53,15 +53,23 @@ def __init__(self, doc_string: str):
5353
def to_equal(self, expected: str):
5454
doc_string = self.doc_string
5555
stripped = strip_ignored_characters(doc_string)
56-
assert stripped == expected, (
57-
f"Expected strip_ignored_characters({doc_string!r})\n"
58-
f"\tto equal {expected!r}\n\tbut got {stripped!r}"
56+
57+
assert stripped == expected, dedent(
58+
f"""
59+
Expected strip_ignored_characters({doc_string!r})
60+
to equal {expected!r}
61+
but got {stripped!r}
62+
"""
5963
)
6064

6165
stripped_twice = strip_ignored_characters(stripped)
62-
assert stripped == stripped_twice, (
63-
f"Expected strip_ignored_characters({stripped!r})\n"
64-
f"\tto equal {stripped!r}\n\tbut got {stripped_twice!r}"
66+
67+
assert stripped == stripped_twice, dedent(
68+
f""""
69+
Expected strip_ignored_characters({stripped!r})"
70+
to equal {stripped!r}
71+
but got {stripped_twice!r}
72+
"""
6573
)
6674

6775
def to_stay_the_same(self):
@@ -338,7 +346,13 @@ def expect_stripped_string(block_str: str):
338346
stripped_str = strip_ignored_characters(block_str)
339347
stripped_value = lex_value(stripped_str)
340348

341-
assert original_value == stripped_value
349+
assert original_value == stripped_value, dedent(
350+
f"""
351+
Expected lexOne(stripIgnoredCharacters({block_str!r})
352+
to equal {original_value!r}
353+
but got {stripped_value!r}
354+
"""
355+
)
342356
return ExpectStripped(block_str)
343357

344358
expect_stripped_string('""""""').to_stay_the_same()
@@ -389,7 +403,13 @@ def expect_stripped_string(block_str: str):
389403
stripped_str = strip_ignored_characters(test_str)
390404
stripped_value = lex_value(stripped_str)
391405

392-
assert test_value == stripped_value
406+
assert test_value == stripped_value, dedent(
407+
f"""
408+
Expected lexOne(stripIgnoredCharacters({test_str!r})
409+
to equal {test_value!r}
410+
but got {stripped_value!r}
411+
"""
412+
)
393413

394414
# noinspection PyShadowingNames
395415
def strips_kitchen_sink_query_but_maintains_the_exact_same_ast(

0 commit comments

Comments
 (0)