Skip to content

Commit 779653c

Browse files
TesterTester
Tester
authored and
Tester
committed
format tests/_(a)sync to pass unasync check
1 parent 5c176c7 commit 779653c

12 files changed

+155
-31
lines changed

tests/_async/test_connection.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ async def test_concurrent_requests_not_available_on_http11_connections():
8686
await conn.request("GET", "https://example.com/")
8787

8888

89-
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
9089
@pytest.mark.anyio
90+
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
9191
async def test_write_error_with_response_sent():
9292
"""
9393
If a server half-closes the connection while the client is sending
@@ -103,7 +103,9 @@ def __init__(self, buffer: typing.List[bytes], http2: bool = False) -> None:
103103
self.count = 0
104104

105105
async def write(
106-
self, buffer: bytes, timeout: typing.Optional[float] = None
106+
self,
107+
buffer: bytes,
108+
timeout: typing.Optional[float] = None,
107109
) -> None:
108110
self.count += len(buffer)
109111

@@ -157,7 +159,9 @@ def __init__(self, buffer: typing.List[bytes], http2: bool = False) -> None:
157159
self.count = 0
158160

159161
async def write(
160-
self, buffer: bytes, timeout: typing.Optional[float] = None
162+
self,
163+
buffer: bytes,
164+
timeout: typing.Optional[float] = None,
161165
) -> None:
162166
self.count += len(buffer)
163167

@@ -212,7 +216,9 @@ async def test_http2_connection():
212216
)
213217

214218
async with AsyncHTTPConnection(
215-
origin=origin, network_backend=network_backend, http2=True
219+
origin=origin,
220+
network_backend=network_backend,
221+
http2=True,
216222
) as conn:
217223
response = await conn.request("GET", "https://example.com/")
218224

@@ -229,7 +235,8 @@ async def test_request_to_incorrect_origin():
229235
origin = Origin(b"https", b"example.com", 443)
230236
network_backend = AsyncMockBackend([])
231237
async with AsyncHTTPConnection(
232-
origin=origin, network_backend=network_backend
238+
origin=origin,
239+
network_backend=network_backend,
233240
) as conn:
234241
with pytest.raises(RuntimeError):
235242
await conn.request("GET", "https://other.com/")
@@ -266,18 +273,24 @@ async def connect_tcp(
266273

267274
class _NeedsRetryAsyncNetworkStream(AsyncNetworkStream):
268275
def __init__(
269-
self, backend: "NeedsRetryBackend", stream: AsyncNetworkStream
276+
self,
277+
backend: "NeedsRetryBackend",
278+
stream: AsyncNetworkStream,
270279
) -> None:
271280
self._backend = backend
272281
self._stream = stream
273282

274283
async def read(
275-
self, max_bytes: int, timeout: typing.Optional[float] = None
284+
self,
285+
max_bytes: int,
286+
timeout: typing.Optional[float] = None,
276287
) -> bytes:
277288
return await self._stream.read(max_bytes, timeout)
278289

279290
async def write(
280-
self, buffer: bytes, timeout: typing.Optional[float] = None
291+
self,
292+
buffer: bytes,
293+
timeout: typing.Optional[float] = None,
281294
) -> None:
282295
await self._stream.write(buffer, timeout)
283296

tests/_async/test_connection_pool.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ async def trace(name, kwargs):
399399
# Sending an initial request, which once complete will not return to the pool.
400400
with pytest.raises(Exception):
401401
await pool.request(
402-
"GET", "https://example.com/", extensions={"trace": trace}
402+
"GET",
403+
"https://example.com/",
404+
extensions={"trace": trace},
403405
)
404406

405407
info = [repr(c) for c in pool.connections]
@@ -452,7 +454,9 @@ async def trace(name, kwargs):
452454
# Sending an initial request, which once complete will not return to the pool.
453455
with pytest.raises(Exception):
454456
await pool.request(
455-
"GET", "https://example.com/", extensions={"trace": trace}
457+
"GET",
458+
"https://example.com/",
459+
extensions={"trace": trace},
456460
)
457461

458462
info = [repr(c) for c in pool.connections]
@@ -775,13 +779,17 @@ async def test_connection_pool_timeout_zero():
775779
# Two consecutive requests with a pool timeout of zero.
776780
# Both succeed without raising a timeout.
777781
response = await pool.request(
778-
"GET", "https://example.com/", extensions=extensions
782+
"GET",
783+
"https://example.com/",
784+
extensions=extensions,
779785
)
780786
assert response.status == 200
781787
assert response.content == b"Hello, world!"
782788

783789
response = await pool.request(
784-
"GET", "https://example.com/", extensions=extensions
790+
"GET",
791+
"https://example.com/",
792+
extensions=extensions,
785793
)
786794
assert response.status == 200
787795
assert response.content == b"Hello, world!"

tests/_async/test_http11.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def test_http11_connection():
2929
assert repr(conn) == (
3030
"<AsyncHTTP11Connection ['https://example.com:443', IDLE,"
3131
" Request Count: 1]>"
32-
)
32+
) # fmt: skip
3333

3434

3535
@pytest.mark.anyio

tests/_async/test_http2.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ async def test_http2_connection():
4141
conn.info() == "'https://example.com:443', HTTP/2, IDLE, Request Count: 1"
4242
)
4343
assert repr(conn) == (
44-
"<AsyncHTTP2Connection ['https://example.com:443', IDLE,"
45-
" Request Count: 1]>"
44+
"<AsyncHTTP2Connection ['https://example.com:443', IDLE, Request Count: 1]>"
4645
)
4746

4847

tests/_sync/test_connection.py

+41-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020

2121

22+
# unasync anyio
2223
def test_http_connection():
2324
origin = Origin(b"https", b"example.com", 443)
2425
network_backend = MockBackend(
@@ -60,6 +61,7 @@ def test_http_connection():
6061
)
6162

6263

64+
# unasync anyio
6365
def test_concurrent_requests_not_available_on_http11_connections():
6466
"""
6567
Attempting to issue a request against an already active HTTP/1.1 connection
@@ -84,6 +86,7 @@ def test_concurrent_requests_not_available_on_http11_connections():
8486
conn.request("GET", "https://example.com/")
8587

