Skip to content

Commit 0ecb1eb

Browse files
committed
Tests for invalid and format_error
1 parent b85ae7c commit 0ecb1eb

File tree

10 files changed

+60
-8
lines changed

10 files changed

+60
-8
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

1414
The current version 1.0.0rc2 of GraphQL-core-next is up-to-date with GraphQL.js
1515
version 14.0.0rc2. All parts of the API are covered by an extensive test
16-
suite of currently 1562 unit tests.
16+
suite of currently 1569 unit tests.
1717

1818

1919
## Documentation

graphql/error/format_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, TYPE_CHECKING
22

3-
if TYPE_CHECKING:
3+
if TYPE_CHECKING: # pragma: no cover
44
from .graphql_error import GraphQLError # noqa: F401
55

66

graphql/error/graphql_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .format_error import format_error
44
from .print_error import print_error
55

6-
if TYPE_CHECKING:
6+
if TYPE_CHECKING: # pragma: no cover
77
from ..language.ast import Node # noqa
88
from ..language.location import SourceLocation # noqa
99
from ..language.source import Source # noqa

graphql/error/located_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .graphql_error import GraphQLError
44

5-
if TYPE_CHECKING:
5+
if TYPE_CHECKING: # pragma: no cover
66
from ..language.ast import Node # noqa
77

88
__all__ = ['located_error']

graphql/error/print_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import reduce
33
from typing import List, Optional, Tuple, TYPE_CHECKING
44

5-
if TYPE_CHECKING:
5+
if TYPE_CHECKING: # pragma: no cover
66
from .graphql_error import GraphQLError # noqa: F401
77
from ..language import Source, SourceLocation # noqa: F401
88

graphql/language/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import NamedTuple, TYPE_CHECKING
22

3-
if TYPE_CHECKING:
3+
if TYPE_CHECKING: # pragma: no cover
44
from .source import Source # noqa: F401
55

66
__all__ = ['get_location', 'SourceLocation']

graphql/language/visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .ast import Node
99

10-
if TYPE_CHECKING:
10+
if TYPE_CHECKING: # pragma: no cover
1111
from ..utilities import TypeInfo # noqa: F401
1212

1313
__all__ = [

graphql/type/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ..pyutils import MaybeAwaitable, cached_property
1919
from ..utilities.value_from_ast_untyped import value_from_ast_untyped
2020

21-
if TYPE_CHECKING:
21+
if TYPE_CHECKING: # pragma: no cover
2222
from .schema import GraphQLSchema # noqa: F401
2323

2424
__all__ = [

tests/error/test_format_error.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pytest import raises
2+
3+
from graphql.error import GraphQLError, format_error
4+
from graphql.language import Node, Source
5+
6+
7+
def describe_format_error():
8+
9+
def throw_if_not_an_error():
10+
with raises(ValueError):
11+
format_error(None)
12+
13+
def format_graphql_error():
14+
source = Source("""
15+
query {
16+
something
17+
}""")
18+
path = ['one', 2]
19+
extensions = {'ext': None}
20+
error = GraphQLError(
21+
'test message', Node(), source, [14, 40], path,
22+
ValueError('original'), extensions=extensions)
23+
assert error == {
24+
'message': 'test message', 'locations': [(2, 14), (3, 20)],
25+
'path': path, 'extensions': extensions}
26+
27+
def add_default_message():
28+
error = format_error(GraphQLError(None))
29+
assert error['message'] == 'An unknown error occurred.'

tests/error/test_invalid.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from graphql.error import INVALID
2+
3+
4+
def describe_invalid():
5+
6+
def has_repr():
7+
assert repr(INVALID) == '<INVALID>'
8+
9+
def has_str():
10+
assert str(INVALID) == 'INVALID'
11+
12+
def as_bool_is_false():
13+
assert bool(INVALID) is False
14+
15+
def only_equal_to_itself():
16+
assert INVALID == INVALID
17+
assert not INVALID != INVALID
18+
none_object = None
19+
assert INVALID != none_object
20+
assert not INVALID == none_object
21+
false_object = False
22+
assert INVALID != false_object
23+
assert not INVALID == false_object

0 commit comments

Comments
 (0)