From 448d0455e26441e54405413729e501324c20de4a Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Sat, 7 Sep 2024 19:39:39 +0200 Subject: [PATCH] Update ruff and adapt code style --- pyproject.toml | 2 +- src/graphql/execution/execute.py | 2 +- src/graphql/pyutils/suggestion_list.py | 3 +- tests/execution/test_abstract.py | 1 + tests/execution/test_customize.py | 7 +- tests/execution/test_defer.py | 39 +++++---- tests/execution/test_execution_result.py | 1 + tests/execution/test_executor.py | 9 +- tests/execution/test_lists.py | 29 ++++--- tests/execution/test_map_async_iterable.py | 31 +++---- tests/execution/test_middleware.py | 7 +- tests/execution/test_mutations.py | 11 +-- tests/execution/test_nonnull.py | 21 ++--- tests/execution/test_parallel.py | 11 +-- tests/execution/test_stream.py | 87 ++++++++++--------- tests/execution/test_subscribe.py | 55 ++++++------ tests/execution/test_sync.py | 15 ++-- tests/language/test_block_string_fuzz.py | 3 +- tests/language/test_lexer.py | 1 + tests/language/test_parser.py | 1 + tests/language/test_printer.py | 1 + tests/language/test_schema_parser.py | 1 + tests/language/test_schema_printer.py | 1 + tests/language/test_source.py | 1 + tests/language/test_visitor.py | 1 + tests/pyutils/test_async_reduce.py | 9 +- tests/pyutils/test_description.py | 1 + tests/pyutils/test_format_list.py | 1 + tests/pyutils/test_inspect.py | 3 +- tests/pyutils/test_is_awaitable.py | 7 +- tests/pyutils/test_simple_pub_sub.py | 9 +- tests/pyutils/test_undefined.py | 1 + tests/star_wars_schema.py | 1 - tests/test_star_wars_query.py | 37 ++++---- tests/test_user_registry.py | 13 +-- tests/type/test_assert_name.py | 1 + tests/type/test_definition.py | 1 + tests/type/test_directives.py | 1 + tests/type/test_extensions.py | 1 + tests/type/test_predicate.py | 1 + tests/type/test_scalars.py | 1 + tests/type/test_schema.py | 1 + tests/type/test_validation.py | 1 + tests/utilities/test_ast_from_value.py | 1 + tests/utilities/test_build_client_schema.py | 1 + tests/utilities/test_coerce_input_value.py | 1 + tests/utilities/test_extend_schema.py | 1 + .../test_introspection_from_schema.py | 3 +- .../test_strip_ignored_characters.py | 1 + .../test_strip_ignored_characters_fuzz.py | 21 ++--- tests/utilities/test_type_from_ast.py | 1 + .../test_assert_equal_awaitables_or_values.py | 6 +- tests/validation/test_validation.py | 1 + tox.ini | 2 +- 54 files changed, 258 insertions(+), 212 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3b9342b1..c3c2367c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,7 @@ tox = [ optional = true [tool.poetry.group.lint.dependencies] -ruff = ">=0.5.7,<0.6" +ruff = ">=0.6.4,<0.7" mypy = [ { version = "^1.11", python = ">=3.8" }, { version = "~1.4", python = "<3.8" } diff --git a/src/graphql/execution/execute.py b/src/graphql/execution/execute.py index e370bcc1..ae56c9b9 100644 --- a/src/graphql/execution/execute.py +++ b/src/graphql/execution/execute.py @@ -96,7 +96,7 @@ anext # noqa: B018 except NameError: # pragma: no cover (Python < 3.10) # noinspection PyShadowingBuiltins - async def anext(iterator: AsyncIterator) -> Any: # noqa: A001 + async def anext(iterator: AsyncIterator) -> Any: """Return the next item from an async iterator.""" return await iterator.__anext__() diff --git a/src/graphql/pyutils/suggestion_list.py b/src/graphql/pyutils/suggestion_list.py index 6abeefed..35240c77 100644 --- a/src/graphql/pyutils/suggestion_list.py +++ b/src/graphql/pyutils/suggestion_list.py @@ -99,8 +99,7 @@ def measure(self, option: str, threshold: int) -> int | None: double_diagonal_cell = rows[(i - 2) % 3][j - 2] current_cell = min(current_cell, double_diagonal_cell + 1) - if current_cell < smallest_cell: - smallest_cell = current_cell + smallest_cell = min(current_cell, smallest_cell) current_row[j] = current_cell diff --git a/tests/execution/test_abstract.py b/tests/execution/test_abstract.py index b5ebc45b..d7d12b7a 100644 --- a/tests/execution/test_abstract.py +++ b/tests/execution/test_abstract.py @@ -3,6 +3,7 @@ from typing import Any, NamedTuple import pytest + from graphql.execution import ExecutionResult, execute, execute_sync from graphql.language import parse from graphql.pyutils import is_awaitable diff --git a/tests/execution/test_customize.py b/tests/execution/test_customize.py index 23740237..85462147 100644 --- a/tests/execution/test_customize.py +++ b/tests/execution/test_customize.py @@ -1,6 +1,7 @@ from inspect import isasyncgen import pytest + from graphql.execution import ExecutionContext, execute, subscribe from graphql.language import parse from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString @@ -9,7 +10,7 @@ anext # noqa: B018 except NameError: # pragma: no cover (Python < 3.10) # noinspection PyShadowingBuiltins - async def anext(iterator): # noqa: A001 + async def anext(iterator): """Return the next item from an async iterator.""" return await iterator.__anext__() @@ -62,7 +63,7 @@ def execute_field( def describe_customize_subscription(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def uses_a_custom_subscribe_field_resolver(): schema = GraphQLSchema( query=GraphQLObjectType("Query", {"foo": GraphQLField(GraphQLString)}), @@ -91,7 +92,7 @@ async def custom_foo(): await subscription.aclose() - @pytest.mark.asyncio() + @pytest.mark.asyncio async def uses_a_custom_execution_context_class(): class TestExecutionContext(ExecutionContext): def build_resolve_info(self, *args, **kwargs): diff --git a/tests/execution/test_defer.py b/tests/execution/test_defer.py index 6b39f74e..312a2a0b 100644 --- a/tests/execution/test_defer.py +++ b/tests/execution/test_defer.py @@ -4,6 +4,7 @@ from typing import Any, AsyncGenerator, NamedTuple import pytest + from graphql.error import GraphQLError from graphql.execution import ( ExecutionResult, @@ -333,7 +334,7 @@ def can_print_deferred_fragment_record(): "path=['bar'], label='foo', parent_context, data)" ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_fragments_containing_scalar_types(): document = parse( """ @@ -358,7 +359,7 @@ async def can_defer_fragments_containing_scalar_types(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_disable_defer_using_if_argument(): document = parse( """ @@ -384,7 +385,7 @@ async def can_disable_defer_using_if_argument(): }, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def does_not_disable_defer_with_null_if_argument(): document = parse( """ @@ -409,7 +410,7 @@ async def does_not_disable_defer_with_null_if_argument(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws_an_error_for_defer_directive_with_non_string_label(): document = parse( """ @@ -430,7 +431,7 @@ async def throws_an_error_for_defer_directive_with_non_string_label(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_fragments_on_the_top_level_query_field(): document = parse( """ @@ -456,7 +457,7 @@ async def can_defer_fragments_on_the_top_level_query_field(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_fragments_with_errors_on_the_top_level_query_field(): document = parse( """ @@ -493,7 +494,7 @@ async def can_defer_fragments_with_errors_on_the_top_level_query_field(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_a_fragment_within_an_already_deferred_fragment(): document = parse( """ @@ -540,7 +541,7 @@ async def can_defer_a_fragment_within_an_already_deferred_fragment(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_a_fragment_that_is_also_not_deferred_with_deferred_first(): document = parse( """ @@ -571,7 +572,7 @@ async def can_defer_a_fragment_that_is_also_not_deferred_with_deferred_first(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_a_fragment_that_is_also_not_deferred_with_non_deferred_first(): document = parse( """ @@ -602,7 +603,7 @@ async def can_defer_a_fragment_that_is_also_not_deferred_with_non_deferred_first }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_an_inline_fragment(): document = parse( """ @@ -632,7 +633,7 @@ async def can_defer_an_inline_fragment(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_errors_thrown_in_deferred_fragments(): document = parse( """ @@ -669,7 +670,7 @@ async def handles_errors_thrown_in_deferred_fragments(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_non_nullable_errors_thrown_in_deferred_fragments(): document = parse( """ @@ -709,7 +710,7 @@ async def handles_non_nullable_errors_thrown_in_deferred_fragments(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_non_nullable_errors_thrown_outside_deferred_fragments(): document = parse( """ @@ -740,7 +741,7 @@ async def handles_non_nullable_errors_thrown_outside_deferred_fragments(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_non_nullable_errors_thrown_in_deferred_fragments(): document = parse( """ @@ -780,7 +781,7 @@ async def handles_async_non_nullable_errors_thrown_in_deferred_fragments(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_payloads_in_correct_order(): document = parse( """ @@ -833,7 +834,7 @@ async def returns_payloads_in_correct_order(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_payloads_from_synchronous_data_in_correct_order(): document = parse( """ @@ -886,7 +887,7 @@ async def returns_payloads_from_synchronous_data_in_correct_order(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def filters_deferred_payloads_when_list_item_from_async_iterable_nulled(): document = parse( """ @@ -920,7 +921,7 @@ async def filters_deferred_payloads_when_list_item_from_async_iterable_nulled(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def original_execute_function_throws_error_if_deferred_and_all_is_sync(): document = parse( """ @@ -938,7 +939,7 @@ async def original_execute_function_throws_error_if_deferred_and_all_is_sync(): " multiple payloads (due to @defer or @stream directive)" ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def original_execute_function_throws_error_if_deferred_and_not_all_is_sync(): document = parse( """ diff --git a/tests/execution/test_execution_result.py b/tests/execution/test_execution_result.py index 28ba17af..162bd00d 100644 --- a/tests/execution/test_execution_result.py +++ b/tests/execution/test_execution_result.py @@ -1,4 +1,5 @@ import pytest + from graphql.error import GraphQLError from graphql.execution import ExecutionResult diff --git a/tests/execution/test_executor.py b/tests/execution/test_executor.py index 5ea1f25b..792066f1 100644 --- a/tests/execution/test_executor.py +++ b/tests/execution/test_executor.py @@ -4,6 +4,7 @@ from typing import Any, Awaitable, cast import pytest + from graphql.error import GraphQLError from graphql.execution import execute, execute_sync from graphql.language import FieldNode, OperationDefinitionNode, parse @@ -41,7 +42,7 @@ def accepts_positional_arguments(): assert result == ({"a": "rootValue"}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def executes_arbitrary_code(): # noinspection PyMethodMayBeStatic,PyMethodMayBeStatic class Data: @@ -375,7 +376,7 @@ def resolve(_obj, _info, **args): assert len(resolved_args) == 1 assert resolved_args[0] == {"numArg": 123, "stringArg": "foo"} - @pytest.mark.asyncio() + @pytest.mark.asyncio async def nulls_out_error_subtrees(): document = parse( """ @@ -868,7 +869,7 @@ def resolves_to_an_error_if_schema_does_not_support_operation(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def correct_field_ordering_despite_execution_order(): schema = GraphQLSchema( GraphQLObjectType( @@ -984,7 +985,7 @@ def does_not_include_arguments_that_were_not_set(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def fails_when_is_type_of_check_is_not_met(): class Special: value: str diff --git a/tests/execution/test_lists.py b/tests/execution/test_lists.py index 3d2bb8fa..5dc4b5f0 100644 --- a/tests/execution/test_lists.py +++ b/tests/execution/test_lists.py @@ -1,6 +1,7 @@ from typing import Any, AsyncGenerator import pytest + from graphql.execution import ExecutionResult, execute, execute_sync from graphql.language import parse from graphql.pyutils import is_awaitable @@ -171,7 +172,7 @@ async def _list_field( assert is_awaitable(result) return await result - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_an_async_generator_as_a_list_value(): async def list_field(): yield "two" @@ -183,7 +184,7 @@ async def list_field(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_a_custom_async_iterable_as_a_list_value(): class ListField: def __aiter__(self): @@ -202,7 +203,7 @@ async def __anext__(self): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_an_async_generator_that_throws(): async def list_field(): yield "two" @@ -214,7 +215,7 @@ async def list_field(): [{"message": "bad", "locations": [(1, 3)], "path": ["listField"]}], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_an_async_generator_where_intermediate_value_triggers_an_error(): async def list_field(): yield "two" @@ -232,7 +233,7 @@ async def list_field(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_errors_from_complete_value_in_async_iterables(): async def list_field(): yield "two" @@ -249,7 +250,7 @@ async def list_field(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_functions_from_complete_value_in_async_iterables(): async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: return data.index @@ -259,7 +260,7 @@ async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_single_async_functions_from_complete_value_in_async_iterables(): async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: return data.index @@ -269,7 +270,7 @@ async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_errors_from_complete_value_in_async_iterables(): async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: index = data.index @@ -288,7 +289,7 @@ async def resolve(data: _IndexData, _info: GraphQLResolveInfo) -> int: ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_nulls_yielded_by_async_generator(): async def list_field(): yield 1 @@ -322,7 +323,7 @@ def execute_query(list_value: Any) -> Any: return result - @pytest.mark.asyncio() + @pytest.mark.asyncio async def contains_values(): list_field = [1, 2] assert await _complete(list_field, "[Int]") == ({"listField": [1, 2]}, None) @@ -330,7 +331,7 @@ async def contains_values(): assert await _complete(list_field, "[Int!]") == ({"listField": [1, 2]}, None) assert await _complete(list_field, "[Int!]!") == ({"listField": [1, 2]}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def contains_null(): list_field = [1, None, 2] errors = [ @@ -351,7 +352,7 @@ async def contains_null(): assert await _complete(list_field, "[Int!]") == ({"listField": None}, errors) assert await _complete(list_field, "[Int!]!") == (None, errors) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_null(): list_field = None errors = [ @@ -366,7 +367,7 @@ async def returns_null(): assert await _complete(list_field, "[Int!]") == ({"listField": None}, None) assert await _complete(list_field, "[Int!]!") == (None, errors) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def contains_error(): list_field = [1, RuntimeError("bad"), 2] errors = [ @@ -393,7 +394,7 @@ async def contains_error(): errors, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def results_in_errors(): list_field = RuntimeError("bad") errors = [ diff --git a/tests/execution/test_map_async_iterable.py b/tests/execution/test_map_async_iterable.py index 055a61bc..eb3cddb8 100644 --- a/tests/execution/test_map_async_iterable.py +++ b/tests/execution/test_map_async_iterable.py @@ -1,11 +1,12 @@ import pytest + from graphql.execution import map_async_iterable try: # pragma: no cover anext # noqa: B018 except NameError: # pragma: no cover (Python < 3.10) # noinspection PyShadowingBuiltins - async def anext(iterator): # noqa: A001 + async def anext(iterator): """Return the next item from an async iterator.""" return await iterator.__anext__() @@ -21,7 +22,7 @@ async def throw(_x: int) -> int: def describe_map_async_iterable(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def maps_over_async_generator(): async def source(): yield 1 @@ -36,7 +37,7 @@ async def source(): with pytest.raises(StopAsyncIteration): assert await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def maps_over_async_iterable(): items = [1, 2, 3] @@ -57,7 +58,7 @@ async def __anext__(self): assert not items assert values == [2, 4, 6] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def compatible_with_async_for(): async def source(): yield 1 @@ -70,7 +71,7 @@ async def source(): assert values == [2, 4, 6] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_returning_early_from_mapped_async_generator(): async def source(): yield 1 @@ -91,7 +92,7 @@ async def source(): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_returning_early_from_mapped_async_iterable(): items = [1, 2, 3] @@ -119,7 +120,7 @@ async def __anext__(self): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_throwing_errors_through_async_iterable(): items = [1, 2, 3] @@ -150,7 +151,7 @@ async def __anext__(self): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_throwing_errors_with_traceback_through_async_iterables(): class Iterable: def __aiter__(self): @@ -177,7 +178,7 @@ async def __anext__(self): with pytest.raises(StopAsyncIteration): await anext(one) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def does_not_map_over_thrown_errors(): async def source(): yield 1 @@ -192,7 +193,7 @@ async def source(): assert str(exc_info.value) == "Goodbye" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def does_not_map_over_externally_thrown_errors(): async def source(): yield 1 @@ -206,7 +207,7 @@ async def source(): assert str(exc_info.value) == "Goodbye" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterable_is_closed_when_mapped_iterable_is_closed(): class Iterable: def __init__(self): @@ -230,7 +231,7 @@ async def aclose(self): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterable_is_closed_on_callback_error(): class Iterable: def __init__(self): @@ -253,7 +254,7 @@ async def aclose(self): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterable_exits_on_callback_error(): exited = False @@ -272,7 +273,7 @@ async def iterable(): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def mapped_iterable_is_closed_when_iterable_cannot_be_closed(): class Iterable: def __aiter__(self): @@ -287,7 +288,7 @@ async def __anext__(self): with pytest.raises(StopAsyncIteration): await anext(doubles) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def ignores_that_iterable_cannot_be_closed_on_callback_error(): class Iterable: def __aiter__(self): diff --git a/tests/execution/test_middleware.py b/tests/execution/test_middleware.py index d4abba95..291f218c 100644 --- a/tests/execution/test_middleware.py +++ b/tests/execution/test_middleware.py @@ -2,6 +2,7 @@ from typing import Awaitable, cast import pytest + from graphql.execution import Middleware, MiddlewareManager, execute, subscribe from graphql.language.parser import parse from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString @@ -90,7 +91,7 @@ def capitalize_middleware(next_, *args, **kwargs): assert result.data == {"first": "Eno", "second": "Owt"} # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def single_async_function(): doc = parse("{ first second }") @@ -200,7 +201,7 @@ def resolve(self, next_, *args, **kwargs): ) assert result.data == {"field": "devloseR"} # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def with_async_function_and_object(): doc = parse("{ field }") @@ -237,7 +238,7 @@ async def resolve(self, next_, *args, **kwargs): result = await awaitable_result assert result.data == {"field": "devloseR"} - @pytest.mark.asyncio() + @pytest.mark.asyncio async def subscription_simple(): async def bar_resolve(_obj, _info): yield "bar" diff --git a/tests/execution/test_mutations.py b/tests/execution/test_mutations.py index 20ee1c97..3737bb6a 100644 --- a/tests/execution/test_mutations.py +++ b/tests/execution/test_mutations.py @@ -4,6 +4,7 @@ from typing import Any, Awaitable import pytest + from graphql.execution import ( ExperimentalIncrementalExecutionResults, execute, @@ -106,7 +107,7 @@ async def promise_to_get_the_number(holder: NumberHolder, _info) -> int: def describe_execute_handles_mutation_execution_ordering(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def evaluates_mutations_serially(): document = parse( """ @@ -154,7 +155,7 @@ def does_not_include_illegal_mutation_fields_in_output(): result = execute_sync(schema=schema, document=document) assert result == ({}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def evaluates_mutations_correctly_in_presence_of_a_failed_mutation(): document = parse( """ @@ -211,7 +212,7 @@ async def evaluates_mutations_correctly_in_presence_of_a_failed_mutation(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def mutation_fields_with_defer_do_not_block_next_mutation(): document = parse( """ @@ -256,7 +257,7 @@ async def mutation_fields_with_defer_do_not_block_next_mutation(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def mutation_inside_of_a_fragment(): document = parse( """ @@ -282,7 +283,7 @@ async def mutation_inside_of_a_fragment(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def mutation_with_defer_is_not_executed_serially(): document = parse( """ diff --git a/tests/execution/test_nonnull.py b/tests/execution/test_nonnull.py index 053009a9..99810ed9 100644 --- a/tests/execution/test_nonnull.py +++ b/tests/execution/test_nonnull.py @@ -3,6 +3,7 @@ from typing import Any, Awaitable, cast import pytest + from graphql.execution import ExecutionResult, execute, execute_sync from graphql.language import parse from graphql.pyutils import AwaitableOrValue @@ -125,12 +126,12 @@ def describe_nulls_a_nullable_field(): } """ - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_null(): result = await execute_sync_and_async(query, NullingData()) assert result == ({"sync": None}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws(): result = await execute_sync_and_async(query, ThrowingData()) assert result == ( @@ -153,7 +154,7 @@ def describe_nulls_a_returned_object_that_contains_a_non_null_field(): } """ - @pytest.mark.asyncio() + @pytest.mark.asyncio async def that_returns_null(): result = await execute_sync_and_async(query, NullingData()) assert result == ( @@ -168,7 +169,7 @@ async def that_returns_null(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def that_throws(): result = await execute_sync_and_async(query, ThrowingData()) assert result == ( @@ -214,14 +215,14 @@ def describe_nulls_a_complex_tree_of_nullable_fields_each(): }, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_null(): result = await cast( Awaitable[ExecutionResult], execute_query(query, NullingData()) ) assert result == (data, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws(): result = await cast( Awaitable[ExecutionResult], execute_query(query, ThrowingData()) @@ -348,7 +349,7 @@ def describe_nulls_first_nullable_after_long_chain_of_non_null_fields(): "anotherPromiseNest": None, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_null(): result = await cast( Awaitable[ExecutionResult], execute_query(query, NullingData()) @@ -411,7 +412,7 @@ async def returns_null(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws(): result = await cast( Awaitable[ExecutionResult], execute_query(query, ThrowingData()) @@ -477,7 +478,7 @@ def describe_nulls_the_top_level_if_non_nullable_field(): } """ - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_null(): result = await execute_sync_and_async(query, NullingData()) await asyncio.sleep(0) # strangely needed to get coverage on Python 3.11 @@ -493,7 +494,7 @@ async def returns_null(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws(): result = await execute_sync_and_async(query, ThrowingData()) await asyncio.sleep(0) # strangely needed to get coverage on Python 3.11 diff --git a/tests/execution/test_parallel.py b/tests/execution/test_parallel.py index faacd0c4..f4dc86b1 100644 --- a/tests/execution/test_parallel.py +++ b/tests/execution/test_parallel.py @@ -2,6 +2,7 @@ from typing import Awaitable import pytest + from graphql.execution import execute from graphql.language import parse from graphql.type import ( @@ -31,7 +32,7 @@ async def wait(self) -> bool: def describe_parallel_execution(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolve_single_field(): # make sure that the special case of resolving a single field works async def resolve(*_args): @@ -52,7 +53,7 @@ async def resolve(*_args): assert result == ({"foo": True}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolve_fields_in_parallel(): barrier = Barrier(2) @@ -78,7 +79,7 @@ async def resolve(*_args): assert result == ({"foo": True, "bar": True}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolve_single_element_list(): # make sure that the special case of resolving a single element list works async def resolve(*_args): @@ -97,7 +98,7 @@ async def resolve(*_args): assert result == ({"foo": [True]}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolve_list_in_parallel(): barrier = Barrier(2) @@ -127,7 +128,7 @@ async def resolve_list(*args): assert result == ({"foo": [True, True]}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolve_is_type_of_in_parallel(): FooType = GraphQLInterfaceType("Foo", {"foo": GraphQLField(GraphQLString)}) diff --git a/tests/execution/test_stream.py b/tests/execution/test_stream.py index 46a53b56..8a1ca605 100644 --- a/tests/execution/test_stream.py +++ b/tests/execution/test_stream.py @@ -4,6 +4,7 @@ from typing import Any, Awaitable, NamedTuple import pytest + from graphql.error import GraphQLError from graphql.execution import ( ExecutionResult, @@ -28,7 +29,7 @@ anext # noqa: B018 except NameError: # pragma: no cover (Python < 3.10) # noinspection PyShadowingBuiltins - async def anext(iterator): # noqa: A001 + async def anext(iterator): """Return the next item from an async iterator.""" return await iterator.__anext__() @@ -217,7 +218,7 @@ def can_compare_incremental_stream_result(): assert result != dict(list(args.items())[:2] + [("path", ["foo", 2])]) assert result != {**args, "label": "baz"} - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_a_list_field(): document = parse("{ scalarList @stream(initialCount: 1) }") result = await complete( @@ -240,7 +241,7 @@ async def can_stream_a_list_field(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_use_default_value_of_initial_count(): document = parse("{ scalarList @stream }") result = await complete( @@ -267,7 +268,7 @@ async def can_use_default_value_of_initial_count(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def negative_values_of_initial_count_throw_field_errors(): document = parse("{ scalarList @stream(initialCount: -2) }") result = await complete( @@ -286,7 +287,7 @@ async def negative_values_of_initial_count_throw_field_errors(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def non_integer_values_of_initial_count_throw_field_errors(): document = parse("{ scalarList @stream(initialCount: 1.5) }") result = await complete(document, {"scalarList": ["apple", "half of a banana"]}) @@ -303,7 +304,7 @@ async def non_integer_values_of_initial_count_throw_field_errors(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_label_from_stream_directive(): document = parse( '{ scalarList @stream(initialCount: 1, label: "scalar-stream") }' @@ -340,7 +341,7 @@ async def returns_label_from_stream_directive(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws_an_error_for_stream_directive_with_non_string_label(): document = parse("{ scalarList @stream(initialCount: 1, label: 42) }") result = await complete(document, {"scalarList": ["some apples"]}) @@ -360,7 +361,7 @@ async def throws_an_error_for_stream_directive_with_non_string_label(): ], } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_disable_stream_using_if_argument(): document = parse("{ scalarList @stream(initialCount: 0, if: false) }") result = await complete( @@ -372,7 +373,7 @@ async def can_disable_stream_using_if_argument(): }, } - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def does_not_disable_stream_with_null_if_argument(): document = parse( @@ -400,7 +401,7 @@ async def does_not_disable_stream_with_null_if_argument(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_multi_dimensional_lists(): document = parse("{ scalarListList @stream(initialCount: 1) }") result = await complete( @@ -440,7 +441,7 @@ async def can_stream_multi_dimensional_lists(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_a_field_that_returns_a_list_of_awaitables(): document = parse( """ @@ -482,7 +483,7 @@ async def await_friend(f): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_in_correct_order_with_list_of_awaitables(): document = parse( """ @@ -537,7 +538,7 @@ async def await_friend(f): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_a_field_that_returns_a_list_with_nested_async_fields(): document = parse( """ @@ -585,7 +586,7 @@ async def get_id(f): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_error_in_list_of_awaitables_before_initial_count_reached(): document = parse( """ @@ -635,7 +636,7 @@ async def await_friend(f, i): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_error_in_list_of_awaitables_after_initial_count_reached(): document = parse( """ @@ -694,7 +695,7 @@ async def await_friend(f, i): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_a_field_that_returns_an_async_iterable(): document = parse( """ @@ -750,7 +751,7 @@ async def friend_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_stream_a_field_that_returns_an_async_iterable_with_initial_count(): document = parse( """ @@ -793,7 +794,7 @@ async def friend_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def negative_initial_count_throw_error_on_field_returning_async_iterable(): document = parse( """ @@ -821,7 +822,7 @@ async def friend_list(_info): "data": {"friendList": None}, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_handle_concurrent_calls_to_next_without_waiting(): document = parse( """ @@ -869,7 +870,7 @@ async def friend_list(_info): {"done": True, "value": None}, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_error_in_async_iterable_before_initial_count_is_reached(): document = parse( """ @@ -900,7 +901,7 @@ async def friend_list(_info): "data": {"friendList": None}, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_error_in_async_iterable_after_initial_count_is_reached(): document = parse( """ @@ -945,7 +946,7 @@ async def friend_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_null_for_non_null_list_items_after_initial_count_is_reached(): document = parse( """ @@ -986,7 +987,7 @@ async def handles_null_for_non_null_list_items_after_initial_count_is_reached(): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_null_for_non_null_async_items_after_initial_count_is_reached(): document = parse( """ @@ -1034,7 +1035,7 @@ async def friend_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_error_thrown_in_complete_value_after_initial_count_is_reached(): document = parse( """ @@ -1073,7 +1074,7 @@ async def scalar_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_error_in_complete_value_after_initial_count_is_reached(): document = parse( """ @@ -1135,7 +1136,7 @@ def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_nested_async_error_in_complete_value_after_initial_count(): document = parse( """ @@ -1196,7 +1197,7 @@ def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_error_in_complete_value_after_initial_count_non_null(): document = parse( """ @@ -1249,7 +1250,7 @@ def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_nested_async_error_in_complete_value_after_initial_non_null(): document = parse( """ @@ -1301,7 +1302,7 @@ def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_error_in_complete_value_after_initial_from_async_iterable(): document = parse( """ @@ -1367,7 +1368,7 @@ async def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_async_error_in_complete_value_from_async_iterable_non_null(): document = parse( """ @@ -1421,7 +1422,7 @@ async def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def filters_payloads_that_are_nulled(): document = parse( """ @@ -1472,7 +1473,7 @@ async def friend_list(_info): }, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def filters_payloads_that_are_nulled_by_a_later_synchronous_error(): document = parse( """ @@ -1515,7 +1516,7 @@ async def friend_list(_info): }, } - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def does_not_filter_payloads_when_null_error_is_in_a_different_path(): document = parse( @@ -1584,7 +1585,7 @@ async def friend_list(_info): {"hasNext": False}, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def filters_stream_payloads_that_are_nulled_in_a_deferred_payload(): document = parse( @@ -1655,7 +1656,7 @@ async def friend_list(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def filters_defer_payloads_that_are_nulled_in_a_stream_response(): document = parse( """ @@ -1716,7 +1717,7 @@ async def friend_list(_info): ] @pytest.mark.timeout(1) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_iterator_and_ignores_error_when_stream_payloads_are_filtered(): finished = False @@ -1795,7 +1796,7 @@ async def iterable(_info): assert not finished # running iterator cannot be canceled - @pytest.mark.asyncio() + @pytest.mark.asyncio async def handles_awaitables_from_complete_value_after_initial_count_is_reached(): document = parse( """ @@ -1858,7 +1859,7 @@ async def get_friends(_info): }, ] - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_payloads_properly_when_parent_deferred_slower_than_stream(): resolve_slow_field = Event() @@ -1944,7 +1945,7 @@ async def get_friends(_info): await anext(iterator) @pytest.mark.timeout(1) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_fields_that_are_resolved_after_async_iterable_is_complete(): resolve_slow_field = Event() resolve_iterable = Event() @@ -2022,7 +2023,7 @@ async def get_friends(_info): with pytest.raises(StopAsyncIteration): await anext(iterator) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def can_defer_fields_that_are_resolved_before_async_iterable_is_complete(): resolve_slow_field = Event() resolve_iterable = Event() @@ -2106,7 +2107,7 @@ async def get_friends(_info): with pytest.raises(StopAsyncIteration): await anext(iterator) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def finishes_async_iterable_when_returned_generator_is_closed(): finished = False @@ -2146,7 +2147,7 @@ async def iterable(_info): await sleep(0) assert finished - @pytest.mark.asyncio() + @pytest.mark.asyncio async def finishes_async_iterable_when_underlying_iterator_has_no_close_method(): class Iterable: def __init__(self): @@ -2197,7 +2198,7 @@ async def __anext__(self): await sleep(0) assert iterable.index == 4 - @pytest.mark.asyncio() + @pytest.mark.asyncio async def finishes_async_iterable_when_error_is_raised_in_returned_generator(): finished = False diff --git a/tests/execution/test_subscribe.py b/tests/execution/test_subscribe.py index fcbd13ef..8a6b4c38 100644 --- a/tests/execution/test_subscribe.py +++ b/tests/execution/test_subscribe.py @@ -13,6 +13,7 @@ ) import pytest + from graphql.execution import ( ExecutionResult, create_source_event_stream, @@ -44,7 +45,7 @@ anext # noqa: B018 except NameError: # pragma: no cover (Python < 3.10) # noinspection PyShadowingBuiltins - async def anext(iterator): # noqa: A001 + async def anext(iterator): """Return the next item from an async iterator.""" return await iterator.__anext__() @@ -197,7 +198,7 @@ def subscribe_with_bad_args( # Check all error cases when initializing the subscription. def describe_subscription_initialization_phase(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_positional_arguments(): document = parse( """ @@ -217,7 +218,7 @@ async def empty_async_iterable(_info): await anext(ai) await ai.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_multiple_subscription_fields_defined_in_schema(): schema = GraphQLSchema( query=DummyQueryType, @@ -242,7 +243,7 @@ async def foo_generator(_info): await subscription.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_type_definition_with_sync_subscribe_function(): async def foo_generator(_obj, _info): yield {"foo": "FooValue"} @@ -262,7 +263,7 @@ async def foo_generator(_obj, _info): await subscription.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_type_definition_with_async_subscribe_function(): async def foo_generator(_obj, _info): await asyncio.sleep(0) @@ -290,7 +291,7 @@ async def subscribe_fn(obj, info): await subscription.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_only_resolve_the_first_field_of_invalid_multi_field(): did_resolve = {"foo": False, "bar": False} @@ -325,7 +326,7 @@ async def subscribe_bar(_obj, _info): # pragma: no cover await subscription.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolves_to_an_error_if_schema_does_not_support_subscriptions(): schema = GraphQLSchema(query=DummyQueryType) document = parse("subscription { unknownField }") @@ -343,7 +344,7 @@ async def resolves_to_an_error_if_schema_does_not_support_subscriptions(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolves_to_an_error_for_unknown_subscription_field(): schema = GraphQLSchema( query=DummyQueryType, @@ -364,7 +365,7 @@ async def resolves_to_an_error_for_unknown_subscription_field(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_pass_through_unexpected_errors_thrown_in_subscribe(): schema = GraphQLSchema( query=DummyQueryType, @@ -375,7 +376,7 @@ async def should_pass_through_unexpected_errors_thrown_in_subscribe(): with pytest.raises(AttributeError): subscribe_with_bad_args(schema=schema, document={}) # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_an_error_if_subscribe_does_not_return_an_iterator(): expected_result = ( @@ -405,7 +406,7 @@ async def async_fn(obj, info): del result cleanup() - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolves_to_an_error_for_subscription_resolver_errors(): expected_result = ( None, @@ -447,7 +448,7 @@ async def reject_with_error(*args): assert is_awaitable(result) assert await result == expected_result - @pytest.mark.asyncio() + @pytest.mark.asyncio async def resolves_to_an_error_if_variables_were_wrong_type(): schema = GraphQLSchema( query=DummyQueryType, @@ -492,7 +493,7 @@ async def resolves_to_an_error_if_variables_were_wrong_type(): # Once a subscription returns a valid AsyncIterator, it can still yield errors. def describe_subscription_publish_phase(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def produces_a_payload_for_multiple_subscribe_in_same_subscription(): pubsub = SimplePubSub() @@ -527,7 +528,7 @@ async def produces_a_payload_for_multiple_subscribe_in_same_subscription(): assert await payload1 == (expected_payload, None) assert await payload2 == (expected_payload, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def produces_a_payload_when_queried_fields_are_async(): pubsub = SimplePubSub() subscription = create_subscription(pubsub, {"asyncResolver": True}) @@ -564,7 +565,7 @@ async def produces_a_payload_when_queried_fields_are_async(): with pytest.raises(StopAsyncIteration): await anext(subscription) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def produces_a_payload_per_subscription_event(): pubsub = SimplePubSub() subscription = create_subscription(pubsub) @@ -643,7 +644,7 @@ async def produces_a_payload_per_subscription_event(): with pytest.raises(StopAsyncIteration): assert await anext(subscription) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def subscribe_function_returns_errors_with_defer(): pubsub = SimplePubSub() subscription = create_subscription(pubsub, {"shouldDefer": True}) @@ -707,7 +708,7 @@ async def subscribe_function_returns_errors_with_defer(): with pytest.raises(StopAsyncIteration): assert await anext(subscription) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def subscribe_function_returns_errors_with_stream(): pubsub = SimplePubSub() subscription = create_subscription(pubsub, {"shouldStream": True}) @@ -788,7 +789,7 @@ async def subscribe_function_returns_errors_with_stream(): with pytest.raises(StopAsyncIteration): assert await anext(subscription) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def produces_a_payload_when_there_are_multiple_events(): pubsub = SimplePubSub() subscription = create_subscription(pubsub) @@ -844,7 +845,7 @@ async def produces_a_payload_when_there_are_multiple_events(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_not_trigger_when_subscription_is_already_done(): pubsub = SimplePubSub() subscription = create_subscription(pubsub) @@ -895,7 +896,7 @@ async def should_not_trigger_when_subscription_is_already_done(): with pytest.raises(StopAsyncIteration): await payload - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_not_trigger_when_subscription_is_thrown(): pubsub = SimplePubSub() subscription = create_subscription(pubsub) @@ -936,7 +937,7 @@ async def should_not_trigger_when_subscription_is_thrown(): with pytest.raises(StopAsyncIteration): await payload - @pytest.mark.asyncio() + @pytest.mark.asyncio async def event_order_is_correct_for_multiple_publishes(): pubsub = SimplePubSub() subscription = create_subscription(pubsub) @@ -992,7 +993,7 @@ async def event_order_is_correct_for_multiple_publishes(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_handle_error_during_execution_of_source_event(): async def generate_messages(_obj, _info): yield "Hello" @@ -1040,7 +1041,7 @@ def resolve_message(message, _info): # Subsequent events are still executed. assert await anext(subscription) == ({"newMessage": "Bonjour"}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_pass_through_error_thrown_in_source_event_stream(): async def generate_messages(_obj, _info): yield "Hello" @@ -1077,7 +1078,7 @@ def resolve_message(message, _info): with pytest.raises(StopAsyncIteration): await anext(subscription) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_work_with_sync_resolve_function(): async def generate_messages(_obj, _info): yield "Hello" @@ -1105,7 +1106,7 @@ def resolve_message(message, _info): assert await anext(subscription) == ({"newMessage": "Hello"}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_work_with_async_resolve_function(): async def generate_messages(_obj, _info): await asyncio.sleep(0) @@ -1135,7 +1136,7 @@ async def resolve_message(message, _info): assert await anext(subscription) == ({"newMessage": "Hello"}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_work_with_custom_async_iterator(): class MessageGenerator: resolved: List[str] = [] @@ -1185,7 +1186,7 @@ async def resolve(cls, message, _info) -> str: await subscription.aclose() # type: ignore - @pytest.mark.asyncio() + @pytest.mark.asyncio async def should_close_custom_async_iterator(): class MessageGenerator: closed: bool = False diff --git a/tests/execution/test_sync.py b/tests/execution/test_sync.py index 36f8c9a5..d5e9504f 100644 --- a/tests/execution/test_sync.py +++ b/tests/execution/test_sync.py @@ -1,4 +1,5 @@ import pytest + from graphql import graphql_sync from graphql.execution import execute, execute_sync from graphql.language import parse @@ -51,7 +52,7 @@ def does_not_return_an_awaitable_if_mutation_fields_are_all_synchronous(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def returns_an_awaitable_if_any_field_is_asynchronous(): doc = "query Example { syncField, asyncField }" result = execute(schema, parse(doc), "rootValue") @@ -80,7 +81,7 @@ def does_not_throw_if_not_encountering_async_execution_with_check_sync(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_execution_with_check_sync(): doc = "query Example { syncField, asyncField }" @@ -93,7 +94,7 @@ async def throws_if_encountering_async_execution_with_check_sync(): del exc_info cleanup() - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_operation_without_check_sync(): doc = "query Example { syncField, asyncField }" @@ -112,7 +113,7 @@ async def throws_if_encountering_async_operation_without_check_sync(): del result cleanup() - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_iterable_execution_with_check_sync(): doc = """ @@ -132,7 +133,7 @@ async def throws_if_encountering_async_iterable_execution_with_check_sync(): del exc_info cleanup() - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_iterable_execution_without_check_sync(): doc = """ @@ -188,7 +189,7 @@ def does_not_throw_if_not_encountering_async_operation_with_check_sync(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_operation_with_check_sync(): doc = "query Example { syncField, asyncField }" @@ -199,7 +200,7 @@ async def throws_if_encountering_async_operation_with_check_sync(): del exc_info cleanup() - @pytest.mark.asyncio() + @pytest.mark.asyncio @pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning") async def throws_if_encountering_async_operation_without_check_sync(): doc = "query Example { syncField, asyncField }" diff --git a/tests/language/test_block_string_fuzz.py b/tests/language/test_block_string_fuzz.py index feb7ca2b..0e17b4d4 100644 --- a/tests/language/test_block_string_fuzz.py +++ b/tests/language/test_block_string_fuzz.py @@ -1,4 +1,5 @@ import pytest + from graphql.language import Lexer, Source, TokenKind from graphql.language.block_string import ( is_printable_as_block_string, @@ -40,7 +41,7 @@ def assert_non_printable_block_string(test_value: str) -> None: def describe_print_block_string(): - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(80) def correctly_print_random_strings(): # Testing with length >7 is taking exponentially more time. However, it is diff --git a/tests/language/test_lexer.py b/tests/language/test_lexer.py index 0bc9a398..d2d24931 100644 --- a/tests/language/test_lexer.py +++ b/tests/language/test_lexer.py @@ -3,6 +3,7 @@ from typing import Optional, Tuple import pytest + from graphql.error import GraphQLSyntaxError from graphql.language import Lexer, Source, SourceLocation, Token, TokenKind from graphql.language.lexer import is_punctuator_token_kind diff --git a/tests/language/test_parser.py b/tests/language/test_parser.py index b671e444..e6d33064 100644 --- a/tests/language/test_parser.py +++ b/tests/language/test_parser.py @@ -3,6 +3,7 @@ from typing import Optional, Tuple, cast import pytest + from graphql.error import GraphQLSyntaxError from graphql.language import ( ArgumentNode, diff --git a/tests/language/test_printer.py b/tests/language/test_printer.py index 6117c69d..b6ac41e0 100644 --- a/tests/language/test_printer.py +++ b/tests/language/test_printer.py @@ -1,6 +1,7 @@ from copy import deepcopy import pytest + from graphql.language import FieldNode, NameNode, parse, print_ast from ..fixtures import kitchen_sink_query # noqa: F401 diff --git a/tests/language/test_schema_parser.py b/tests/language/test_schema_parser.py index a5005a06..df64381a 100644 --- a/tests/language/test_schema_parser.py +++ b/tests/language/test_schema_parser.py @@ -6,6 +6,7 @@ from typing import Optional, Tuple import pytest + from graphql.error import GraphQLSyntaxError from graphql.language import ( ArgumentNode, diff --git a/tests/language/test_schema_printer.py b/tests/language/test_schema_printer.py index 95fcac97..083dcd0f 100644 --- a/tests/language/test_schema_printer.py +++ b/tests/language/test_schema_printer.py @@ -1,6 +1,7 @@ from copy import deepcopy import pytest + from graphql.language import NameNode, ScalarTypeDefinitionNode, parse, print_ast from ..fixtures import kitchen_sink_sdl # noqa: F401 diff --git a/tests/language/test_source.py b/tests/language/test_source.py index 02014445..24008605 100644 --- a/tests/language/test_source.py +++ b/tests/language/test_source.py @@ -4,6 +4,7 @@ from typing import cast import pytest + from graphql.language import Source, SourceLocation from ..utils import dedent diff --git a/tests/language/test_visitor.py b/tests/language/test_visitor.py index 1e74c6ff..00283fe1 100644 --- a/tests/language/test_visitor.py +++ b/tests/language/test_visitor.py @@ -5,6 +5,7 @@ from typing import Any, cast import pytest + from graphql.language import ( BREAK, REMOVE, diff --git a/tests/pyutils/test_async_reduce.py b/tests/pyutils/test_async_reduce.py index cbcef554..0ac606c8 100644 --- a/tests/pyutils/test_async_reduce.py +++ b/tests/pyutils/test_async_reduce.py @@ -1,6 +1,7 @@ from functools import reduce import pytest + from graphql.pyutils import async_reduce, is_awaitable @@ -16,7 +17,7 @@ def callback(accumulator, current_value): assert result == 42 assert result == reduce(callback, values, initial_value) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def works_with_sync_values_and_sync_initial_value(): def callback(accumulator, current_value): return accumulator + "-" + current_value @@ -26,7 +27,7 @@ def callback(accumulator, current_value): assert not is_awaitable(result) assert result == "foo-bar-baz" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def works_with_async_initial_value(): async def async_initial_value(): return "foo" @@ -39,7 +40,7 @@ def callback(accumulator, current_value): assert is_awaitable(result) assert await result == "foo-bar-baz" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def works_with_async_callback(): async def async_callback(accumulator, current_value): return accumulator + "-" + current_value @@ -49,7 +50,7 @@ async def async_callback(accumulator, current_value): assert is_awaitable(result) assert await result == "foo-bar-baz" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def works_with_async_callback_and_async_initial_value(): async def async_initial_value(): return 1 / 8 diff --git a/tests/pyutils/test_description.py b/tests/pyutils/test_description.py index 8a19396d..3148520b 100644 --- a/tests/pyutils/test_description.py +++ b/tests/pyutils/test_description.py @@ -2,6 +2,7 @@ from typing import cast import pytest + from graphql import graphql_sync from graphql.pyutils import ( Description, diff --git a/tests/pyutils/test_format_list.py b/tests/pyutils/test_format_list.py index ee425eca..09567645 100644 --- a/tests/pyutils/test_format_list.py +++ b/tests/pyutils/test_format_list.py @@ -1,4 +1,5 @@ import pytest + from graphql.pyutils import and_list, or_list diff --git a/tests/pyutils/test_inspect.py b/tests/pyutils/test_inspect.py index 3721d018..94c62b48 100644 --- a/tests/pyutils/test_inspect.py +++ b/tests/pyutils/test_inspect.py @@ -6,6 +6,7 @@ from typing import Any import pytest + from graphql.pyutils import Undefined, inspect from graphql.type import ( GraphQLDirective, @@ -138,7 +139,7 @@ def test_generator(): assert inspect(test_generator) == "" assert inspect(test_generator()) == "" - @pytest.mark.asyncio() + @pytest.mark.asyncio async def inspect_coroutine(): async def test_coroutine(): pass diff --git a/tests/pyutils/test_is_awaitable.py b/tests/pyutils/test_is_awaitable.py index dcee07d9..b05f01af 100644 --- a/tests/pyutils/test_is_awaitable.py +++ b/tests/pyutils/test_is_awaitable.py @@ -3,6 +3,7 @@ from sys import version_info as python_version import pytest + from graphql.pyutils import is_awaitable @@ -66,7 +67,7 @@ async def some_async_function(): assert not isawaitable(some_async_function) assert not is_awaitable(some_async_function) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def recognizes_a_coroutine_object(): async def some_async_function(): return True @@ -92,7 +93,7 @@ def some_function(): assert is_awaitable(some_old_style_coroutine) assert is_awaitable(some_old_style_coroutine) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def recognizes_a_future_object(): async def some_async_function(): return True @@ -105,7 +106,7 @@ async def some_async_function(): assert await some_future is True - @pytest.mark.asyncio() + @pytest.mark.asyncio async def declines_an_async_generator(): async def some_async_generator_function(): yield True diff --git a/tests/pyutils/test_simple_pub_sub.py b/tests/pyutils/test_simple_pub_sub.py index 2f30a8e2..f0a88dcb 100644 --- a/tests/pyutils/test_simple_pub_sub.py +++ b/tests/pyutils/test_simple_pub_sub.py @@ -1,11 +1,12 @@ from asyncio import sleep import pytest + from graphql.pyutils import SimplePubSub, is_awaitable def describe_simple_pub_sub(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def subscribe_async_iterator_mock(): pubsub = SimplePubSub() iterator = pubsub.get_subscriber() @@ -49,7 +50,7 @@ async def subscribe_async_iterator_mock(): with pytest.raises(StopAsyncIteration): await iterator.__anext__() - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterator_aclose_empties_push_queue(): pubsub = SimplePubSub() assert not pubsub.subscribers @@ -67,7 +68,7 @@ async def iterator_aclose_empties_push_queue(): assert iterator.pull_queue.qsize() == 0 assert not iterator.listening - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterator_aclose_empties_pull_queue(): pubsub = SimplePubSub() assert not pubsub.subscribers @@ -84,7 +85,7 @@ async def iterator_aclose_empties_pull_queue(): assert iterator.pull_queue.qsize() == 0 assert not iterator.listening - @pytest.mark.asyncio() + @pytest.mark.asyncio async def iterator_aclose_is_idempotent(): pubsub = SimplePubSub() iterator = pubsub.get_subscriber() diff --git a/tests/pyutils/test_undefined.py b/tests/pyutils/test_undefined.py index b6f62eea..b34611e3 100644 --- a/tests/pyutils/test_undefined.py +++ b/tests/pyutils/test_undefined.py @@ -1,6 +1,7 @@ import pickle import pytest + from graphql.pyutils import Undefined, UndefinedType diff --git a/tests/star_wars_schema.py b/tests/star_wars_schema.py index 3f8713ab..575bf482 100644 --- a/tests/star_wars_schema.py +++ b/tests/star_wars_schema.py @@ -54,7 +54,6 @@ GraphQLSchema, GraphQLString, ) - from tests.star_wars_data import ( get_droid, get_friends, diff --git a/tests/test_star_wars_query.py b/tests/test_star_wars_query.py index 6e5bbf59..bb1008b8 100644 --- a/tests/test_star_wars_query.py +++ b/tests/test_star_wars_query.py @@ -1,4 +1,5 @@ import pytest + from graphql import graphql, graphql_sync from .star_wars_schema import star_wars_schema as schema @@ -6,7 +7,7 @@ def describe_star_wars_query_tests(): def describe_basic_queries(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def correctly_identifies_r2_d2_as_hero_of_the_star_wars_saga(): source = """ query HeroNameQuery { @@ -18,7 +19,7 @@ async def correctly_identifies_r2_d2_as_hero_of_the_star_wars_saga(): result = await graphql(schema=schema, source=source) assert result == ({"hero": {"name": "R2-D2"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def accepts_positional_arguments_to_graphql(): source = """ query HeroNameQuery { @@ -33,7 +34,7 @@ async def accepts_positional_arguments_to_graphql(): sync_result = graphql_sync(schema, source) assert sync_result == result - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_for_the_id_and_friends_of_r2_d2(): source = """ query HeroNameAndFriendsQuery { @@ -63,7 +64,7 @@ async def allows_us_to_query_for_the_id_and_friends_of_r2_d2(): ) def describe_nested_queries(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_for_the_friends_of_friends_of_r2_d2(): source = """ query NestedQuery { @@ -121,7 +122,7 @@ async def allows_us_to_query_for_the_friends_of_friends_of_r2_d2(): ) def describe_using_ids_and_query_parameters_to_refetch_objects(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_for_r2_d2_directly_using_his_id(): source = """ query { @@ -133,7 +134,7 @@ async def allows_us_to_query_for_r2_d2_directly_using_his_id(): result = await graphql(schema=schema, source=source) assert result == ({"droid": {"name": "R2-D2"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_characters_directly_using_their_id(): source = """ query FetchLukeAndC3POQuery { @@ -151,7 +152,7 @@ async def allows_us_to_query_characters_directly_using_their_id(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_creating_a_generic_query_to_fetch_luke_using_his_id(): source = """ query FetchSomeIDQuery($someId: String!) { @@ -166,7 +167,7 @@ async def allows_creating_a_generic_query_to_fetch_luke_using_his_id(): ) assert result == ({"human": {"name": "Luke Skywalker"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_creating_a_generic_query_to_fetch_han_using_his_id(): source = """ query FetchSomeIDQuery($someId: String!) { @@ -181,7 +182,7 @@ async def allows_creating_a_generic_query_to_fetch_han_using_his_id(): ) assert result == ({"human": {"name": "Han Solo"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def generic_query_that_gets_null_back_when_passed_invalid_id(): source = """ query humanQuery($id: String!) { @@ -197,7 +198,7 @@ async def generic_query_that_gets_null_back_when_passed_invalid_id(): assert result == ({"human": None}, None) def describe_using_aliases_to_change_the_key_in_the_response(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_for_luke_changing_his_key_with_an_alias(): source = """ query FetchLukeAliased { @@ -209,7 +210,7 @@ async def allows_us_to_query_for_luke_changing_his_key_with_an_alias(): result = await graphql(schema=schema, source=source) assert result == ({"luke": {"name": "Luke Skywalker"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def query_for_luke_and_leia_using_two_root_fields_and_an_alias(): source = """ query FetchLukeAndLeiaAliased { @@ -228,7 +229,7 @@ async def query_for_luke_and_leia_using_two_root_fields_and_an_alias(): ) def describe_uses_fragments_to_express_more_complex_queries(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_query_using_duplicated_content(): source = """ query DuplicateFields { @@ -251,7 +252,7 @@ async def allows_us_to_query_using_duplicated_content(): None, ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_use_a_fragment_to_avoid_duplicating_content(): source = """ query UseFragment { @@ -277,7 +278,7 @@ async def allows_us_to_use_a_fragment_to_avoid_duplicating_content(): ) def describe_using_typename_to_find_the_type_of_an_object(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_verify_that_r2_d2_is_a_droid(): source = """ query CheckTypeOfR2 { @@ -290,7 +291,7 @@ async def allows_us_to_verify_that_r2_d2_is_a_droid(): result = await graphql(schema=schema, source=source) assert result == ({"hero": {"__typename": "Droid", "name": "R2-D2"}}, None) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def allows_us_to_verify_that_luke_is_a_human(): source = """ query CheckTypeOfLuke { @@ -307,7 +308,7 @@ async def allows_us_to_verify_that_luke_is_a_human(): ) def describe_reporting_errors_raised_in_resolvers(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def correctly_reports_error_on_accessing_secret_backstory(): source = """ query HeroNameQuery { @@ -329,7 +330,7 @@ async def correctly_reports_error_on_accessing_secret_backstory(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def correctly_reports_error_on_accessing_backstory_in_a_list(): source = """ query HeroNameQuery { @@ -373,7 +374,7 @@ async def correctly_reports_error_on_accessing_backstory_in_a_list(): ], ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def correctly_reports_error_on_accessing_through_an_alias(): source = """ query HeroNameQuery { diff --git a/tests/test_user_registry.py b/tests/test_user_registry.py index 7d134a52..147e01bd 100644 --- a/tests/test_user_registry.py +++ b/tests/test_user_registry.py @@ -12,6 +12,7 @@ from typing import Any, AsyncIterable, NamedTuple import pytest + from graphql import ( GraphQLArgument, GraphQLBoolean, @@ -212,13 +213,13 @@ async def resolve_subscription_user(event, info, id): # noqa: ARG001, A002 ) -@pytest.fixture() +@pytest.fixture def context(): return {"registry": UserRegistry()} def describe_query(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def query_user(context): user = await context["registry"].create( firstName="John", lastName="Doe", tweets=42, verified=True @@ -250,7 +251,7 @@ async def query_user(context): def describe_mutation(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def create_user(context): received = {} @@ -302,7 +303,7 @@ def receive(msg): "User 0": {"user": user, "mutation": MutationEnum.CREATED.value}, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def update_user(context): received = {} @@ -358,7 +359,7 @@ def receive(msg): "User 0": {"user": user, "mutation": MutationEnum.UPDATED.value}, } - @pytest.mark.asyncio() + @pytest.mark.asyncio async def delete_user(context): received = {} @@ -400,7 +401,7 @@ def receive(msg): def describe_subscription(): - @pytest.mark.asyncio() + @pytest.mark.asyncio async def subscribe_to_user_mutations(context): query = """ subscription ($userId: ID!) { diff --git a/tests/type/test_assert_name.py b/tests/type/test_assert_name.py index 55ef75c7..24ffc55d 100644 --- a/tests/type/test_assert_name.py +++ b/tests/type/test_assert_name.py @@ -1,4 +1,5 @@ import pytest + from graphql.error import GraphQLError from graphql.type import assert_enum_value_name, assert_name diff --git a/tests/type/test_definition.py b/tests/type/test_definition.py index 88ce94f7..a8b7c24b 100644 --- a/tests/type/test_definition.py +++ b/tests/type/test_definition.py @@ -12,6 +12,7 @@ from typing_extensions import TypedDict import pytest + from graphql.error import GraphQLError from graphql.language import ( EnumTypeDefinitionNode, diff --git a/tests/type/test_directives.py b/tests/type/test_directives.py index 3f29a947..4257d81f 100644 --- a/tests/type/test_directives.py +++ b/tests/type/test_directives.py @@ -1,4 +1,5 @@ import pytest + from graphql.error import GraphQLError from graphql.language import DirectiveDefinitionNode, DirectiveLocation from graphql.type import GraphQLArgument, GraphQLDirective, GraphQLInt, GraphQLString diff --git a/tests/type/test_extensions.py b/tests/type/test_extensions.py index 5aa087e2..d28b9482 100644 --- a/tests/type/test_extensions.py +++ b/tests/type/test_extensions.py @@ -1,4 +1,5 @@ import pytest + from graphql.type import ( GraphQLArgument, GraphQLDirective, diff --git a/tests/type/test_predicate.py b/tests/type/test_predicate.py index bd006e74..c741eca3 100644 --- a/tests/type/test_predicate.py +++ b/tests/type/test_predicate.py @@ -1,6 +1,7 @@ from typing import Any import pytest + from graphql.language import DirectiveLocation from graphql.type import ( GraphQLArgument, diff --git a/tests/type/test_scalars.py b/tests/type/test_scalars.py index 27255388..0ef5e548 100644 --- a/tests/type/test_scalars.py +++ b/tests/type/test_scalars.py @@ -3,6 +3,7 @@ from typing import Any import pytest + from graphql.error import GraphQLError from graphql.language import parse_value as parse_value_to_ast from graphql.pyutils import Undefined diff --git a/tests/type/test_schema.py b/tests/type/test_schema.py index f589302b..e678de35 100644 --- a/tests/type/test_schema.py +++ b/tests/type/test_schema.py @@ -1,6 +1,7 @@ from copy import deepcopy import pytest + from graphql.language import ( DirectiveLocation, SchemaDefinitionNode, diff --git a/tests/type/test_validation.py b/tests/type/test_validation.py index ab364e9f..087832ba 100644 --- a/tests/type/test_validation.py +++ b/tests/type/test_validation.py @@ -3,6 +3,7 @@ from operator import attrgetter import pytest + from graphql.language import DirectiveLocation, parse from graphql.pyutils import inspect from graphql.type import ( diff --git a/tests/utilities/test_ast_from_value.py b/tests/utilities/test_ast_from_value.py index 1432d7a4..947f2b18 100644 --- a/tests/utilities/test_ast_from_value.py +++ b/tests/utilities/test_ast_from_value.py @@ -1,6 +1,7 @@ from math import inf, nan import pytest + from graphql.error import GraphQLError from graphql.language import ( BooleanValueNode, diff --git a/tests/utilities/test_build_client_schema.py b/tests/utilities/test_build_client_schema.py index 518fb5bf..4b861003 100644 --- a/tests/utilities/test_build_client_schema.py +++ b/tests/utilities/test_build_client_schema.py @@ -1,6 +1,7 @@ from typing import cast import pytest + from graphql import graphql_sync from graphql.type import ( GraphQLArgument, diff --git a/tests/utilities/test_coerce_input_value.py b/tests/utilities/test_coerce_input_value.py index c18b5098..90af6cb9 100644 --- a/tests/utilities/test_coerce_input_value.py +++ b/tests/utilities/test_coerce_input_value.py @@ -4,6 +4,7 @@ from typing import Any, NamedTuple import pytest + from graphql.error import GraphQLError from graphql.pyutils import Undefined from graphql.type import ( diff --git a/tests/utilities/test_extend_schema.py b/tests/utilities/test_extend_schema.py index 75c70efd..28ac0be4 100644 --- a/tests/utilities/test_extend_schema.py +++ b/tests/utilities/test_extend_schema.py @@ -3,6 +3,7 @@ from typing import Union import pytest + from graphql import graphql_sync from graphql.language import parse, print_ast from graphql.type import ( diff --git a/tests/utilities/test_introspection_from_schema.py b/tests/utilities/test_introspection_from_schema.py index 895ade9a..1c9dbd52 100644 --- a/tests/utilities/test_introspection_from_schema.py +++ b/tests/utilities/test_introspection_from_schema.py @@ -3,6 +3,7 @@ from copy import deepcopy import pytest + from graphql.type import GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString from graphql.utilities import ( IntrospectionQuery, @@ -105,7 +106,7 @@ def can_deep_copy_pickled_schema(): # check that introspecting the copied schema gives the same result assert introspection_from_schema(copied) == introspected_schema - @pytest.mark.slow() + @pytest.mark.slow def describe_deepcopy_and_pickle_big(): # pragma: no cover @pytest.mark.timeout(20) def can_deep_copy_big_schema(big_schema_sdl): # noqa: F811 diff --git a/tests/utilities/test_strip_ignored_characters.py b/tests/utilities/test_strip_ignored_characters.py index d708bfdb..cdc6062d 100644 --- a/tests/utilities/test_strip_ignored_characters.py +++ b/tests/utilities/test_strip_ignored_characters.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from graphql.error import GraphQLSyntaxError from graphql.language import Lexer, Source, TokenKind, parse from graphql.utilities import strip_ignored_characters diff --git a/tests/utilities/test_strip_ignored_characters_fuzz.py b/tests/utilities/test_strip_ignored_characters_fuzz.py index 85c43aec..4c276e07 100644 --- a/tests/utilities/test_strip_ignored_characters_fuzz.py +++ b/tests/utilities/test_strip_ignored_characters_fuzz.py @@ -3,6 +3,7 @@ from json import dumps import pytest + from graphql.error import GraphQLSyntaxError from graphql.language import Lexer, Source, TokenKind from graphql.utilities import strip_ignored_characters @@ -74,7 +75,7 @@ def lex_value(s: str) -> str | None: def describe_strip_ignored_characters(): - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def strips_documents_with_random_combination_of_ignored_characters(): for ignored in ignored_tokens: @@ -85,7 +86,7 @@ def strips_documents_with_random_combination_of_ignored_characters(): ExpectStripped("".join(ignored_tokens)).to_equal("") - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def strips_random_leading_and_trailing_ignored_tokens(): for token in punctuator_tokens + non_punctuator_tokens: @@ -100,7 +101,7 @@ def strips_random_leading_and_trailing_ignored_tokens(): ExpectStripped("".join(ignored_tokens) + token).to_equal(token) ExpectStripped(token + "".join(ignored_tokens)).to_equal(token) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def strips_random_ignored_tokens_between_punctuator_tokens(): for left in punctuator_tokens: @@ -117,7 +118,7 @@ def strips_random_ignored_tokens_between_punctuator_tokens(): left + right ) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def strips_random_ignored_tokens_between_punctuator_and_non_punctuator_tokens(): for non_punctuator in non_punctuator_tokens: @@ -136,7 +137,7 @@ def strips_random_ignored_tokens_between_punctuator_and_non_punctuator_tokens(): punctuator + "".join(ignored_tokens) + non_punctuator ).to_equal(punctuator + non_punctuator) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def strips_random_ignored_tokens_between_non_punctuator_and_punctuator_tokens(): for non_punctuator in non_punctuator_tokens: @@ -159,7 +160,7 @@ def strips_random_ignored_tokens_between_non_punctuator_and_punctuator_tokens(): non_punctuator + "".join(ignored_tokens) + punctuator ).to_equal(non_punctuator + punctuator) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def replace_random_ignored_tokens_between_non_punctuator_and_spread_with_space(): for non_punctuator in non_punctuator_tokens: @@ -177,7 +178,7 @@ def replace_random_ignored_tokens_between_non_punctuator_and_spread_with_space() non_punctuator + " ..." ) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def replace_random_ignored_tokens_between_non_punctuator_tokens_with_space(): for left in non_punctuator_tokens: @@ -194,7 +195,7 @@ def replace_random_ignored_tokens_between_non_punctuator_tokens_with_space(): left + " " + right ) - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def does_not_strip_random_ignored_tokens_embedded_in_the_string(): for ignored in ignored_tokens: @@ -205,7 +206,7 @@ def does_not_strip_random_ignored_tokens_embedded_in_the_string(): ExpectStripped(dumps("".join(ignored_tokens))).to_stay_the_same() - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(10) def does_not_strip_random_ignored_tokens_embedded_in_the_block_string(): ignored_tokens_without_formatting = [ @@ -226,7 +227,7 @@ def does_not_strip_random_ignored_tokens_embedded_in_the_block_string(): '"""|' + "".join(ignored_tokens_without_formatting) + '|"""' ).to_stay_the_same() - @pytest.mark.slow() + @pytest.mark.slow @pytest.mark.timeout(80) def strips_ignored_characters_inside_random_block_strings(): # Testing with length >7 is taking exponentially more time. However it is diff --git a/tests/utilities/test_type_from_ast.py b/tests/utilities/test_type_from_ast.py index 282c8f50..fa75a9f9 100644 --- a/tests/utilities/test_type_from_ast.py +++ b/tests/utilities/test_type_from_ast.py @@ -1,4 +1,5 @@ import pytest + from graphql.language import TypeNode, parse_type from graphql.type import GraphQLList, GraphQLNonNull, GraphQLObjectType from graphql.utilities import type_from_ast diff --git a/tests/utils/test_assert_equal_awaitables_or_values.py b/tests/utils/test_assert_equal_awaitables_or_values.py index 214acfea..3e60fbcb 100644 --- a/tests/utils/test_assert_equal_awaitables_or_values.py +++ b/tests/utils/test_assert_equal_awaitables_or_values.py @@ -15,7 +15,7 @@ def does_not_throw_when_given_equal_values(): == test_value ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def does_not_throw_when_given_equal_awaitables(): async def test_value(): return {"test": "test"} @@ -27,7 +27,7 @@ async def test_value(): == await test_value() ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws_when_given_unequal_awaitables(): async def test_value(value): return value @@ -37,7 +37,7 @@ async def test_value(value): test_value({}), test_value({}), test_value({"test": "test"}) ) - @pytest.mark.asyncio() + @pytest.mark.asyncio async def throws_when_given_mixture_of_equal_values_and_awaitables(): async def test_value(): return {"test": "test"} diff --git a/tests/validation/test_validation.py b/tests/validation/test_validation.py index 37d57e9b..e8f08fe1 100644 --- a/tests/validation/test_validation.py +++ b/tests/validation/test_validation.py @@ -1,4 +1,5 @@ import pytest + from graphql.error import GraphQLError from graphql.language import parse from graphql.utilities import TypeInfo, build_schema diff --git a/tox.ini b/tox.ini index c261c70e..e5953a48 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ python = [testenv:ruff] basepython = python3.12 -deps = ruff>=0.5.7,<0.6 +deps = ruff>=0.6.4,<0.7 commands = ruff check src tests ruff format --check src tests