Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 17, 2024
1 parent 6546d32 commit bba81fd
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 144 deletions.
14 changes: 7 additions & 7 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ async def __call__(
__param: Application,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Request, Application]: ...
@overload
async def __call__(
self,
__param: BaseTestServer[_Request],
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[_Request, None]: ...


Expand All @@ -70,7 +70,7 @@ def __call__(
handler: _RequestHandler[BaseRequest],
*,
port: Optional[int] = None,
**kwargs: Any
**kwargs: Any,
) -> Awaitable[RawTestServer]: ...


Expand Down Expand Up @@ -332,7 +332,7 @@ async def go(
handler: _RequestHandler[BaseRequest],
*,
port: Optional[int] = None,
**kwargs: Any
**kwargs: Any,
) -> RawTestServer:
server = RawTestServer(handler, port=port)
await server.start_server(**kwargs)
Expand Down Expand Up @@ -392,20 +392,20 @@ async def go(
__param: Application,
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Request, Application]: ...
@overload
async def go(
__param: BaseTestServer[_Request],
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[_Request, None]: ...
async def go(
__param: Union[Application, BaseTestServer[Any]],
*,
server_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
**kwargs: Any,
) -> TestClient[Any, Any]:
if isinstance(__param, Application):
server_kwargs = server_kwargs or {}
Expand Down
7 changes: 4 additions & 3 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2993,9 +2993,10 @@ async def close(self) -> None:

connector = aiohttp.TCPConnector(resolver=FakeResolver(), ssl=False)

async with aiohttp.ClientSession(connector=connector) as client, client.get(
url_from, auth=aiohttp.BasicAuth("user", "pass")
) as resp:
async with (
aiohttp.ClientSession(connector=connector) as client,
client.get(url_from, auth=aiohttp.BasicAuth("user", "pass")) as resp,
):
assert len(resp.history) == 1
assert str(resp.url) == "http://example.com"
assert resp.status == 200
Expand Down
22 changes: 12 additions & 10 deletions tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,12 @@ async def create_connection(
return create_mocked_conn()

connector = session._connector
with mock.patch.object(connector, "connect", connect), mock.patch.object(
connector, "_create_connection", create_connection
), mock.patch.object(connector, "_release"), mock.patch(
"aiohttp.client.os"
) as m_os:
with (
mock.patch.object(connector, "connect", connect),
mock.patch.object(connector, "_create_connection", create_connection),
mock.patch.object(connector, "_release"),
mock.patch("aiohttp.client.os") as m_os,
):
m_os.urandom.return_value = key_data
await session.ws_connect(f"{protocol}://example")

Expand Down Expand Up @@ -635,11 +636,12 @@ async def create_connection(
return create_mocked_conn()

connector = session._connector
with mock.patch.object(connector, "connect", connect), mock.patch.object(
connector, "_create_connection", create_connection
), mock.patch.object(connector, "_release"), mock.patch(
"aiohttp.client.os"
) as m_os:
with (
mock.patch.object(connector, "connect", connect),
mock.patch.object(connector, "_create_connection", create_connection),
mock.patch.object(connector, "_release"),
mock.patch("aiohttp.client.os") as m_os,
):
m_os.urandom.return_value = key_data
await session.ws_connect(f"{protocol}://example")

Expand Down
29 changes: 17 additions & 12 deletions tests/test_client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ async def test_ws_connect_read_timeout_is_reset_to_inf(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = 0.5
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand All @@ -89,9 +90,10 @@ async def test_ws_connect_read_timeout_stays_inf(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = None
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand Down Expand Up @@ -120,9 +122,10 @@ async def test_ws_connect_read_timeout_reset_to_max(
hdrs.SEC_WEBSOCKET_PROTOCOL: "chat",
}
resp.connection.protocol.read_timeout = 0.5
with mock.patch("aiohttp.client.os") as m_os, mock.patch(
"aiohttp.client.ClientSession.request"
) as m_req:
with (
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(resp)
Expand Down Expand Up @@ -447,9 +450,11 @@ async def test_close_connection_lost(
hdrs.SEC_WEBSOCKET_ACCEPT: ws_key,
}
mresp.connection.protocol.read_timeout = None
with mock.patch("aiohttp.client.WebSocketWriter"), mock.patch(
"aiohttp.client.os"
) as m_os, mock.patch("aiohttp.client.ClientSession.request") as m_req:
with (
mock.patch("aiohttp.client.WebSocketWriter"),
mock.patch("aiohttp.client.os") as m_os,
mock.patch("aiohttp.client.ClientSession.request") as m_req,
):
m_os.urandom.return_value = key_data
m_req.return_value = loop.create_future()
m_req.return_value.set_result(mresp)
Expand Down
13 changes: 8 additions & 5 deletions tests/test_client_ws_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,14 @@ async def handler(request: web.Request) -> NoReturn:
# since if we closed the connection normally, the client would
# would cancel the heartbeat task and we wouldn't get a ping
assert resp._conn is not None
with mock.patch.object(
resp._conn.transport, "write", side_effect=ClientConnectionResetError
), mock.patch.object(
resp._writer, "send_frame", wraps=resp._writer.send_frame
) as send_frame:
with (
mock.patch.object(
resp._conn.transport, "write", side_effect=ClientConnectionResetError
),
mock.patch.object(
resp._writer, "send_frame", wraps=resp._writer.send_frame
) as send_frame,
):
await resp.receive()
ping_count = send_frame.call_args_list.count(mock.call(b"", WSMsgType.PING))
# Connection should be closed roughly after 1.5x heartbeat.
Expand Down
Loading

0 comments on commit bba81fd

Please sign in to comment.