Skip to content

Commit 045c904

Browse files
igor.stulikovigor.stulikov
igor.stulikov
authored and
igor.stulikov
committed
Fix imports and black (encode#550)
1 parent e061990 commit 045c904

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

httpcore/_async/connection_pool.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ async def _attempt_to_acquire_connection(self, status: RequestStatus) -> bool:
174174

175175
# Attempt to close CONNECTING connections that no one needs
176176
if self._is_pool_full:
177-
for idx, connection in enumerate(self._pool): # Try to check old connections first
177+
for idx, connection in enumerate(
178+
self._pool
179+
): # Try to check old connections first
178180
if not connection.is_connecting():
179181
continue
180182
for req_status in self._requests:

httpcore/backends/mock.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import anyio
77

88
from httpcore import ReadTimeout
9-
from .base import AsyncNetworkBackend, AsyncNetworkStream, NetworkBackend, NetworkStream
9+
1010
from .._exceptions import ReadError
11+
from .base import AsyncNetworkBackend, AsyncNetworkStream, NetworkBackend, NetworkStream
1112

1213

1314
class MockSSLObject:
@@ -59,10 +60,10 @@ def read(self, max_bytes: int, timeout: Optional[float] = None) -> bytes:
5960

6061
class MockBackend(NetworkBackend):
6162
def __init__(
62-
self,
63-
buffer: typing.List[bytes],
64-
http2: bool = False,
65-
resp_stream_cls: Optional[Type[NetworkStream]] = None,
63+
self,
64+
buffer: typing.List[bytes],
65+
http2: bool = False,
66+
resp_stream_cls: Optional[Type[NetworkStream]] = None,
6667
) -> None:
6768
self._buffer = buffer
6869
self._http2 = http2
@@ -127,14 +128,16 @@ async def read(self, max_bytes: int, timeout: Optional[float] = None) -> bytes:
127128

128129
class AsyncMockBackend(AsyncNetworkBackend):
129130
def __init__(
130-
self,
131-
buffer: typing.List[bytes],
132-
http2: bool = False,
133-
resp_stream_cls: Optional[Type[AsyncNetworkStream]] = None,
131+
self,
132+
buffer: typing.List[bytes],
133+
http2: bool = False,
134+
resp_stream_cls: Optional[Type[AsyncNetworkStream]] = None,
134135
) -> None:
135136
self._buffer = buffer
136137
self._http2 = http2
137-
self._resp_stream_cls: Type[AsyncMockStream] = resp_stream_cls or AsyncMockStream
138+
self._resp_stream_cls: Type[AsyncMockStream] = (
139+
resp_stream_cls or AsyncMockStream
140+
)
138141

139142
async def connect_tcp(
140143
self,

tests/_async/test_connection_pool.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
AsyncConnectionPool,
99
ConnectError,
1010
PoolTimeout,
11-
ReadTimeout,
1211
ReadError,
12+
ReadTimeout,
1313
UnsupportedProtocol,
1414
)
1515
from httpcore.backends.base import AsyncNetworkStream
16-
from httpcore.backends.mock import AsyncMockBackend, AsyncHangingStream
16+
from httpcore.backends.mock import AsyncHangingStream, AsyncMockBackend
1717

1818

1919
@pytest.mark.anyio
@@ -514,16 +514,16 @@ async def test_pool_under_load():
514514
async def fetch(_pool: AsyncConnectionPool, *exceptions: Type[BaseException]):
515515
with contextlib.suppress(*exceptions):
516516
async with pool.stream(
517-
"GET",
518-
"http://a.com/",
519-
extensions={
520-
"timeout": {
521-
"connect": 0.1,
522-
"read": 0.1,
523-
"pool": 0.1,
524-
"write": 0.1,
525-
},
517+
"GET",
518+
"http://a.com/",
519+
extensions={
520+
"timeout": {
521+
"connect": 0.1,
522+
"read": 0.1,
523+
"pool": 0.1,
524+
"write": 0.1,
526525
},
526+
},
527527
) as response:
528528
await response.aread()
529529

@@ -537,11 +537,12 @@ async def fetch(_pool: AsyncConnectionPool, *exceptions: Type[BaseException]):
537537
nursery.start_soon(fetch, pool, PoolTimeout, ReadTimeout)
538538
if pool.connections: # There is one connection in pool in "CONNECTING" state
539539
assert pool.connections[0].is_connecting()
540-
with pytest.raises(ReadTimeout): # ReadTimeout indicates that connection could be retrieved
540+
with pytest.raises(
541+
ReadTimeout
542+
): # ReadTimeout indicates that connection could be retrieved
541543
await fetch(pool)
542544

543545

544-
545546
@pytest.mark.trio
546547
async def test_pool_timeout_connection_cleanup():
547548
"""
@@ -555,7 +556,8 @@ async def test_pool_timeout_connection_cleanup():
555556
b"Content-Length: 13\r\n",
556557
b"\r\n",
557558
b"Hello, world!",
558-
] * 2,
559+
]
560+
* 2,
559561
)
560562

561563
async with AsyncConnectionPool(
@@ -568,12 +570,18 @@ async def test_pool_timeout_connection_cleanup():
568570
"write": 0.1,
569571
}
570572
with contextlib.suppress(PoolTimeout):
571-
await pool.request("GET", "https://example.com/", extensions={"timeout": timeout})
573+
await pool.request(
574+
"GET", "https://example.com/", extensions={"timeout": timeout}
575+
)
572576

573577
# wait for a considerable amount of time to make sure all requests time out
574578
await concurrency.sleep(0.1)
575579

576-
await pool.request("GET", "https://example.com/", extensions={"timeout": {**timeout, 'pool': 0.1}})
580+
await pool.request(
581+
"GET",
582+
"https://example.com/",
583+
extensions={"timeout": {**timeout, "pool": 0.1}},
584+
)
577585

578586
if pool.connections:
579587
for conn in pool.connections:

tests/_sync/test_connection_pool.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import pytest
66

77
from httpcore import (
8-
ConnectionPool,
98
ConnectError,
9+
ConnectionPool,
1010
PoolTimeout,
11-
ReadTimeout,
1211
ReadError,
12+
ReadTimeout,
1313
UnsupportedProtocol,
1414
)
1515
from httpcore.backends.base import NetworkStream
16-
from httpcore.backends.mock import MockBackend, HangingStream
16+
from httpcore.backends.mock import HangingStream, MockBackend
1717
from tests import concurrency
1818

1919

0 commit comments

Comments
 (0)