Skip to content

Commit a206db0

Browse files
committed
Bring coverage to 100% (upstream only)
We still need to achieve 100% coverage in Python. Replicates graphql/graphql-js@c54e141
1 parent 9b8ade4 commit a206db0

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

src/graphql/type/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def is_possible_type(
260260
261261
Deprecated: Use is_sub_type() instead.
262262
"""
263-
return self.is_sub_type(abstract_type, possible_type) # pragma: no cover
263+
return self.is_sub_type(abstract_type, possible_type)
264264

265265
def is_sub_type(
266266
self,

tests/language/test_visitor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ def leave(self, *args):
209209
assert ast == parse("{ a, b, c { a, b, c } }", no_location=True)
210210
assert edited_ast == parse("{ a, c { a, c } }", no_location=True)
211211

212+
def ignores_false_returned_on_leave():
213+
ast = parse("{ a, b, c { a, b, c } }", no_location=True)
214+
215+
assert SKIP is False
216+
217+
# noinspection PyMethodMayBeStatic
218+
class TestVisitor(Visitor):
219+
def leave(self, *args):
220+
return SKIP
221+
222+
returned_ast = visit(ast, TestVisitor())
223+
assert returned_ast == parse("{ a, b, c { a, b, c } }", no_location=True)
224+
212225
def visits_edited_node():
213226
ast = parse("{ a { x } }", no_location=True)
214227
added_field = FieldNode(name=NameNode(value="__typename"))

tests/subscription/test_subscribe.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ async def empty_async_iterator(_info):
141141
for value in (): # type: ignore
142142
yield value
143143

144-
await subscribe(
144+
ai = await subscribe(
145145
email_schema, document, {"importantEmail": empty_async_iterator}
146146
)
147147

148+
with raises(StopAsyncIteration):
149+
await anext(ai)
150+
await ai.aclose() # type: ignore
151+
148152
@mark.asyncio
149153
async def accepts_multiple_subscription_fields_defined_in_schema():
150154
pubsub = EventEmitter()

tests/type/test_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def includes_interface_possible_types_in_the_type_map():
154154
assert schema.type_map["SomeInterface"] is SomeInterface
155155
assert schema.type_map["SomeSubtype"] is SomeSubtype
156156

157+
assert schema.is_sub_type(SomeInterface, SomeSubtype) is True
158+
assert schema.is_possible_type(SomeInterface, SomeSubtype) is True
159+
157160
def includes_interfaces_thunk_subtypes_in_the_type_map():
158161
AnotherInterface = GraphQLInterfaceType("AnotherInterface", {})
159162
SomeInterface = GraphQLInterfaceType(

tests/validation/test_validation.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pytest import raises # type: ignore
22

3+
from graphql.error import GraphQLError
34
from graphql.language import parse
4-
from graphql.utilities import TypeInfo
5-
from graphql.validation import ASTValidationRule, validate
5+
from graphql.utilities import TypeInfo, build_schema
6+
from graphql.validation import ValidationRule, validate
67

78
from .harness import test_schema
89

@@ -80,6 +81,36 @@ def validates_using_a_custom_type_info():
8081
" Did you mean 'isHouseTrained'?",
8182
]
8283

84+
def validates_using_a_custom_rule():
85+
schema = build_schema(
86+
"""
87+
directive @custom(arg: String) on FIELD
88+
89+
type Query {
90+
foo: String
91+
}
92+
"""
93+
)
94+
95+
doc = parse(
96+
"""
97+
query {
98+
name @custom
99+
}
100+
"""
101+
)
102+
103+
class CustomRule(ValidationRule):
104+
def enter_directive(self, node, *_args):
105+
directive_def = self.context.get_directive()
106+
error = GraphQLError("Reporting directive: " + str(directive_def), node)
107+
self.context.report_error(error)
108+
109+
errors = validate(schema, doc, [CustomRule])
110+
assert errors == [
111+
{"message": "Reporting directive: @custom", "locations": [(3, 20)]}
112+
]
113+
83114

84115
def describe_validate_limit_maximum_number_of_validation_errors():
85116
query = """
@@ -120,7 +151,7 @@ def when_max_errors_is_less_than_number_of_errors():
120151
]
121152

122153
def pass_through_exceptions_from_rules():
123-
class CustomRule(ASTValidationRule):
154+
class CustomRule(ValidationRule):
124155
def enter_field(self, *_args):
125156
raise RuntimeError("Error from custom rule!")
126157

0 commit comments

Comments
 (0)