1111
1212import aiohttp
1313from aiohttp import payload
14+ from aiohttp .abc import AbstractStreamWriter
1415from aiohttp .compression_utils import ZLibBackend
1516from aiohttp .hdrs import (
1617 CONTENT_DISPOSITION ,
@@ -44,7 +45,7 @@ def buf() -> bytearray:
4445
4546@pytest .fixture
4647def stream (buf : bytearray ) -> mock .Mock :
47- writer = mock .Mock ( )
48+ writer = mock .create_autospec ( AbstractStreamWriter , instance = True , spec_set = True )
4849
4950 async def write (chunk : bytes ) -> None :
5051 buf .extend (chunk )
@@ -1021,7 +1022,7 @@ async def test_writer(writer: aiohttp.MultipartWriter) -> None:
10211022
10221023
10231024async def test_writer_serialize_io_chunk (
1024- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1025+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
10251026) -> None :
10261027 with io .BytesIO (b"foobarbaz" ) as file_handle :
10271028 writer .append (file_handle )
@@ -1033,7 +1034,7 @@ async def test_writer_serialize_io_chunk(
10331034
10341035
10351036async def test_writer_serialize_json (
1036- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1037+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
10371038) -> None :
10381039 writer .append_json ({"привет" : "мир" })
10391040 await writer .write (stream )
@@ -1044,7 +1045,7 @@ async def test_writer_serialize_json(
10441045
10451046
10461047async def test_writer_serialize_form (
1047- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1048+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
10481049) -> None :
10491050 data = [("foo" , "bar" ), ("foo" , "baz" ), ("boo" , "zoo" )]
10501051 writer .append_form (data )
@@ -1054,7 +1055,7 @@ async def test_writer_serialize_form(
10541055
10551056
10561057async def test_writer_serialize_form_dict (
1057- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1058+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
10581059) -> None :
10591060 data = {"hello" : "мир" }
10601061 writer .append_form (data )
@@ -1064,7 +1065,7 @@ async def test_writer_serialize_form_dict(
10641065
10651066
10661067async def test_writer_write (
1067- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1068+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
10681069) -> None :
10691070 writer .append ("foo-bar-baz" )
10701071 writer .append_json ({"test" : "passed" })
@@ -1111,7 +1112,7 @@ async def test_writer_write(
11111112 ) == bytes (buf )
11121113
11131114
1114- async def test_writer_write_no_close_boundary (buf : bytearray , stream : Stream ) -> None :
1115+ async def test_writer_write_no_close_boundary (buf : bytearray , stream : AbstractStreamWriter ) -> None :
11151116 writer = aiohttp .MultipartWriter (boundary = ":" )
11161117 writer .append ("foo-bar-baz" )
11171118 writer .append_json ({"test" : "passed" })
@@ -1144,7 +1145,7 @@ async def test_writer_write_no_close_boundary(buf: bytearray, stream: Stream) ->
11441145
11451146
11461147async def test_writer_write_no_parts (
1147- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1148+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
11481149) -> None :
11491150 await writer .write (stream )
11501151 assert b"--:--\r \n " == bytes (buf )
@@ -1153,7 +1154,7 @@ async def test_writer_write_no_parts(
11531154@pytest .mark .usefixtures ("parametrize_zlib_backend" )
11541155async def test_writer_serialize_with_content_encoding_gzip (
11551156 buf : bytearray ,
1156- stream : Stream ,
1157+ stream : AbstractStreamWriter ,
11571158 writer : aiohttp .MultipartWriter ,
11581159) -> None :
11591160 writer .append ("Time to Relax!" , {CONTENT_ENCODING : "gzip" })
@@ -1172,7 +1173,7 @@ async def test_writer_serialize_with_content_encoding_gzip(
11721173
11731174
11741175async def test_writer_serialize_with_content_encoding_deflate (
1175- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1176+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
11761177) -> None :
11771178 writer .append ("Time to Relax!" , {CONTENT_ENCODING : "deflate" })
11781179 await writer .write (stream )
@@ -1188,7 +1189,7 @@ async def test_writer_serialize_with_content_encoding_deflate(
11881189
11891190
11901191async def test_writer_serialize_with_content_encoding_identity (
1191- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1192+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
11921193) -> None :
11931194 thing = b"\x0b \xc9 \xcc MU(\xc9 W\x08 J\xcd I\xac P\x04 \x00 "
11941195 writer .append (thing , {CONTENT_ENCODING : "identity" })
@@ -1205,14 +1206,14 @@ async def test_writer_serialize_with_content_encoding_identity(
12051206
12061207
12071208def test_writer_serialize_with_content_encoding_unknown (
1208- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1209+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
12091210) -> None :
12101211 with pytest .raises (RuntimeError ):
12111212 writer .append ("Time to Relax!" , {CONTENT_ENCODING : "snappy" })
12121213
12131214
12141215async def test_writer_with_content_transfer_encoding_base64 (
1215- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1216+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
12161217) -> None :
12171218 writer .append ("Time to Relax!" , {CONTENT_TRANSFER_ENCODING : "base64" })
12181219 await writer .write (stream )
@@ -1227,7 +1228,7 @@ async def test_writer_with_content_transfer_encoding_base64(
12271228
12281229
12291230async def test_writer_content_transfer_encoding_quote_printable (
1230- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1231+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
12311232) -> None :
12321233 writer .append ("Привет, мир!" , {CONTENT_TRANSFER_ENCODING : "quoted-printable" })
12331234 await writer .write (stream )
@@ -1245,7 +1246,7 @@ async def test_writer_content_transfer_encoding_quote_printable(
12451246
12461247
12471248def test_writer_content_transfer_encoding_unknown (
1248- buf : bytearray , stream : Stream , writer : aiohttp .MultipartWriter
1249+ buf : bytearray , stream : AbstractStreamWriter , writer : aiohttp .MultipartWriter
12491250) -> None :
12501251 with pytest .raises (RuntimeError ):
12511252 writer .append ("Time to Relax!" , {CONTENT_TRANSFER_ENCODING : "unknown" })
@@ -1375,7 +1376,7 @@ def test_append_none_not_allowed(self) -> None:
13751376 writer .append (None )
13761377
13771378 async def test_write_preserves_content_disposition (
1378- self , buf : bytearray , stream : Stream
1379+ self , buf : bytearray , stream : AbstractStreamWriter
13791380 ) -> None :
13801381 with aiohttp .MultipartWriter (boundary = ":" ) as writer :
13811382 part = writer .append (b"foo" , headers = {CONTENT_TYPE : "test/passed" })
@@ -1394,7 +1395,7 @@ async def test_write_preserves_content_disposition(
13941395 assert message == b"foo\r \n --:--\r \n "
13951396
13961397 async def test_preserve_content_disposition_header (
1397- self , buf : bytearray , stream : Stream
1398+ self , buf : bytearray , stream : AbstractStreamWriter
13981399 ) -> None :
13991400 # https://github.com/aio-libs/aiohttp/pull/3475#issuecomment-451072381
14001401 with pathlib .Path (__file__ ).open ("rb" ) as fobj :
@@ -1420,7 +1421,7 @@ async def test_preserve_content_disposition_header(
14201421 )
14211422
14221423 async def test_set_content_disposition_override (
1423- self , buf : bytearray , stream : Stream
1424+ self , buf : bytearray , stream : AbstractStreamWriter
14241425 ) -> None :
14251426 # https://github.com/aio-libs/aiohttp/pull/3475#issuecomment-451072381
14261427 with pathlib .Path (__file__ ).open ("rb" ) as fobj :
@@ -1446,7 +1447,7 @@ async def test_set_content_disposition_override(
14461447 )
14471448
14481449 async def test_reset_content_disposition_header (
1449- self , buf : bytearray , stream : Stream
1450+ self , buf : bytearray , stream : AbstractStreamWriter
14501451 ) -> None :
14511452 # https://github.com/aio-libs/aiohttp/pull/3475#issuecomment-451072381
14521453 with pathlib .Path (__file__ ).open ("rb" ) as fobj :
0 commit comments