Skip to content

Commit cf06bbf

Browse files
committed
Unify print_block_string tests in correct place
Replicates graphql/graphql-js@961dab3
1 parent a64ca4b commit cf06bbf

File tree

4 files changed

+27
-134
lines changed

4 files changed

+27
-134
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.0.2 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.1.1. All parts of the API are covered by an extensive test suite of currently 1737
16+
14.1.1. All parts of the API are covered by an extensive test suite of currently 1724
1717
unit tests.
1818

1919

tests/language/test_block_string.py

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,62 +70,29 @@ def does_not_alter_trailing_spaces():
7070

7171

7272
def describe_print_block_string():
73-
def describe_single_line():
74-
def simple():
75-
assert print_block_string("single line") == '"""single line"""'
76-
77-
def with_leading_whitespace():
78-
assert print_block_string(" single line") == '""" single line"""'
79-
80-
def with_indentation():
81-
assert (
82-
print_block_string("single line", indentation=" ")
83-
== '"""single line"""'
84-
)
85-
86-
def with_indentation_and_leading_whitespace():
87-
assert (
88-
print_block_string(" single line", indentation=" ")
89-
== '""" single line"""'
90-
)
91-
92-
def with_trailing_quote():
93-
assert print_block_string('single "line"') == '"""\nsingle "line"\n"""'
94-
95-
def prefer_multiple_lines():
96-
assert (
97-
print_block_string("single line", prefer_multiple_lines=True)
98-
== '"""\nsingle line\n"""'
99-
)
100-
101-
def describe_multiple_lines():
102-
def simple():
103-
assert print_block_string("multiple\nlines") == '"""\nmultiple\nlines\n"""'
104-
105-
def with_leading_whitespace():
106-
assert (
107-
print_block_string(" multiple\nlines") == '"""\n multiple\nlines\n"""'
108-
)
109-
110-
def with_indentation():
111-
assert (
112-
print_block_string("multiple\nlines", indentation=" ")
113-
== '"""\n multiple\n lines\n"""'
114-
)
115-
116-
def with_indentation_and_leading_whitespace():
117-
assert (
118-
print_block_string(" multiple\nlines", indentation=" ")
119-
== '"""\n multiple\n lines\n"""'
120-
)
121-
122-
def with_trailing_quote():
123-
assert (
124-
print_block_string('multiple\n"line"') == '"""\nmultiple\n"line"\n"""'
125-
)
126-
127-
def do_not_prefer_multiple_lines():
128-
assert (
129-
print_block_string("multiple\nlines", prefer_multiple_lines=False)
130-
== '"""\nmultiple\nlines\n"""'
131-
)
73+
def by_default_print_block_strings_as_single_line():
74+
s = "one liner"
75+
assert print_block_string(s) == '"""one liner"""'
76+
assert print_block_string(s, "", True) == '"""\none liner\n"""'
77+
78+
def correctly_prints_single_line_with_leading_space():
79+
s = " space-led string"
80+
assert print_block_string(s) == '""" space-led string"""'
81+
assert print_block_string(s, "", True) == '""" space-led string\n"""'
82+
83+
def correctly_prints_single_line_with_leading_space_and_quotation():
84+
s = ' space-led value "quoted string"'
85+
86+
assert print_block_string(s) == '""" space-led value "quoted string"\n"""'
87+
88+
assert (
89+
print_block_string(s, "", True)
90+
== '""" space-led value "quoted string"\n"""'
91+
)
92+
93+
def correctly_prints_string_with_a_first_line_indentation():
94+
s = join_lines(" first ", " line ", "indentation", " string")
95+
96+
assert print_block_string(s) == join_lines(
97+
'"""', " first ", " line ", "indentation", " string", '"""'
98+
)

tests/language/test_printer.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,41 +89,6 @@ def experimental_prints_fragment_with_variable_directives():
8989
"""
9090
)
9191

92-
93-
def describe_block_string():
94-
def correctly_prints_single_line_block_strings_with_leading_space():
95-
ast_with_artifacts = parse('{ field(arg: """ space-led value""") }')
96-
assert print_ast(ast_with_artifacts) == dedent(
97-
'''
98-
{
99-
field(arg: """ space-led value""")
100-
}
101-
'''
102-
)
103-
104-
def correctly_prints_string_with_a_first_line_indentation():
105-
source = '''
106-
{
107-
field(arg: """
108-
first
109-
line
110-
indentation
111-
""")
112-
}
113-
'''
114-
ast_with_artifacts = parse(source)
115-
assert print_ast(ast_with_artifacts) == dedent(source)
116-
117-
def correctly_prints_single_line_with_leading_space_and_quotation():
118-
source = '''
119-
{
120-
field(arg: """ space-led value "quoted string"
121-
""")
122-
}
123-
'''
124-
ast_with_artifacts = parse(source)
125-
assert print_ast(ast_with_artifacts) == dedent(source)
126-
12792
def experimental_correctly_prints_fragment_defined_variables():
12893
source = """
12994
fragment Foo($a: ComplexType, $b: Boolean = false) on TestType {

tests/utilities/test_schema_printer.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -494,45 +494,6 @@ def one_line_prints_a_short_description():
494494
recreated_field = recreated_root.fields["singleField"]
495495
assert recreated_field.description == description
496496

497-
def does_not_one_line_print_a_description_that_ends_with_a_quote():
498-
description = 'This field is "awesome"'
499-
output = print_single_field_schema(
500-
GraphQLField(GraphQLString, description=description)
501-
)
502-
assert output == dedent(
503-
'''
504-
type Query {
505-
"""
506-
This field is "awesome"
507-
"""
508-
singleField: String
509-
}
510-
'''
511-
)
512-
schema = build_schema(output)
513-
recreated_root = assert_object_type(schema.type_map["Query"])
514-
recreated_field = recreated_root.fields["singleField"]
515-
assert recreated_field.description == description
516-
517-
def preserves_leading_spaces_when_printing_a_description():
518-
description = ' This field is "awesome"'
519-
output = print_single_field_schema(
520-
GraphQLField(GraphQLString, description=description)
521-
)
522-
assert output == dedent(
523-
'''
524-
type Query {
525-
""" This field is "awesome"
526-
"""
527-
singleField: String
528-
}
529-
'''
530-
)
531-
schema = build_schema(output)
532-
recreated_root = assert_object_type(schema.type_map["Query"])
533-
recreated_field = recreated_root.fields["singleField"]
534-
assert recreated_field.description == description
535-
536497
def prints_introspection_schema():
537498
schema = GraphQLSchema()
538499
output = print_introspection_schema(schema)

0 commit comments

Comments
 (0)