Skip to content

Commit 7ca78e8

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent feeb6d0 commit 7ca78e8

File tree

2 files changed

+97
-54
lines changed

2 files changed

+97
-54
lines changed

tests/test_client_request.py

+84-24
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ def test_cookie_coded_value_preserved(event_loop: asyncio.AbstractEventLoop) ->
597597

598598

599599
async def test_connection_header(conn: mock.Mock) -> None:
600-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
600+
req = ClientRequest(
601+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
602+
)
601603
req.headers.clear()
602604

603605
req.version = HttpVersion11
@@ -626,23 +628,29 @@ async def test_connection_header(conn: mock.Mock) -> None:
626628

627629

628630
async def test_no_content_length(conn: mock.Mock) -> None:
629-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
631+
req = ClientRequest(
632+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
633+
)
630634
resp = await req.send(conn)
631635
assert req.headers.get("CONTENT-LENGTH") is None
632636
await req.close()
633637
resp.close()
634638

635639

636640
async def test_no_content_length_head(conn: mock.Mock) -> None:
637-
req = ClientRequest("head", URL("http://python.org"), loop=asyncio.get_running_loop())
641+
req = ClientRequest(
642+
"head", URL("http://python.org"), loop=asyncio.get_running_loop()
643+
)
638644
resp = await req.send(conn)
639645
assert req.headers.get("CONTENT-LENGTH") is None
640646
await req.close()
641647
resp.close()
642648

643649

644650
async def test_content_type_auto_header_get(conn: mock.Mock) -> None:
645-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
651+
req = ClientRequest(
652+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
653+
)
646654
resp = await req.send(conn)
647655
assert "CONTENT-TYPE" not in req.headers
648656
resp.close()
@@ -651,7 +659,10 @@ async def test_content_type_auto_header_get(conn: mock.Mock) -> None:
651659

652660
async def test_content_type_auto_header_form(conn: mock.Mock) -> None:
653661
req = ClientRequest(
654-
"post", URL("http://python.org"), data={"hey": "you"}, loop=asyncio.get_running_loop()
662+
"post",
663+
URL("http://python.org"),
664+
data={"hey": "you"},
665+
loop=asyncio.get_running_loop(),
655666
)
656667
resp = await req.send(conn)
657668
assert "application/x-www-form-urlencoded" == req.headers.get("CONTENT-TYPE")
@@ -660,7 +671,10 @@ async def test_content_type_auto_header_form(conn: mock.Mock) -> None:
660671

661672
async def test_content_type_auto_header_bytes(conn: mock.Mock) -> None:
662673
req = ClientRequest(
663-
"post", URL("http://python.org"), data=b"hey you", loop=asyncio.get_running_loop()
674+
"post",
675+
URL("http://python.org"),
676+
data=b"hey you",
677+
loop=asyncio.get_running_loop(),
664678
)
665679
resp = await req.send(conn)
666680
assert "application/octet-stream" == req.headers.get("CONTENT-TYPE")
@@ -741,7 +755,10 @@ async def test_formdata_boundary_from_headers(conn: mock.Mock) -> None:
741755
async def test_post_data(conn: mock.Mock) -> None:
742756
for meth in ClientRequest.POST_METHODS:
743757
req = ClientRequest(
744-
meth, URL("http://python.org/"), data={"life": "42"}, loop=asyncio.get_running_loop()
758+
meth,
759+
URL("http://python.org/"),
760+
data={"life": "42"},
761+
loop=asyncio.get_running_loop(),
745762
)
746763
resp = await req.send(conn)
747764
assert "/" == req.url.path
@@ -753,7 +770,9 @@ async def test_post_data(conn: mock.Mock) -> None:
753770

754771
async def test_pass_falsy_data() -> None:
755772
with mock.patch("aiohttp.client_reqrep.ClientRequest.update_body_from_data") as m:
756-
req = ClientRequest("post", URL("http://python.org/"), data={}, loop=asyncio.get_running_loop())
773+
req = ClientRequest(
774+
"post", URL("http://python.org/"), data={}, loop=asyncio.get_running_loop()
775+
)
757776
m.assert_called_once_with({})
758777
await req.close()
759778

