Skip to content

Commit

Permalink
Fix coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 11, 2024
1 parent b4f8261 commit ac56523
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
36 changes: 5 additions & 31 deletions src/graphql/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ async def execute_stream_async_iterator_item(
) -> Any:
"""Execute stream iterator item."""
if async_iterator in self._canceled_iterators:
raise StopAsyncIteration
raise StopAsyncIteration # pragma: no cover
try:
item = await anext(async_iterator)
except StopAsyncIteration as raw_error:
Expand Down Expand Up @@ -1682,7 +1682,6 @@ async def execute_stream_async_iterator(
parent_context: IncrementalDataRecord | None = None,
) -> None:
"""Execute stream iterator."""
is_awaitable = self.is_awaitable
incremental_publisher = self.incremental_publisher
index = initial_index
previous_incremental_data_record = parent_context
Expand Down Expand Up @@ -1722,35 +1721,10 @@ async def execute_stream_async_iterator(
except StopAsyncIteration:
done = True

if is_awaitable(completed_item):

async def await_completed_item(
incremental_data_record: StreamItemsRecord, completed_item: Any
) -> None:
try:
value = await completed_item
except GraphQLError as error:
incremental_publisher.add_field_error(
incremental_data_record, error
)
incremental_publisher.filter(path, incremental_data_record)
incremental_publisher.complete_stream_items_record(
incremental_data_record, None
)
else:
incremental_publisher.complete_stream_items_record(
incremental_data_record, [value]
)

self.add_task(
await_completed_item(incremental_data_record, completed_item)
)

else:
incremental_publisher.complete_stream_items_record(
incremental_data_record,
[completed_item],
)
incremental_publisher.complete_stream_items_record(
incremental_data_record,
[completed_item],
)

if done:
break
Expand Down
6 changes: 4 additions & 2 deletions src/graphql/execution/incremental_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ async def subscribe(
finally:
close_async_iterators = []
for incremental_data_record in pending:
if isinstance(incremental_data_record, StreamItemsRecord):
if isinstance(
incremental_data_record, StreamItemsRecord
): # pragma: no cover
async_iterator = incremental_data_record.async_iterator
if async_iterator:
try:
Expand Down Expand Up @@ -508,7 +510,7 @@ def filter(
if async_iterator:
try:
close_async_iterator = async_iterator.aclose() # type:ignore
except AttributeError:
except AttributeError: # pragma: no cover
pass
else:
self._add_task(close_async_iterator)
Expand Down
1 change: 1 addition & 0 deletions tests/execution/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def resolve_error(*_args):
],
)

@pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning")
def uses_the_inline_operation_if_no_operation_name_is_provided():
schema = GraphQLSchema(
GraphQLObjectType("Type", {"a": GraphQLField(GraphQLString)})
Expand Down

0 comments on commit ac56523

Please sign in to comment.