Skip to content

Commit

Permalink
Bring coverage to 100% (upstream only)
Browse files Browse the repository at this point in the history
We still need to achieve 100% coverage in Python.

Replicates graphql/graphql-js@c54e141
  • Loading branch information
Cito committed Feb 10, 2020
1 parent 9b8ade4 commit a206db0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/graphql/type/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def is_possible_type(
Deprecated: Use is_sub_type() instead.
"""
return self.is_sub_type(abstract_type, possible_type) # pragma: no cover
return self.is_sub_type(abstract_type, possible_type)

def is_sub_type(
self,
Expand Down
13 changes: 13 additions & 0 deletions tests/language/test_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ def leave(self, *args):
assert ast == parse("{ a, b, c { a, b, c } }", no_location=True)
assert edited_ast == parse("{ a, c { a, c } }", no_location=True)

def ignores_false_returned_on_leave():
ast = parse("{ a, b, c { a, b, c } }", no_location=True)

assert SKIP is False

# noinspection PyMethodMayBeStatic
class TestVisitor(Visitor):
def leave(self, *args):
return SKIP

returned_ast = visit(ast, TestVisitor())
assert returned_ast == parse("{ a, b, c { a, b, c } }", no_location=True)

def visits_edited_node():
ast = parse("{ a { x } }", no_location=True)
added_field = FieldNode(name=NameNode(value="__typename"))
Expand Down
6 changes: 5 additions & 1 deletion tests/subscription/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ async def empty_async_iterator(_info):
for value in (): # type: ignore
yield value

await subscribe(
ai = await subscribe(
email_schema, document, {"importantEmail": empty_async_iterator}
)

with raises(StopAsyncIteration):
await anext(ai)
await ai.aclose() # type: ignore

@mark.asyncio
async def accepts_multiple_subscription_fields_defined_in_schema():
pubsub = EventEmitter()
Expand Down
3 changes: 3 additions & 0 deletions tests/type/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def includes_interface_possible_types_in_the_type_map():
assert schema.type_map["SomeInterface"] is SomeInterface
assert schema.type_map["SomeSubtype"] is SomeSubtype

assert schema.is_sub_type(SomeInterface, SomeSubtype) is True
assert schema.is_possible_type(SomeInterface, SomeSubtype) is True

def includes_interfaces_thunk_subtypes_in_the_type_map():
AnotherInterface = GraphQLInterfaceType("AnotherInterface", {})
SomeInterface = GraphQLInterfaceType(
Expand Down
37 changes: 34 additions & 3 deletions tests/validation/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pytest import raises # type: ignore

from graphql.error import GraphQLError
from graphql.language import parse
from graphql.utilities import TypeInfo
from graphql.validation import ASTValidationRule, validate
from graphql.utilities import TypeInfo, build_schema
from graphql.validation import ValidationRule, validate

from .harness import test_schema

Expand Down Expand Up @@ -80,6 +81,36 @@ def validates_using_a_custom_type_info():
" Did you mean 'isHouseTrained'?",
]

def validates_using_a_custom_rule():
schema = build_schema(
"""
directive @custom(arg: String) on FIELD
type Query {
foo: String
}
"""
)

doc = parse(
"""
query {
name @custom
}
"""
)

class CustomRule(ValidationRule):
def enter_directive(self, node, *_args):
directive_def = self.context.get_directive()
error = GraphQLError("Reporting directive: " + str(directive_def), node)
self.context.report_error(error)

errors = validate(schema, doc, [CustomRule])
assert errors == [
{"message": "Reporting directive: @custom", "locations": [(3, 20)]}
]


def describe_validate_limit_maximum_number_of_validation_errors():
query = """
Expand Down Expand Up @@ -120,7 +151,7 @@ def when_max_errors_is_less_than_number_of_errors():
]

def pass_through_exceptions_from_rules():
class CustomRule(ASTValidationRule):
class CustomRule(ValidationRule):
def enter_field(self, *_args):
raise RuntimeError("Error from custom rule!")

Expand Down

0 comments on commit a206db0

Please sign in to comment.