Skip to content

Commit 961d626

Browse files
committed
Enforce 100% test coverage
1 parent 617bb04 commit 961d626

File tree

8 files changed

+46
-19
lines changed

8 files changed

+46
-19
lines changed

Diff for: src/graphql_relay/mutation/mutation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any, Callable, Dict, Optional
33

44
from graphql import (
5-
GraphQLError,
65
GraphQLArgument,
76
GraphQLField,
87
GraphQLFieldMap,
@@ -15,7 +14,7 @@
1514
GraphQLString,
1615
Thunk,
1716
)
18-
from graphql.pyutils import AwaitableOrValue, inspect
17+
from graphql.pyutils import AwaitableOrValue
1918

2019
# Note: Contrary to the Javascript implementation of MutationFn,
2120
# the context is passed as part of the GraphQLResolveInfo and any arguments

Diff for: tests/connection/test_array_connection.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,21 @@ def returns_an_edges_cursor_given_an_array_without_index_method():
400400
class LettersWithoutIndex:
401401
__getitem__ = letters.__getitem__
402402

403-
letters_without_index = LettersWithoutIndex()
403+
letters_without_index = cast(Sequence, LettersWithoutIndex())
404404

405405
with raises(AttributeError):
406-
cast(Sequence, letters_without_index).index("B")
406+
letters_without_index.index("B")
407407

408408
letter_b_cursor = cursor_for_object_in_connection(
409-
cast(Sequence, letters_without_index), "B"
409+
letters_without_index, "B"
410410
)
411411
assert letter_b_cursor == "YXJyYXljb25uZWN0aW9uOjE="
412412

413+
no_letter_cursor = cursor_for_object_in_connection(
414+
letters_without_index, "="
415+
)
416+
assert no_letter_cursor is None
417+
413418
def describe_extended_functionality():
414419
"""Test functionality that is not part of graphql-relay-js."""
415420

Diff for: tests/mutation/test_mutation.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,36 @@ def can_access_root_value():
154154
)
155155

156156
def supports_mutations_returning_null():
157+
def null_resolve(_info, **_input) -> None:
158+
return None
159+
160+
some_mutation = mutation_with_client_mutation_id(
161+
"SomeMutation", {}, {"result": GraphQLField(GraphQLInt)}, null_resolve
162+
)
163+
schema = wrap_in_schema({"someMutation": some_mutation})
164+
source = """
165+
mutation {
166+
someMutation(input: {clientMutationId: "abc"}) {
167+
result
168+
clientMutationId
169+
}
170+
}
171+
"""
172+
assert graphql_sync(schema, source) == (
173+
{"someMutation": {"result": None, "clientMutationId": "abc"}},
174+
None,
175+
)
176+
177+
@mark.asyncio
178+
async def supports_async_mutations_returning_null():
179+
async def null_resolve(_info, **_input) -> None:
180+
return None
181+
157182
some_mutation = mutation_with_client_mutation_id(
158183
"SomeMutation",
159184
{},
160185
{"result": GraphQLField(GraphQLInt)},
161-
lambda _info, **_input: None,
186+
null_resolve,
162187
)
163188
schema = wrap_in_schema({"someMutation": some_mutation})
164189
source = """
@@ -169,7 +194,7 @@ def supports_mutations_returning_null():
169194
}
170195
}
171196
"""
172-
assert graphql_sync(schema, source) == (
197+
assert await graphql(schema, source) == (
173198
{"someMutation": {"result": None, "clientMutationId": "abc"}},
174199
None,
175200
)

Diff for: tests/node/test_global.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_node(global_id: str, info: GraphQLResolveInfo) -> Any:
6464
)
6565
if type_ == "Post":
6666
return next(filter(lambda obj: obj["id"] == id_, post_data), None)
67-
return None
67+
return None # pragma: no cover
6868

6969
def get_node_type(
7070
obj: Any, info: GraphQLResolveInfo, _type: Any
@@ -76,7 +76,7 @@ def get_node_type(
7676
return photo_type
7777
if "text" in obj:
7878
return post_type
79-
return None
79+
return None # pragma: no cover
8080

8181
else:
8282

@@ -89,7 +89,7 @@ def get_node(global_id: str, info: GraphQLResolveInfo) -> Any:
8989
return next(filter(lambda obj: obj.photo_id == id_, photo_data), None)
9090
if type_ == "Post":
9191
return next(filter(lambda obj: obj.id == id_, post_data), None)
92-
return None
92+
return None # pragma: no cover
9393

9494
def get_node_type(
9595
obj: Any, info: GraphQLResolveInfo, _type: Any
@@ -101,7 +101,7 @@ def get_node_type(
101101
return photo_type
102102
if isinstance(obj, Post):
103103
return post_type
104-
return None
104+
return None # pragma: no cover
105105

106106
node_interface, node_field = node_definitions(get_node, get_node_type)[:2]
107107

Diff for: tests/node/test_node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_node_type(
5353
return user_type
5454
if obj in photo_data:
5555
return photo_type
56-
return None
56+
return None # pragma: no cover
5757

5858

5959
node_interface, node_field, nodes_field = node_definitions(get_node, get_node_type)

Diff for: tests/star_wars_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_ship(ship_name: str, faction_id: str) -> Ship:
4444
new_ship = Ship(str(len(all_ships) + 1), ship_name)
4545
all_ships.append(new_ship)
4646
faction = get_faction(faction_id)
47-
if faction:
47+
if faction: # pragma: no cover else
4848
faction.ships.append(new_ship.id)
4949
return new_ship
5050

Diff for: tests/star_wars_schema.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,15 @@ def get_node(global_id, _info):
103103
type_, id_ = from_global_id(global_id)
104104
if type_ == "Faction":
105105
return get_faction(id_)
106-
elif type_ == "Ship":
106+
if type_ == "Ship":
107107
return get_ship(id_)
108-
else:
109-
return None
108+
return None # pragma: no cover
110109

111110

112111
def get_node_type(obj, _info, _type):
113112
if isinstance(obj, Faction):
114113
return factionType
115-
else:
116-
return shipType
114+
return shipType
117115

118116

119117
node_interface, node_field = node_definitions(get_node, get_node_type)[:2]

Diff for: tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ deps =
4444
pytest-describe>=2,<3
4545
py36,py37: typing-extensions>=4,<5
4646
commands =
47-
pytest tests {posargs: --cov-report=term-missing --cov=graphql_relay --cov=tests --cov-fail-under=98}
47+
pytest tests {posargs: --cov-report=term-missing --cov=graphql_relay --cov=tests --cov-fail-under=100}

0 commit comments

Comments
 (0)