From 1e4e87d5154b02d358227ff33c4e2ed5a3791ec1 Mon Sep 17 00:00:00 2001 From: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com> Date: Sat, 10 Aug 2024 09:33:49 +0530 Subject: [PATCH] Support for Python 3.12 (#1444) * Support for Python 3.12 * Use `assert_called_once_with` and not `called_once_with` * lint fix * Fix `test_pac_file_served_from_disk` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/test-library.yml | 3 ++- proxy/http/handler.py | 4 +-- tests/http/web/test_web_server.py | 41 +++++++++++++++++++----------- tox.ini | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test-library.yml b/.github/workflows/test-library.yml index 86fe2180..88e9d407 100644 --- a/.github/workflows/test-library.yml +++ b/.github/workflows/test-library.yml @@ -446,8 +446,9 @@ jobs: # NOTE: The latest and the lowest supported Pythons are prioritized # NOTE: to improve the responsiveness. It's nice to see the most # NOTE: important results first. - - '3.11' + - '3.12' - 3.6 + - '3.11' - '3.10' - 3.9 - 3.8 diff --git a/proxy/http/handler.py b/proxy/http/handler.py index 0bdcfa22..5120d5b3 100644 --- a/proxy/http/handler.py +++ b/proxy/http/handler.py @@ -292,9 +292,7 @@ class HttpProtocolHandler(BaseTcpServerHandler[HttpClientConnection]): return True # Discover which HTTP handler plugin is capable of # handling the current incoming request - klass = self._discover_plugin_klass( - self.request.http_handler_protocol, - ) + klass = self._discover_plugin_klass(self.request.http_handler_protocol) if klass is None: # No matching protocol class found. # Return bad request response and diff --git a/tests/http/web/test_web_server.py b/tests/http/web/test_web_server.py index 71baac4f..8100d995 100644 --- a/tests/http/web/test_web_server.py +++ b/tests/http/web/test_web_server.py @@ -59,19 +59,6 @@ def test_on_client_connection_called_on_teardown(mocker: MockerFixture) -> None: assert _conn.closed -def mock_selector_for_client_read(self: Any) -> None: - self.mock_selector.return_value.select.return_value = [ - ( - selectors.SelectorKey( - fileobj=self._conn.fileno(), - fd=self._conn.fileno(), - events=selectors.EVENT_READ, - data=None, - ), - selectors.EVENT_READ, - ), - ] - # @mock.patch('socket.fromfd') # def test_on_client_connection_called_on_teardown( # self, mock_fromfd: mock.Mock, @@ -171,16 +158,40 @@ class TestWebServerPluginWithPacFilePlugin(Assertions): b'GET / HTTP/1.1', CRLF, ]) - mock_selector_for_client_read(self) + self.mock_selector.return_value.select.side_effect = [ + [ + ( + selectors.SelectorKey( + fileobj=self._conn.fileno(), + fd=self._conn.fileno(), + events=selectors.EVENT_READ, + data=None, + ), + selectors.EVENT_READ, + ), + ], + [ + ( + selectors.SelectorKey( + fileobj=self._conn.fileno(), + fd=self._conn.fileno(), + events=selectors.EVENT_WRITE, + data=None, + ), + selectors.EVENT_WRITE, + ), + ], + ] @pytest.mark.asyncio # type: ignore[misc] async def test_pac_file_served_from_disk(self) -> None: + await self.protocol_handler._run_once() await self.protocol_handler._run_once() self.assertEqual( self.protocol_handler.request.state, httpParserStates.COMPLETE, ) - self._conn.send.called_once_with( + self._conn.send.assert_called_once_with( build_http_response( 200, reason=b'OK', diff --git a/tox.ini b/tox.ini index 5e7d706a..37f686ca 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,py37,py38,py39,py310,py311 +envlist = py36,py37,py38,py39,py310,py311,py312 isolated_build = true minversion = 3.21.0