@@ -779,7 +798,10 @@ async def test_pass_falsy_data_file(tmp_path: pathlib.Path) -> None:
779798
async def test_get_with_data() -> None:
780799
for meth in ClientRequest.GET_METHODS:
781800
req = ClientRequest(
782-
meth, URL("http://python.org/"), data={"life": "42"}, loop=asyncio.get_running_loop()
801+
meth,
802+
URL("http://python.org/"),
803+
data={"life": "42"},
804+
loop=asyncio.get_running_loop(),
783805
)
784806
assert "/" == req.url.path
785807
assert b"life=42" == req.body._value
@@ -789,7 +811,10 @@ async def test_get_with_data() -> None:
789811
async def test_bytes_data(conn: mock.Mock) -> None:
790812
for meth in ClientRequest.POST_METHODS:
791813
req = ClientRequest(
792-
meth, URL("http://python.org/"), data=b"binary data", loop=asyncio.get_running_loop()
814+
meth,
815+
URL("http://python.org/"),
816+
data=b"binary data",
817+
loop=asyncio.get_running_loop(),
793818
)
794819
resp = await req.send(conn)
795820
assert "/" == req.url.path
@@ -821,7 +846,10 @@ async def test_content_encoding(conn: mock.Mock) -> None:
821846

822847
async def test_content_encoding_dont_set_headers_if_no_body(conn: mock.Mock) -> None:
823848
req = ClientRequest(
824-
"post", URL("http://python.org/"), compress="deflate", loop=asyncio.get_running_loop()
849+
"post",
850+
URL("http://python.org/"),
851+
compress="deflate",
852+
loop=asyncio.get_running_loop(),
825853
)
826854
with mock.patch("aiohttp.client_reqrep.http"):
827855
resp = await req.send(conn)
@@ -944,7 +972,9 @@ async def test_chunked_transfer_encoding(conn: mock.Mock) -> None:
944972
async def test_file_upload_not_chunked() -> None:
945973
file_path = pathlib.Path(__file__).parent / "aiohttp.png"
946974
with file_path.open("rb") as f:
947-
req = ClientRequest("post", URL("http://python.org/"), data=f, loop=asyncio.get_running_loop())
975+
req = ClientRequest(
976+
"post", URL("http://python.org/"), data=f, loop=asyncio.get_running_loop()
977+
)
948978
assert not req.chunked
949979
assert req.headers["CONTENT-LENGTH"] == str(file_path.stat().st_size)
950980
await req.close()
@@ -971,7 +1001,9 @@ async def test_file_upload_not_chunked_seek() -> None:
9711001
file_path = pathlib.Path(__file__).parent / "aiohttp.png"
9721002
with file_path.open("rb") as f:
9731003
f.seek(100)
974-
req = ClientRequest("post", URL("http://python.org/"), data=f, loop=asyncio.get_running_loop())
1004+
req = ClientRequest(
1005+
"post", URL("http://python.org/"), data=f, loop=asyncio.get_running_loop()
1006+
)
9751007
assert req.headers["CONTENT-LENGTH"] == str(file_path.stat().st_size - 100)
9761008
await req.close()
9771009

@@ -980,7 +1012,11 @@ async def test_file_upload_force_chunked() -> None:
9801012
file_path = pathlib.Path(__file__).parent / "aiohttp.png"
9811013
with file_path.open("rb") as f:
9821014
req = ClientRequest(
983-
"post", URL("http://python.org/"), data=f, chunked=True, loop=asyncio.get_running_loop()
1015+
"post",
1016+
URL("http://python.org/"),
1017+
data=f,
1018+
chunked=True,
1019+
loop=asyncio.get_running_loop(),
9841020
)
9851021
assert req.chunked
9861022
assert "CONTENT-LENGTH" not in req.headers
@@ -989,7 +1025,10 @@ async def test_file_upload_force_chunked() -> None:
9891025

9901026
async def test_expect100(conn: mock.Mock) -> None:
9911027
req = ClientRequest(
992-
"get", URL("http://python.org/"), expect100=True, loop=asyncio.get_running_loop()
1028+
"get",
1029+
URL("http://python.org/"),
1030+
expect100=True,
1031+
loop=asyncio.get_running_loop(),
9931032
)
9941033
resp = await req.send(conn)
9951034
assert "100-continue" == req.headers["EXPECT"]
@@ -1017,7 +1056,9 @@ async def gen() -> AsyncIterator[bytes]:
10171056
yield b"binary data"
10181057
yield b" result"
10191058

