Skip to content

Commit 967a02d

Browse files
committed
Switch schema parser tests to use dedent
Replicates graphql/graphql-js@d1e0abf
1 parent d24f556 commit 967a02d

File tree

1 file changed

+72
-17
lines changed

1 file changed

+72
-17
lines changed

tests/language/test_schema_parser.py

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,14 @@ def directive_node(name, arguments, loc):
110110

111111
def describe_schema_parser():
112112
def simple_type():
113-
body = "\ntype Hello {\n world: String\n}"
114-
definition = assert_definitions(body, (0, 31))
113+
body = dedent(
114+
"""
115+
type Hello {
116+
world: String
117+
}
118+
"""
119+
)
120+
definition = assert_definitions(body, (0, 32))
115121
assert isinstance(definition, ObjectTypeDefinitionNode)
116122
assert definition.name == name_node("Hello", (6, 11))
117123
assert definition.description is None
@@ -125,8 +131,15 @@ def simple_type():
125131
assert definition.loc == (1, 31)
126132

127133
def parses_type_with_description_string():
128-
body = '\n"Description"\ntype Hello {\n world: String\n}'
129-
definition = assert_definitions(body, (0, 45))
134+
body = dedent(
135+
"""
136+
"Description"
137+
type Hello {
138+
world: String
139+
}
140+
"""
141+
)
142+
definition = assert_definitions(body, (0, 46))
130143
assert isinstance(definition, ObjectTypeDefinitionNode)
131144
assert definition.name == name_node("Hello", (20, 25))
132145
description = definition.description
@@ -156,7 +169,13 @@ def parses_type_with_description_multi_line_string():
156169
assert description.loc == (1, 20)
157170

158171
def simple_extension():
159-
body = "\nextend type Hello {\n world: String\n}\n"
172+
body = dedent(
173+
"""
174+
extend type Hello {
175+
world: String
176+
}
177+
"""
178+
)
160179
extension = assert_definitions(body, (0, 39))
161180
assert isinstance(extension, ObjectTypeExtensionNode)
162181
assert extension.name == name_node("Hello", (13, 18))
@@ -261,8 +280,14 @@ def schema_extension_without_anything_throws():
261280
assert_syntax_error("extend schema", "Unexpected <EOF>", (1, 14))
262281

263282
def simple_non_null_type():
264-
body = "\ntype Hello {\n world: String!\n}"
265-
definition = assert_definitions(body, (0, 32))
283+
body = dedent(
284+
"""
285+
type Hello {
286+
world: String!
287+
}
288+
"""
289+
)
290+
definition = assert_definitions(body, (0, 33))
266291
assert isinstance(definition, ObjectTypeDefinitionNode)
267292
assert definition.name == name_node("Hello", (6, 11))
268293
assert definition.description is None
@@ -352,8 +377,14 @@ def double_value_enum():
352377
assert definition.loc == (0, 22)
353378

354379
def simple_interface():
355-
body = "\ninterface Hello {\n world: String\n}"
356-
definition = assert_definitions(body, (0, 36))
380+
body = dedent(
381+
"""
382+
interface Hello {
383+
world: String
384+
}
385+
"""
386+
)
387+
definition = assert_definitions(body, (0, 37))
357388
assert isinstance(definition, InterfaceTypeDefinitionNode)
358389
assert definition.name == name_node("Hello", (11, 16))
359390
assert definition.description is None
@@ -366,8 +397,14 @@ def simple_interface():
366397
assert definition.loc == (1, 36)
367398

368399
def simple_field_with_arg():
369-
body = "\ntype Hello {\n world(flag: Boolean): String\n}"
370-
definition = assert_definitions(body, (0, 46))
400+
body = dedent(
401+
"""
402+
type Hello {
403+
world(flag: Boolean): String
404+
}
405+
"""
406+
)
407+
definition = assert_definitions(body, (0, 47))
371408
assert isinstance(definition, ObjectTypeDefinitionNode)
372409
assert definition.name == name_node("Hello", (6, 11))
373410
assert definition.description is None
@@ -391,8 +428,14 @@ def simple_field_with_arg():
391428
assert definition.loc == (1, 46)
392429

393430
def simple_field_with_arg_with_default_value():
394-
body = "\ntype Hello {\n world(flag: Boolean = true): String\n}"
395-
definition = assert_definitions(body, (0, 53))
431+
body = dedent(
432+
"""
433+
type Hello {
434+
world(flag: Boolean = true): String
435+
}
436+
"""
437+
)
438+
definition = assert_definitions(body, (0, 54))
396439
assert isinstance(definition, ObjectTypeDefinitionNode)
397440
assert definition.name == name_node("Hello", (6, 11))
398441
assert definition.description is None
@@ -416,8 +459,14 @@ def simple_field_with_arg_with_default_value():
416459
assert definition.loc == (1, 53)
417460

418461
def simple_field_with_list_arg():
419-
body = "\ntype Hello {\n world(things: [String]): String\n}"
420-
definition = assert_definitions(body, (0, 49))
462+
body = dedent(
463+
"""
464+
type Hello {
465+
world(things: [String]): String
466+
}
467+
"""
468+
)
469+
definition = assert_definitions(body, (0, 50))
421470
assert isinstance(definition, ObjectTypeDefinitionNode)
422471
assert definition.name == name_node("Hello", (6, 11))
423472
assert definition.description is None
@@ -441,8 +490,14 @@ def simple_field_with_list_arg():
441490
assert definition.loc == (1, 49)
442491

443492
def simple_field_with_two_args():
444-
body = "\ntype Hello {\n world(argOne: Boolean, argTwo: Int): String\n}"
445-
definition = assert_definitions(body, (0, 61))
493+
body = dedent(
494+
"""
495+
type Hello {
496+
world(argOne: Boolean, argTwo: Int): String
497+
}
498+
"""
499+
)
500+
definition = assert_definitions(body, (0, 62))
446501
assert isinstance(definition, ObjectTypeDefinitionNode)
447502
assert definition.name == name_node("Hello", (6, 11))
448503
assert definition.description is None

0 commit comments

Comments
 (0)