@@ -597,7 +597,9 @@ def test_cookie_coded_value_preserved(event_loop: asyncio.AbstractEventLoop) ->
597
597
598
598
599
599
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
+ )
601
603
req .headers .clear ()
602
604
603
605
req .version = HttpVersion11
@@ -626,23 +628,29 @@ async def test_connection_header(conn: mock.Mock) -> None:
626
628
627
629
628
630
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
+ )
630
634
resp = await req .send (conn )
631
635
assert req .headers .get ("CONTENT-LENGTH" ) is None
632
636
await req .close ()
633
637
resp .close ()
634
638
635
639
636
640
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
+ )
638
644
resp = await req .send (conn )
639
645
assert req .headers .get ("CONTENT-LENGTH" ) is None
640
646
await req .close ()
641
647
resp .close ()
642
648
643
649
644
650
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
+ )
646
654
resp = await req .send (conn )
647
655
assert "CONTENT-TYPE" not in req .headers
648
656
resp .close ()
@@ -651,7 +659,10 @@ async def test_content_type_auto_header_get(conn: mock.Mock) -> None:
651
659
652
660
async def test_content_type_auto_header_form (conn : mock .Mock ) -> None :
653
661
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 (),
655
666
)
656
667
resp = await req .send (conn )
657
668
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:
660
671
661
672
async def test_content_type_auto_header_bytes (conn : mock .Mock ) -> None :
662
673
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 (),
664
678
)
665
679
resp = await req .send (conn )
666
680
assert "application/octet-stream" == req .headers .get ("CONTENT-TYPE" )
@@ -741,7 +755,10 @@ async def test_formdata_boundary_from_headers(conn: mock.Mock) -> None:
741
755
async def test_post_data (conn : mock .Mock ) -> None :
742
756
for meth in ClientRequest .POST_METHODS :
743
757
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 (),
745
762
)
746
763
resp = await req .send (conn )
747
764
assert "/" == req .url .path
@@ -753,7 +770,9 @@ async def test_post_data(conn: mock.Mock) -> None:
753
770
754
771
async def test_pass_falsy_data () -> None :
755
772
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
+ )
757
776
m .assert_called_once_with ({})
758
777
await req .close ()
759
778
@@ -779,7 +798,10 @@ async def test_pass_falsy_data_file(tmp_path: pathlib.Path) -> None:
779
798
async def test_get_with_data () -> None :
780
799
for meth in ClientRequest .GET_METHODS :
781
800
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 (),
783
805
)
784
806
assert "/" == req .url .path
785
807
assert b"life=42" == req .body ._value
@@ -789,7 +811,10 @@ async def test_get_with_data() -> None:
789
811
async def test_bytes_data (conn : mock .Mock ) -> None :
790
812
for meth in ClientRequest .POST_METHODS :
791
813
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 (),
793
818
)
794
819
resp = await req .send (conn )
795
820
assert "/" == req .url .path
@@ -821,7 +846,10 @@ async def test_content_encoding(conn: mock.Mock) -> None:
821
846
822
847
async def test_content_encoding_dont_set_headers_if_no_body (conn : mock .Mock ) -> None :
823
848
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 (),
825
853
)
826
854
with mock .patch ("aiohttp.client_reqrep.http" ):
827
855
resp = await req .send (conn )
@@ -944,7 +972,9 @@ async def test_chunked_transfer_encoding(conn: mock.Mock) -> None:
944
972
async def test_file_upload_not_chunked () -> None :
945
973
file_path = pathlib .Path (__file__ ).parent / "aiohttp.png"
946
974
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
+ )
948
978
assert not req .chunked
949
979
assert req .headers ["CONTENT-LENGTH" ] == str (file_path .stat ().st_size )
950
980
await req .close ()
@@ -971,7 +1001,9 @@ async def test_file_upload_not_chunked_seek() -> None:
971
1001
file_path = pathlib .Path (__file__ ).parent / "aiohttp.png"
972
1002
with file_path .open ("rb" ) as f :
973
1003
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
+ )
975
1007
assert req .headers ["CONTENT-LENGTH" ] == str (file_path .stat ().st_size - 100 )
976
1008
await req .close ()
977
1009
@@ -980,7 +1012,11 @@ async def test_file_upload_force_chunked() -> None:
980
1012
file_path = pathlib .Path (__file__ ).parent / "aiohttp.png"
981
1013
with file_path .open ("rb" ) as f :
982
1014
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 (),
984
1020
)
985
1021
assert req .chunked
986
1022
assert "CONTENT-LENGTH" not in req .headers
@@ -989,7 +1025,10 @@ async def test_file_upload_force_chunked() -> None:
989
1025
990
1026
async def test_expect100 (conn : mock .Mock ) -> None :
991
1027
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 (),
993
1032
)
994
1033
resp = await req .send (conn )
995
1034
assert "100-continue" == req .headers ["EXPECT" ]
@@ -1017,7 +1056,9 @@ async def gen() -> AsyncIterator[bytes]:
1017
1056
yield b"binary data"
1018
1057
yield b" result"
1019
1058
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
+ )
1021
1062
assert req .chunked
1022
1063
assert req .headers ["TRANSFER-ENCODING" ] == "chunked"
1023
1064
original_write_bytes = req .write_bytes
@@ -1124,7 +1165,11 @@ async def gen() -> AsyncIterator[bytes]:
1124
1165
yield b" result"
1125
1166
1126
1167
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 (),
1128
1173
)
1129
1174
assert req .chunked
1130
1175
@@ -1174,7 +1219,9 @@ async def gen() -> AsyncIterator[bytes]:
1174
1219
await asyncio .sleep (0.00001 )
1175
1220
yield b"result"
1176
1221
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
+ )
1178
1225
resp = await req .send (conn )
1179
1226
await req .close ()
1180
1227
assert buf .split (b"\r \n \r \n " , 1 )[1 ] == b"6\r \n result\r \n 0\r \n \r \n "
@@ -1201,7 +1248,10 @@ async def read(self) -> bytes:
1201
1248
return b"customized!"
1202
1249
1203
1250
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 (),
1205
1255
)
1206
1256
resp = await req .send (conn )
1207
1257
assert await resp .read () == b"customized!"
@@ -1210,7 +1260,9 @@ async def read(self) -> bytes:
1210
1260
1211
1261
1212
1262
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
+ )
1214
1266
1215
1267
writer = WriterMock ()
1216
1268
writer .write .side_effect = OSError
@@ -1224,7 +1276,9 @@ async def test_oserror_on_write_bytes(conn: mock.Mock) -> None:
1224
1276
1225
1277
@pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "Needs Task.cancelling()" )
1226
1278
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
+ )
1228
1282
req ._writer = asyncio .Future () # type: ignore[assignment]
1229
1283
1230
1284
t = asyncio .create_task (req .close ())
@@ -1239,7 +1293,9 @@ async def test_cancel_close(conn: mock.Mock) -> None:
1239
1293
1240
1294
1241
1295
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
+ )
1243
1299
1244
1300
async def _mock_write_bytes (* args : object , ** kwargs : object ) -> None :
1245
1301
# Ensure the task is scheduled
@@ -1301,7 +1357,9 @@ async def _mock_write_bytes(*args: object, **kwargs: object) -> None:
1301
1357
1302
1358
1303
1359
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
+ )
1305
1363
assert req ._writer is None
1306
1364
1307
1365
req .terminate ()
@@ -1380,7 +1438,9 @@ def test_insecure_fingerprint_sha1() -> None:
1380
1438
1381
1439
1382
1440
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
+ )
1384
1444
morsel : "Morsel[str]" = Morsel ()
1385
1445
morsel .set (key = "string" , val = "Another string" , coded_val = "really" )
1386
1446
0 commit comments