1020-
req = ClientRequest("POST", URL("http://python.org/"), data=gen(), loop=asyncio.get_running_loop())
1059+
req = ClientRequest(
1060+
"POST", URL("http://python.org/"), data=gen(), loop=asyncio.get_running_loop()
1061+
)
10211062
assert req.chunked
10221063
assert req.headers["TRANSFER-ENCODING"] == "chunked"
10231064
original_write_bytes = req.write_bytes
@@ -1124,7 +1165,11 @@ async def gen() -> AsyncIterator[bytes]:
11241165
yield b" result"
11251166

11261167
req = ClientRequest(
1127-
"POST", URL("http://python.org/"), data=gen(), expect100=True, loop=asyncio.get_running_loop()
1168+
"POST",
1169+
URL("http://python.org/"),
1170+
data=gen(),
1171+
expect100=True,
1172+
loop=asyncio.get_running_loop(),
11281173
)
11291174
assert req.chunked
11301175

@@ -1174,7 +1219,9 @@ async def gen() -> AsyncIterator[bytes]:
11741219
await asyncio.sleep(0.00001)
11751220
yield b"result"
11761221

1177-
req = ClientRequest("POST", URL("http://python.org/"), data=gen(), loop=asyncio.get_running_loop())
1222+
req = ClientRequest(
1223+
"POST", URL("http://python.org/"), data=gen(), loop=asyncio.get_running_loop()
1224+
)
11781225
resp = await req.send(conn)
11791226
await req.close()
11801227
assert buf.split(b"\r\n\r\n", 1)[1] == b"6\r\nresult\r\n0\r\n\r\n"
@@ -1201,7 +1248,10 @@ async def read(self) -> bytes:
12011248
return b"customized!"
12021249

12031250
req = ClientRequest(
1204-
"GET", URL("http://python.org/"), response_class=CustomResponse, loop=asyncio.get_running_loop()
1251+
"GET",
1252+
URL("http://python.org/"),
1253+
response_class=CustomResponse,
1254+
loop=asyncio.get_running_loop(),
12051255
)
12061256
resp = await req.send(conn)
12071257
assert await resp.read() == b"customized!"
@@ -1210,7 +1260,9 @@ async def read(self) -> bytes:
12101260

12111261

12121262
async def test_oserror_on_write_bytes(conn: mock.Mock) -> None:
1213-
req = ClientRequest("POST", URL("http://python.org/"), loop=asyncio.get_running_loop())
1263+
req = ClientRequest(
1264+
"POST", URL("http://python.org/"), loop=asyncio.get_running_loop()
1265+
)
12141266

12151267
writer = WriterMock()
12161268
writer.write.side_effect = OSError
@@ -1224,7 +1276,9 @@ async def test_oserror_on_write_bytes(conn: mock.Mock) -> None:
12241276

12251277
@pytest.mark.skipif(sys.version_info < (3, 11), reason="Needs Task.cancelling()")
12261278
async def test_cancel_close(conn: mock.Mock) -> None:
1227-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
1279+
req = ClientRequest(
1280+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
1281+
)
12281282
req._writer = asyncio.Future() # type: ignore[assignment]
12291283

12301284
t = asyncio.create_task(req.close())
@@ -1239,7 +1293,9 @@ async def test_cancel_close(conn: mock.Mock) -> None:
12391293

12401294

12411295
async def test_terminate(conn: mock.Mock) -> None:
1242-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
1296+
req = ClientRequest(
1297+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
1298+
)
12431299

12441300
async def _mock_write_bytes(*args: object, **kwargs: object) -> None:
12451301
# Ensure the task is scheduled
@@ -1301,7 +1357,9 @@ async def _mock_write_bytes(*args: object, **kwargs: object) -> None:
13011357

13021358

13031359
def test_terminate_without_writer() -> None:
1304-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
1360+
req = ClientRequest(
1361+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
1362+
)
13051363
assert req._writer is None
13061364

13071365
req.terminate()
@@ -1380,7 +1438,9 @@ def test_insecure_fingerprint_sha1() -> None:
13801438

13811439

13821440
def test_loose_cookies_types() -> None:
1383-
req = ClientRequest("get", URL("http://python.org"), loop=asyncio.get_running_loop())
1441+
req = ClientRequest(
1442+
"get", URL("http://python.org"), loop=asyncio.get_running_loop()
1443+
)
13841444
morsel: "Morsel[str]" = Morsel()
13851445
morsel.set(key="string", val="Another string", coded_val="really")
13861446

0 commit comments

Comments
 (0)