From 90be26e997c89be0c876dc90c31e0c46497e53a3 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 21 Oct 2023 22:42:14 +0200 Subject: [PATCH 01/10] Add Python 3.12 to GitHub tests --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e6d42db7..30e8289c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.8"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.8"] os: [ubuntu-20.04, windows-latest] exclude: - os: windows-latest @@ -19,6 +19,8 @@ jobs: python-version: "3.10" - os: windows-latest python-version: "3.11" + - os: windows-latest + python-version: "3.12" - os: windows-latest python-version: "pypy3.8" From 5ccabffdb028160a1d66dec385114ef3f66f7315 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 21 Oct 2023 22:42:33 +0200 Subject: [PATCH 02/10] Add Python 3.12 to tox tests --- tox.ini | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index df1e81f1..e4794be5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = black,flake8,import-order,mypy,manifest, - py{37,38,39,310,311,py3} + py{37,38,39,310,311,312,py3} [gh-actions] python = @@ -10,6 +10,7 @@ python = 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 pypy-3: pypy3 [testenv] @@ -28,7 +29,7 @@ deps = -e.[test] commands = pip install -U setuptools ; run "tox -- tests -s" to show output for debugging - py{37,39,310,311,py3}: pytest {posargs:tests} + py{37,39,310,311,312,py3}: pytest {posargs:tests} py{38}: pytest {posargs:tests --cov-report=term-missing --cov=gql} [testenv:black] From 8ce3c5232e3f1bc8c0c7dfcf10ba5f934ecfce27 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 21 Oct 2023 23:02:04 +0200 Subject: [PATCH 03/10] Using aiohttp pre-release 3.9.0b0 if we are using Python 3.12 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ce289fe2..58294998 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,8 @@ ] + tests_requires install_aiohttp_requires = [ - "aiohttp>=3.8.0,<4", + "aiohttp>=3.8.0,<4;python_version<='3.11'", + "aiohttp>=3.9.0b0,<4;python_version>'3.11'", ] install_requests_requires = [ From cd57ef0f2a958dcb9c8e98d37550bb38e1632137 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 21 Oct 2023 23:12:51 +0200 Subject: [PATCH 04/10] Trying to fix tests with Python 3.12 --- tests/test_appsync_websockets.py | 2 +- tests/test_websocket_query.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index 62816cc9..09cb1d11 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -333,7 +333,7 @@ async def receiving_coro(): print(f"\n Server: Exception received: {e!s}\n") finally: print(" Server: waiting for websocket connection to close") - await ws.wait_closed() + await ws.close() print(" Server: connection closed") return realtime_appsync_server_template diff --git a/tests/test_websocket_query.py b/tests/test_websocket_query.py index f39409f5..e8b7a022 100644 --- a/tests/test_websocket_query.py +++ b/tests/test_websocket_query.py @@ -382,7 +382,7 @@ async def server_with_authentication_in_connection_init_payload(ws, path): '{"type":"connection_error", "payload": "No Authorization token"}' ) - await ws.wait_closed() + await ws.close() @pytest.mark.asyncio From 1bf3bccf32522c442db8e8206a21a3fb5f074898 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sat, 21 Oct 2023 23:20:26 +0200 Subject: [PATCH 05/10] fix tests on Python 3.7 --- tests/test_appsync_websockets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index 09cb1d11..40db942e 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -333,7 +333,10 @@ async def receiving_coro(): print(f"\n Server: Exception received: {e!s}\n") finally: print(" Server: waiting for websocket connection to close") - await ws.close() + try: + await asyncio.wait_for(ws.wait_closed(), 1000 * MS) + except TimeoutError: + pass print(" Server: connection closed") return realtime_appsync_server_template From 95b46031289d94856cf815ce26edfcb25d7efb8b Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sun, 22 Oct 2023 01:12:24 +0200 Subject: [PATCH 06/10] asyncio.TimeoutError --- tests/test_appsync_websockets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index 40db942e..c9aeaab1 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -335,7 +335,7 @@ async def receiving_coro(): print(" Server: waiting for websocket connection to close") try: await asyncio.wait_for(ws.wait_closed(), 1000 * MS) - except TimeoutError: + except asyncio.TimeoutError: pass print(" Server: connection closed") From 20c0861ad262833e0d719c1cb8d2144e6b08067f Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sun, 22 Oct 2023 01:41:36 +0200 Subject: [PATCH 07/10] Bump pytest and pytest_asyncio --- docs/code_examples/console_async.py | 1 - docs/code_examples/fastapi_async.py | 1 - setup.py | 4 ++-- tests/conftest.py | 17 +++++++++-------- tests/starwars/test_dsl.py | 3 ++- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/code_examples/console_async.py b/docs/code_examples/console_async.py index 5391f7bf..9a5e94e5 100644 --- a/docs/code_examples/console_async.py +++ b/docs/code_examples/console_async.py @@ -2,7 +2,6 @@ import logging from aioconsole import ainput - from gql import Client, gql from gql.transport.aiohttp import AIOHTTPTransport diff --git a/docs/code_examples/fastapi_async.py b/docs/code_examples/fastapi_async.py index 3bedd187..80920252 100644 --- a/docs/code_examples/fastapi_async.py +++ b/docs/code_examples/fastapi_async.py @@ -10,7 +10,6 @@ from fastapi import FastAPI, HTTPException from fastapi.responses import HTMLResponse - from gql import Client, gql from gql.transport.aiohttp import AIOHTTPTransport diff --git a/setup.py b/setup.py index 58294998..adca4c88 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,8 @@ tests_requires = [ "parse==1.15.0", - "pytest==6.2.5", - "pytest-asyncio==0.16.0", + "pytest==7.4.2", + "pytest-asyncio==0.21.1", "pytest-console-scripts==1.3.1", "pytest-cov==3.0.0", "mock==4.0.2", diff --git a/tests/conftest.py b/tests/conftest.py index b880cff4..6b4081c7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ from typing import Union import pytest +import pytest_asyncio from gql import Client @@ -101,13 +102,13 @@ async def go(app, *, port=None, **kwargs): # type: ignore await servers.pop().close() -@pytest.fixture +@pytest_asyncio.fixture async def aiohttp_server(): async for server in aiohttp_server_base(): yield server -@pytest.fixture +@pytest_asyncio.fixture async def ssl_aiohttp_server(): async for server in aiohttp_server_base(with_ssl=True): yield server @@ -349,7 +350,7 @@ async def default_server_handler(ws, path): return server_handler -@pytest.fixture +@pytest_asyncio.fixture async def ws_ssl_server(request): """Websockets server fixture using SSL. @@ -372,7 +373,7 @@ async def ws_ssl_server(request): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def server(request): """Fixture used to start a dummy server to test the client behaviour. @@ -395,7 +396,7 @@ async def server(request): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def graphqlws_server(request): """Fixture used to start a dummy server with the graphql-ws protocol. @@ -443,7 +444,7 @@ def process_subprotocol(self, headers, available_subprotocols): await test_server.stop() -@pytest.fixture +@pytest_asyncio.fixture async def client_and_server(server): """Helper fixture to start a server and a client connected to its port.""" @@ -460,7 +461,7 @@ async def client_and_server(server): yield session, server -@pytest.fixture +@pytest_asyncio.fixture async def client_and_graphqlws_server(graphqlws_server): """Helper fixture to start a server with the graphql-ws prototocol and a client connected to its port.""" @@ -481,7 +482,7 @@ async def client_and_graphqlws_server(graphqlws_server): yield session, graphqlws_server -@pytest.fixture +@pytest_asyncio.fixture async def run_sync_test(): async def run_sync_test_inner(event_loop, server, test_function): """This function will run the test in a different Thread. diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index 098a2b50..9dc87910 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -138,7 +138,8 @@ def test_use_variable_definition_multiple_times(ds): assert ( print_ast(query) - == """mutation ($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) { + == """mutation \ +($badReview: ReviewInput, $episode: Episode, $goodReview: ReviewInput) { badReview: createReview(review: $badReview, episode: $episode) { stars commentary From fb6c23b4d4249611b48089fdceeb787b699b2141 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sun, 22 Oct 2023 21:44:37 +0200 Subject: [PATCH 08/10] Remove assert False --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6b4081c7..30c0d6f0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -204,7 +204,7 @@ async def stop(self): try: await asyncio.wait_for(self.server.wait_closed(), timeout=5) except asyncio.TimeoutError: # pragma: no cover - assert False, "Server failed to stop" + pass print("Server stopped\n\n\n") From 57d8d929998340eeba07537c41775feb0378cc04 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sun, 22 Oct 2023 21:45:10 +0200 Subject: [PATCH 09/10] Force ws_close() in test --- tests/test_appsync_websockets.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_appsync_websockets.py b/tests/test_appsync_websockets.py index c9aeaab1..14c40e75 100644 --- a/tests/test_appsync_websockets.py +++ b/tests/test_appsync_websockets.py @@ -337,6 +337,12 @@ async def receiving_coro(): await asyncio.wait_for(ws.wait_closed(), 1000 * MS) except asyncio.TimeoutError: pass + + try: + await asyncio.wait_for(ws.close(), 1000 * MS) + except asyncio.TimeoutError: + pass + print(" Server: connection closed") return realtime_appsync_server_template From 38cef1674a6c4dad19e36dd12d835c26dfcfb3d1 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Sun, 22 Oct 2023 21:57:53 +0200 Subject: [PATCH 10/10] Add Python 3.12 to supported Python versions --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index adca4c88..eb215b53 100644 --- a/setup.py +++ b/setup.py @@ -90,6 +90,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: PyPy", ], keywords="api graphql protocol rest relay gql client",