Skip to content

Commit 7c72a38

Browse files
committed
Improve coverage in tests
1 parent 2744051 commit 7c72a38

21 files changed

+84
-87
lines changed

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ omit =
88
[report]
99
exclude_lines =
1010
pragma: no cover
11-
pragma: false coverage
1211
raise NotImplementedError
1312
raise TypeError\(f?"Unexpected
13+
assert False,
1414
if MYPY:
1515
if TYPE_CHECKING:
16-
^\s+...$
16+
^\s+\.\.\.$
1717
^\s+pass$
1818
ignore_errors = True

src/graphql/execution/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def collect_fields(
487487
fields,
488488
visited_fragment_names,
489489
)
490-
elif isinstance(selection, FragmentSpreadNode): # pragma: no cover
490+
elif isinstance(selection, FragmentSpreadNode): # pragma: no cover else
491491
frag_name = selection.name.value
492492
if frag_name in visited_fragment_names or not self.should_include_node(
493493
selection

src/graphql/execution/values.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def coerce_variable_values(
9696
coerced_values[var_name] = value_from_ast(
9797
var_def_node.default_value, var_type
9898
)
99-
elif is_non_null_type(var_type): # pragma: false coverage
99+
elif is_non_null_type(var_type): # pragma: no cover else
100100
var_type_str = inspect(var_type)
101101
on_error(
102102
GraphQLError(
@@ -163,13 +163,13 @@ def get_argument_values(
163163
if argument_node is None:
164164
if arg_def.default_value is not Undefined:
165165
coerced_values[arg_def.out_name or name] = arg_def.default_value
166-
elif is_non_null_type(arg_type):
166+
elif is_non_null_type(arg_type): # pragma: no cover else
167167
raise GraphQLError(
168168
f"Argument '{name}' of required type '{arg_type}'"
169169
" was not provided.",
170170
node,
171171
)
172-
continue # pragma: false coverage
172+
continue # pragma: no cover
173173

174174
value_node = argument_node.value
175175
is_null = isinstance(argument_node.value, NullValueNode)
@@ -179,14 +179,14 @@ def get_argument_values(
179179
if variable_values is None or variable_name not in variable_values:
180180
if arg_def.default_value is not Undefined:
181181
coerced_values[arg_def.out_name or name] = arg_def.default_value
182-
elif is_non_null_type(arg_type):
182+
elif is_non_null_type(arg_type): # pragma: no cover else
183183
raise GraphQLError(
184184
f"Argument '{name}' of required type '{arg_type}'"
185185
f" was provided the variable '${variable_name}'"
186186
" which was not provided a runtime value.",
187187
value_node,
188188
)
189-
continue # pragma: false coverage
189+
continue # pragma: no cover
190190
is_null = variable_values[variable_name] is None
191191

192192
if is_null and is_non_null_type(arg_type):

src/graphql/utilities/build_client_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_interface_type(type_ref: Dict) -> GraphQLInterfaceType:
122122
def build_type(type_: Dict) -> GraphQLNamedType:
123123
if type_ and "name" in type_ and "kind" in type_:
124124
builder = type_builders.get(cast(str, type_["kind"]))
125-
if builder:
125+
if builder: # pragma: no cover else
126126
return cast(GraphQLNamedType, builder(type_))
127127
raise TypeError(
128128
"Invalid or incomplete introspection result."

src/graphql/utilities/coerce_input_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def coerce_input_value(
9898
if field.default_value is not Undefined:
9999
# Use out name as name if it exists (extension of GraphQL.js).
100100
coerced_dict[field.out_name or field_name] = field.default_value
101-
elif is_non_null_type(field.type):
101+
elif is_non_null_type(field.type): # pragma: no cover else
102102
type_str = inspect(field.type)
103103
on_error(
104104
path.as_list() if path else [],

src/graphql/utilities/introspection_from_schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def introspection_from_schema(
2929
result = execute(schema, document)
3030
if not isinstance(result, ExecutionResult): # pragma: no cover
3131
raise RuntimeError("Introspection cannot be executed")
32-
if result.errors or not result.data:
33-
raise result.errors[0] if result.errors else GraphQLError(
34-
"Introspection did not return a result"
35-
)
32+
if result.errors: # pragma: no cover
33+
raise result.errors[0]
34+
if not result.data: # pragma: no cover
35+
raise GraphQLError("Introspection did not return a result")
3636
return result.data

src/graphql/utilities/value_from_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def value_from_ast(
110110
if field.default_value is not Undefined:
111111
# Use out name as name if it exists (extension of GraphQL.js).
112112
coerced_obj[field.out_name or field_name] = field.default_value
113-
elif is_non_null_type(field.type): # pragma: false coverage
113+
elif is_non_null_type(field.type): # pragma: no cover else
114114
return Undefined
115115
continue
116116
field_value = value_from_ast(field_node.value, field.type, variables)

src/graphql/validation/rules/known_directives.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,18 @@ def enter_directive(self, node: DirectiveNode, _key, _parent, _path, ancestors):
9191

9292
def get_directive_location_for_ast_path(ancestors):
9393
applied_to = ancestors[-1]
94-
if isinstance(applied_to, Node):
95-
kind = applied_to.kind
96-
if kind == "operation_definition":
97-
applied_to = cast(OperationDefinitionNode, applied_to)
98-
return _operation_location[applied_to.operation.value]
99-
elif kind == "input_value_definition":
100-
parent_node = ancestors[-3]
101-
return (
102-
DirectiveLocation.INPUT_FIELD_DEFINITION
103-
if parent_node.kind == "input_object_type_definition"
104-
else DirectiveLocation.ARGUMENT_DEFINITION
105-
)
106-
else:
107-
return _directive_location.get(kind)
94+
if not isinstance(applied_to, Node): # pragma: no cover
95+
raise TypeError("Unexpected error in directive.")
96+
kind = applied_to.kind
97+
if kind == "operation_definition":
98+
applied_to = cast(OperationDefinitionNode, applied_to)
99+
return _operation_location[applied_to.operation.value]
100+
elif kind == "input_value_definition":
101+
parent_node = ancestors[-3]
102+
return (
103+
DirectiveLocation.INPUT_FIELD_DEFINITION
104+
if parent_node.kind == "input_object_type_definition"
105+
else DirectiveLocation.ARGUMENT_DEFINITION
106+
)
107+
else:
108+
return _directive_location.get(kind)

src/graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def collect_fields_and_fragment_names(
690690
)
691691
elif isinstance(selection, FragmentSpreadNode):
692692
fragment_names[selection.name.value] = True
693-
elif isinstance(selection, InlineFragmentNode):
693+
elif isinstance(selection, InlineFragmentNode): # pragma: no cover else
694694
type_condition = selection.type_condition
695695
inline_fragment_type = (
696696
type_from_ast(context.schema, type_condition)

tests/pyutils/test_inspect.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def overly_large_int():
100100
assert inspect(n) == r
101101

102102
def inspect_function():
103-
assert inspect(lambda: 0) == "<function>"
103+
assert inspect(lambda: 0) == "<function>" # pragma: no cover
104104

105105
def test_func():
106-
return None
106+
pass
107107

108108
assert inspect(test_func) == "<function test_func>"
109109

@@ -114,7 +114,7 @@ def inspect_exception():
114114
def inspect_class_and_method():
115115
class TestClass:
116116
def test_method(self):
117-
return None
117+
pass
118118

119119
assert inspect(TestClass) == "<class TestClass>"
120120
assert inspect(TestClass()) == "<TestClass instance>"
@@ -132,15 +132,15 @@ class TestClass(metaclass=MetaClass):
132132

133133
def inspect_generator():
134134
def test_generator():
135-
yield None
135+
yield None # pragma: no cover
136136

137137
assert inspect(test_generator) == "<generator function test_generator>"
138138
assert inspect(test_generator()) == "<generator test_generator>"
139139

140140
@mark.asyncio
141141
async def inspect_coroutine():
142142
async def test_coroutine():
143-
return None
143+
pass
144144

145145
assert inspect(test_coroutine) == "<coroutine function test_coroutine>"
146146
coroutine_object = test_coroutine()
@@ -149,7 +149,7 @@ async def test_coroutine():
149149

150150
def inspect_async_generator():
151151
async def test_async_generator():
152-
yield None
152+
yield None # pragma: no cover
153153

154154
assert inspect(test_async_generator) == (
155155
"<async generator function test_async_generator>"

0 commit comments

Comments
 (0)