8688

89+
# unasync anyio
8790
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
8891
def test_write_error_with_response_sent():
8992
"""
@@ -99,7 +102,11 @@ def __init__(self, buffer: typing.List[bytes], http2: bool = False) -> None:
99102
super().__init__(buffer, http2)
100103
self.count = 0
101104

102-
def write(self, buffer: bytes, timeout: typing.Optional[float] = None) -> None:
105+
def write(
106+
self,
107+
buffer: bytes,
108+
timeout: typing.Optional[float] = None,
109+
) -> None:
103110
self.count += len(buffer)
104111

105112
if self.count > 1_000_000:
@@ -136,6 +143,7 @@ def connect_tcp(
136143
assert response.content == b"Request body exceeded 1,000,000 bytes"
137144

138145

146+
# unasync anyio
139147
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
140148
def test_write_error_without_response_sent():
141149
"""
@@ -150,7 +158,11 @@ def __init__(self, buffer: typing.List[bytes], http2: bool = False) -> None:
150158
super().__init__(buffer, http2)
151159
self.count = 0
152160

153-
def write(self, buffer: bytes, timeout: typing.Optional[float] = None) -> None:
161+
def write(
162+
self,
163+
buffer: bytes,
164+
timeout: typing.Optional[float] = None,
165+
) -> None:
154166
self.count += len(buffer)
155167

156168
if self.count > 1_000_000:
@@ -179,6 +191,7 @@ def connect_tcp(
179191
assert str(exc_info.value) == "Server disconnected without sending a response."
180192

181193

194+
# unasync anyio
182195
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
183196
def test_http2_connection():
184197
origin = Origin(b"https", b"example.com", 443)
@@ -203,7 +216,9 @@ def test_http2_connection():
203216
)
204217

205218
with HTTPConnection(
206-
origin=origin, network_backend=network_backend, http2=True
219+
origin=origin,
220+
network_backend=network_backend,
221+
http2=True,
207222
) as conn:
208223
response = conn.request("GET", "https://example.com/")
209224

@@ -212,13 +227,17 @@ def test_http2_connection():
212227
assert response.extensions["http_version"] == b"HTTP/2"
213228

214229

230+
# unasync anyio
215231
def test_request_to_incorrect_origin():
216232
"""
217233
A connection can only send requests whichever origin it is connected to.
218234
"""
219235
origin = Origin(b"https", b"example.com", 443)
220236
network_backend = MockBackend([])
221-
with HTTPConnection(origin=origin, network_backend=network_backend) as conn:
237+
with HTTPConnection(
238+
origin=origin,
239+
network_backend=network_backend,
240+
) as conn:
222241
with pytest.raises(RuntimeError):
223242
conn.request("GET", "https://other.com/")
224243

@@ -253,14 +272,26 @@ def connect_tcp(
253272
return self._NeedsRetryAsyncNetworkStream(self, stream)
254273

255274
class _NeedsRetryAsyncNetworkStream(NetworkStream):
256-
def __init__(self, backend: "NeedsRetryBackend", stream: NetworkStream) -> None:
275+
def __init__(
276+
self,
277+
backend: "NeedsRetryBackend",
278+
stream: NetworkStream,
279+
) -> None:
257280
self._backend = backend
258281
self._stream = stream
259282

260-
def read(self, max_bytes: int, timeout: typing.Optional[float] = None) -> bytes:
283+
def read(
284+
self,
285+
max_bytes: int,
286+
timeout: typing.Optional[float] = None,
287+
) -> bytes:
261288
return self._stream.read(max_bytes, timeout)
262289

263-
def write(self, buffer: bytes, timeout: typing.Optional[float] = None) -> None:
290+
def write(
291+
self,
292+
buffer: bytes,
293+
timeout: typing.Optional[float] = None,
294+
) -> None:
264295
self._stream.write(buffer, timeout)
265296

266297
def close(self) -> None:
@@ -283,6 +314,7 @@ def get_extra_info(self, info: str) -> typing.Any:
283314
return self._stream.get_extra_info(info)
284315

285316

317+
# unasync anyio
286318
def test_connection_retries():
287319
origin = Origin(b"https", b"example.com", 443)
288320
content = [
@@ -309,6 +341,7 @@ def test_connection_retries():
309341
conn.request("GET", "https://example.com/")
310342

311343

344+
# unasync anyio
312345
def test_connection_retries_tls():
313346
origin = Origin(b"https", b"example.com", 443)
314347
content = [
@@ -339,6 +372,7 @@ def test_connection_retries_tls():
339372
conn.request("GET", "https://example.com/")
340373

341374

375+
# unasync anyio
342376
def test_uds_connections():
343377
# We're not actually testing Unix Domain Sockets here, because we're just
344378
# using a mock backend, but at least we're covering the UDS codepath

0 commit comments

Comments
 (0)