Skip to content

Commit f676f7f

Browse files
committed
Use type hints in definition tests
Replicates graphql/graphql-js@6ea1a14
1 parent 0a33b50 commit f676f7f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

tests/type/test_definition.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
GraphQLArgument,
88
GraphQLBoolean,
99
GraphQLField,
10+
GraphQLFieldResolver,
1011
GraphQLInt,
1112
GraphQLString,
1213
GraphQLObjectType,
@@ -22,6 +23,7 @@
2223
GraphQLInputField,
2324
GraphQLNonNull,
2425
is_input_type,
26+
is_object_type,
2527
is_output_type,
2628
)
2729

@@ -114,24 +116,20 @@ def defines_a_query_only_schema():
114116
BlogSchema = GraphQLSchema(BlogQuery)
115117

116118
assert BlogSchema.query_type == BlogQuery
119+
assert is_object_type(BlogQuery)
117120

118121
article_field = BlogQuery.fields["article"]
119122
assert article_field.type == BlogArticle
120-
assert article_field.type.name == "Article"
121123

122-
article_field_type = article_field.type
123-
assert isinstance(article_field_type, GraphQLObjectType)
124-
125-
title_field = article_field_type.fields["title"]
124+
assert is_object_type(BlogArticle)
125+
blog_article_fields = BlogArticle.fields
126+
title_field = blog_article_fields["title"]
126127
assert title_field.type == GraphQLString
127-
assert title_field.type.name == "String"
128-
129-
author_field = article_field_type.fields["author"]
130-
131-
author_field_type = author_field.type
132-
assert isinstance(author_field_type, GraphQLObjectType)
133-
recent_article_field = author_field_type.fields["recentArticle"]
128+
author_field = blog_article_fields["author"]
129+
assert author_field.type == BlogAuthor
134130

131+
assert is_object_type(BlogAuthor)
132+
recent_article_field = BlogAuthor.fields["recentArticle"]
135133
assert recent_article_field.type == BlogArticle
136134

137135
feed_field = BlogQuery.fields["feed"]
@@ -142,9 +140,9 @@ def defines_a_mutation_schema():
142140

143141
assert BlogSchema.mutation_type == BlogMutation
144142

143+
assert is_object_type(BlogMutation)
145144
write_mutation = BlogMutation.fields["writeArticle"]
146145
assert write_mutation.type == BlogArticle
147-
assert write_mutation.type.name == "Article"
148146

149147
def defines_a_subscription_schema():
150148
BlogSchema = GraphQLSchema(query=BlogQuery, subscription=BlogSubscription)
@@ -325,18 +323,18 @@ def allows_a_thunk_for_union_member_types():
325323
assert types[0] is ObjectType
326324

327325
def does_not_mutate_passed_field_definitions():
328-
fields = {
326+
output_fields = {
329327
"field1": GraphQLField(GraphQLString),
330328
"field2": GraphQLField(
331329
GraphQLString, args={"id": GraphQLArgument(GraphQLString)}
332330
),
333331
}
334332

335-
TestObject1 = GraphQLObjectType("Test1", fields)
336-
TestObject2 = GraphQLObjectType("Test2", fields)
333+
TestObject1 = GraphQLObjectType("Test1", output_fields)
334+
TestObject2 = GraphQLObjectType("Test2", output_fields)
337335

338336
assert TestObject1.fields == TestObject2.fields
339-
assert fields == {
337+
assert output_fields == {
340338
"field1": GraphQLField(GraphQLString),
341339
"field2": GraphQLField(
342340
GraphQLString, args={"id": GraphQLArgument(GraphQLString)}
@@ -440,7 +438,7 @@ def rejects_an_object_type_with_incorrectly_typed_field_args():
440438
msg = str(exc_info.value)
441439
assert msg == "Field args must be a dict with argument names as keys."
442440

443-
def does_not_accept_is_deprecated_as_argument():
441+
def does_not_accept_is_deprecated_instead_of_deprecation_reason_on_field():
444442
kwargs = dict(is_deprecated=True)
445443
with raises(TypeError) as exc_info:
446444
GraphQLObjectType(
@@ -514,7 +512,7 @@ def rejects_object_type_with_incorrectly_typed_interfaces_as_a_function():
514512

515513

516514
def describe_type_system_object_fields_must_have_valid_resolve_values():
517-
def _schema_with_object_with_field_resolver(resolve_value):
515+
def _schema_with_object_with_field_resolver(resolve_value: GraphQLFieldResolver):
518516
BadResolverType = GraphQLObjectType(
519517
"BadResolver",
520518
{"bad_field": GraphQLField(GraphQLString, resolve=resolve_value)},
@@ -843,11 +841,11 @@ def describe_type_system_list_must_accept_only_types():
843841

844842
not_types = [{}, dict, str, object, None]
845843

846-
@mark.parametrize("type_", types)
844+
@mark.parametrize("type_", types, ids=lambda type_: type_.__class__.__name__)
847845
def accepts_a_type_as_item_type_of_list(type_):
848846
assert GraphQLList(type_)
849847

850-
@mark.parametrize("type_", not_types)
848+
@mark.parametrize("type_", not_types, ids=lambda type_: type_.__class__.__name__)
851849
def rejects_a_non_type_as_item_type_of_list(type_):
852850
with raises(TypeError) as exc_info:
853851
assert GraphQLList(type_)

0 commit comments

Comments
 (0)