test_content.py
This file
Path
tests/test_content.py
486 lines · 16.1 KiB · Python
Last changed by
replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 2146c75 point at it.
Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 1–7why, one step back1import io2import typing34import pytest56import httpx7Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 8–9why, one step back8method = "POST"9url = "https://www.example.com"Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 10why, one step back10Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 11why, one step back11replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 12why, one step back12@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 13why, one step back13async def test_empty_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 14–16why, one step back14 request = httpx.Request(method, url)15 assert isinstance(request.stream, httpx.SyncByteStream)16 assert isinstance(request.stream, httpx.AsyncByteStream)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 17why, one step back17Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 18–19why, one step back18 sync_content = b"".join([part for part in request.stream])19 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 20why, one step back20Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 21why, one step back21 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 22–25why, one step back22 assert sync_content == b""23 assert async_content == b""2425replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 26why, one step back26@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 27why, one step back27async def test_bytes_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 28–30why, one step back28 request = httpx.Request(method, url, content=b"Hello, world!")29 assert isinstance(request.stream, typing.Iterable)30 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 31why, one step back31Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 32–33why, one step back32 sync_content = b"".join([part for part in request.stream])33 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 34why, one step back34Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 35why, one step back35 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 36–40why, one step back36 assert sync_content == b"Hello, world!"37 assert async_content == b"Hello, world!"3839 # Support 'data' for compat with requests.40 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 41–43why, one step back41 request = httpx.Request(method, url, data=b"Hello, world!") # type: ignore42 assert isinstance(request.stream, typing.Iterable)43 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 44why, one step back44Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 45–46why, one step back45 sync_content = b"".join([part for part in request.stream])46 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 47why, one step back47Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 48why, one step back48 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 49–52why, one step back49 assert sync_content == b"Hello, world!"50 assert async_content == b"Hello, world!"5152replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 53why, one step back53@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 54why, one step back54async def test_bytesio_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 55–57why, one step back55 request = httpx.Request(method, url, content=io.BytesIO(b"Hello, world!"))56 assert isinstance(request.stream, typing.Iterable)57 assert not isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 58why, one step back58Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 59why, one step back59 content = b"".join([part for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 60why, one step back60Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 61why, one step back61 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 62–64why, one step back62 assert content == b"Hello, world!"6364replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 65why, one step back65@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 66–67why, one step back66async def test_async_bytesio_content():67 class AsyncBytesIO:Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 68why, one step back68 def __init__(self, content: bytes) -> None:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 69–71why, one step back69 self._idx = 070 self._content = content71Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5
line 72why, one step back72 async def aread(self, chunk_size: int) -> bytes:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 73–77why, one step back73 chunk = self._content[self._idx : self._idx + chunk_size]74 self._idx = self._idx + chunk_size75 return chunk7677 async def __aiter__(self):use # pragma: no cover instead of # pragma: nocover (#2471)Adrian Garcia Badaraccobefore adoption16e2830
line 78why, one step back78 yield self._content # pragma: no coverAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 79why, one step back79Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 80–82why, one step back80 request = httpx.Request(method, url, content=AsyncBytesIO(b"Hello, world!"))81 assert not isinstance(request.stream, typing.Iterable)82 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 83why, one step back83Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 84why, one step back84 content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 85why, one step back85Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 86–89why, one step back86 assert request.headers == {87 "Host": "www.example.com",88 "Transfer-Encoding": "chunked",89 }Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 90–92why, one step back90 assert content == b"Hello, world!"9192replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 93why, one step back93@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 94why, one step back94async def test_iterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 95why, one step back95 def hello_world() -> typing.Iterator[bytes]:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 96–98why, one step back96 yield b"Hello, "97 yield b"world!"98Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 99–101why, one step back99 request = httpx.Request(method, url, content=hello_world())100 assert isinstance(request.stream, typing.Iterable)101 assert not isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 102why, one step back102Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 103why, one step back103 content = b"".join([part for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 104why, one step back104Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 105–108why, one step back105 assert request.headers == {106 "Host": "www.example.com",107 "Transfer-Encoding": "chunked",108 }Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 109–111why, one step back109 assert content == b"Hello, world!"110111 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 112why, one step back112 [part for part in request.stream]Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 113–115why, one step back113114 # Support 'data' for compat with requests.115 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 116–118why, one step back116 request = httpx.Request(method, url, data=hello_world()) # type: ignore117 assert isinstance(request.stream, typing.Iterable)118 assert not isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 119why, one step back119Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 120why, one step back120 content = b"".join([part for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 121why, one step back121Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 122–125why, one step back122 assert request.headers == {123 "Host": "www.example.com",124 "Transfer-Encoding": "chunked",125 }Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 126–128why, one step back126 assert content == b"Hello, world!"127128replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 129why, one step back129@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 130why, one step back130async def test_aiterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 131why, one step back131 async def hello_world() -> typing.AsyncIterator[bytes]:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 132–134why, one step back132 yield b"Hello, "133 yield b"world!"134Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 135–137why, one step back135 request = httpx.Request(method, url, content=hello_world())136 assert not isinstance(request.stream, typing.Iterable)137 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 138why, one step back138Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 139why, one step back139 content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 140why, one step back140Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 141–144why, one step back141 assert request.headers == {142 "Host": "www.example.com",143 "Transfer-Encoding": "chunked",144 }Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 145–147why, one step back145 assert content == b"Hello, world!"146147 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 148why, one step back148 [part async for part in request.stream]Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 149–151why, one step back149150 # Support 'data' for compat with requests.151 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 152–154why, one step back152 request = httpx.Request(method, url, data=hello_world()) # type: ignore153 assert not isinstance(request.stream, typing.Iterable)154 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 155why, one step back155Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 156why, one step back156 content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 157why, one step back157Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 158–161why, one step back158 assert request.headers == {159 "Host": "www.example.com",160 "Transfer-Encoding": "chunked",161 }Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 162–164why, one step back162 assert content == b"Hello, world!"163164replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 165why, one step back165@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 166why, one step back166async def test_json_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 167–169why, one step back167 request = httpx.Request(method, url, json={"Hello": "world!"})168 assert isinstance(request.stream, typing.Iterable)169 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 170why, one step back170Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 171–172why, one step back171 sync_content = b"".join([part for part in request.stream])172 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 173why, one step back173Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 174–175why, one step back174 assert request.headers == {175 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 176–182why, one step back176 "Content-Length": "19",177 "Content-Type": "application/json",178 }179 assert sync_content == b'{"Hello": "world!"}'180 assert async_content == b'{"Hello": "world!"}'181182replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 183why, one step back183@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 184why, one step back184async def test_urlencoded_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 185–187why, one step back185 request = httpx.Request(method, url, data={"Hello": "world!"})186 assert isinstance(request.stream, typing.Iterable)187 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 188why, one step back188Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 189–190why, one step back189 sync_content = b"".join([part for part in request.stream])190 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 191why, one step back191Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 192–193why, one step back192 assert request.headers == {193 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 194–200why, one step back194 "Content-Length": "14",195 "Content-Type": "application/x-www-form-urlencoded",196 }197 assert sync_content == b"Hello=world%21"198 assert async_content == b"Hello=world%21"199200replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 201why, one step back201@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 202why, one step back202async def test_urlencoded_boolean():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 203–205why, one step back203 request = httpx.Request(method, url, data={"example": True})204 assert isinstance(request.stream, typing.Iterable)205 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 206why, one step back206Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 207–208why, one step back207 sync_content = b"".join([part for part in request.stream])208 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 209why, one step back209Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 210–211why, one step back210 assert request.headers == {211 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 212–218why, one step back212 "Content-Length": "12",213 "Content-Type": "application/x-www-form-urlencoded",214 }215 assert sync_content == b"example=true"216 assert async_content == b"example=true"217218replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 219why, one step back219@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 220why, one step back220async def test_urlencoded_none():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 221–223why, one step back221 request = httpx.Request(method, url, data={"example": None})222 assert isinstance(request.stream, typing.Iterable)223 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 224why, one step back224Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 225–226why, one step back225 sync_content = b"".join([part for part in request.stream])226 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 227why, one step back227Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 228–229why, one step back228 assert request.headers == {229 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 230–236why, one step back230 "Content-Length": "8",231 "Content-Type": "application/x-www-form-urlencoded",232 }233 assert sync_content == b"example="234 assert async_content == b"example="235236replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 237why, one step back237@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 238why, one step back238async def test_urlencoded_list():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 239–241why, one step back239 request = httpx.Request(method, url, data={"example": ["a", 1, True]})240 assert isinstance(request.stream, typing.Iterable)241 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 242why, one step back242Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 243–244why, one step back243 sync_content = b"".join([part for part in request.stream])244 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 245why, one step back245Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 246–247why, one step back246 assert request.headers == {247 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 248–254why, one step back248 "Content-Length": "32",249 "Content-Type": "application/x-www-form-urlencoded",250 }251 assert sync_content == b"example=a&example=1&example=true"252 assert async_content == b"example=a&example=1&example=true"253254replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 255why, one step back255@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 256–257why, one step back256async def test_multipart_files_content():257 files = {"file": io.BytesIO(b"<file content>")}Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 258–266why, one step back258 headers = {"Content-Type": "multipart/form-data; boundary=+++"}259 request = httpx.Request(260 method,261 url,262 files=files,263 headers=headers,264 )265 assert isinstance(request.stream, typing.Iterable)266 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 267why, one step back267Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 268–269why, one step back268 sync_content = b"".join([part for part in request.stream])269 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 270why, one step back270Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 271–272why, one step back271 assert request.headers == {272 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 273–297why, one step back273 "Content-Length": "138",274 "Content-Type": "multipart/form-data; boundary=+++",275 }276 assert sync_content == b"".join(277 [278 b"--+++\r\n",279 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',280 b"Content-Type: application/octet-stream\r\n",281 b"\r\n",282 b"<file content>\r\n",283 b"--+++--\r\n",284 ]285 )286 assert async_content == b"".join(287 [288 b"--+++\r\n",289 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',290 b"Content-Type: application/octet-stream\r\n",291 b"\r\n",292 b"<file content>\r\n",293 b"--+++--\r\n",294 ]295 )296297replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 298why, one step back298@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 299–301why, one step back299async def test_multipart_data_and_files_content():300 data = {"message": "Hello, world!"}301 files = {"file": io.BytesIO(b"<file content>")}Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 302–305why, one step back302 headers = {"Content-Type": "multipart/form-data; boundary=+++"}303 request = httpx.Request(method, url, data=data, files=files, headers=headers)304 assert isinstance(request.stream, typing.Iterable)305 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 306why, one step back306Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 307–308why, one step back307 sync_content = b"".join([part for part in request.stream])308 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 309why, one step back309Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 310–311why, one step back310 assert request.headers == {311 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 312–344why, one step back312 "Content-Length": "210",313 "Content-Type": "multipart/form-data; boundary=+++",314 }315 assert sync_content == b"".join(316 [317 b"--+++\r\n",318 b'Content-Disposition: form-data; name="message"\r\n',319 b"\r\n",320 b"Hello, world!\r\n",321 b"--+++\r\n",322 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',323 b"Content-Type: application/octet-stream\r\n",324 b"\r\n",325 b"<file content>\r\n",326 b"--+++--\r\n",327 ]328 )329 assert async_content == b"".join(330 [331 b"--+++\r\n",332 b'Content-Disposition: form-data; name="message"\r\n',333 b"\r\n",334 b"Hello, world!\r\n",335 b"--+++\r\n",336 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',337 b"Content-Type: application/octet-stream\r\n",338 b"\r\n",339 b"<file content>\r\n",340 b"--+++--\r\n",341 ]342 )343344replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 345why, one step back345@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 346why, one step back346async def test_empty_request():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 347–349why, one step back347 request = httpx.Request(method, url, data={}, files={})348 assert isinstance(request.stream, typing.Iterable)349 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 350why, one step back350Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 351–352why, one step back351 sync_content = b"".join([part for part in request.stream])352 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 353why, one step back353Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 354why, one step back354 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 355–360why, one step back355 assert sync_content == b""356 assert async_content == b""357358359def test_invalid_argument():360 with pytest.raises(TypeError):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 361why, one step back361 httpx.Request(method, url, content=123) # type: ignoreAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 362why, one step back362Raise TypeError if content is passed a 'dict' instance. (#2495)Tom Christiebefore adoptiona8dd079
lines 363–365why, one step back363 with pytest.raises(TypeError):364 httpx.Request(method, url, content={"a": "b"}) # type: ignore365Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 366why, one step back366replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 367why, one step back367@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 368–372why, one step back368async def test_multipart_multiple_files_single_input_content():369 files = [370 ("file", io.BytesIO(b"<file content 1>")),371 ("file", io.BytesIO(b"<file content 2>")),372 ]Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 373–376why, one step back373 headers = {"Content-Type": "multipart/form-data; boundary=+++"}374 request = httpx.Request(method, url, files=files, headers=headers)375 assert isinstance(request.stream, typing.Iterable)376 assert isinstance(request.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 377why, one step back377Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 378–379why, one step back378 sync_content = b"".join([part for part in request.stream])379 async_content = b"".join([part async for part in request.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 380why, one step back380Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 381–382why, one step back381 assert request.headers == {382 "Host": "www.example.com",Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 383–417why, one step back383 "Content-Length": "271",384 "Content-Type": "multipart/form-data; boundary=+++",385 }386 assert sync_content == b"".join(387 [388 b"--+++\r\n",389 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',390 b"Content-Type: application/octet-stream\r\n",391 b"\r\n",392 b"<file content 1>\r\n",393 b"--+++\r\n",394 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',395 b"Content-Type: application/octet-stream\r\n",396 b"\r\n",397 b"<file content 2>\r\n",398 b"--+++--\r\n",399 ]400 )401 assert async_content == b"".join(402 [403 b"--+++\r\n",404 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',405 b"Content-Type: application/octet-stream\r\n",406 b"\r\n",407 b"<file content 1>\r\n",408 b"--+++\r\n",409 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',410 b"Content-Type: application/octet-stream\r\n",411 b"\r\n",412 b"<file content 2>\r\n",413 b"--+++--\r\n",414 ]415 )416417replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 418why, one step back418@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 419why, one step back419async def test_response_empty_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 420–422why, one step back420 response = httpx.Response(200)421 assert isinstance(response.stream, typing.Iterable)422 assert isinstance(response.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 423why, one step back423Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 424–425why, one step back424 sync_content = b"".join([part for part in response.stream])425 async_content = b"".join([part async for part in response.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 426why, one step back426Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 427why, one step back427 assert response.headers == {}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 428–431why, one step back428 assert sync_content == b""429 assert async_content == b""430431replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 432why, one step back432@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 433why, one step back433async def test_response_bytes_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 434–436why, one step back434 response = httpx.Response(200, content=b"Hello, world!")435 assert isinstance(response.stream, typing.Iterable)436 assert isinstance(response.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 437why, one step back437Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 438–439why, one step back438 sync_content = b"".join([part for part in response.stream])439 async_content = b"".join([part async for part in response.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 440why, one step back440Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 441why, one step back441 assert response.headers == {"Content-Length": "13"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 442–445why, one step back442 assert sync_content == b"Hello, world!"443 assert async_content == b"Hello, world!"444445replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 446why, one step back446@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 447why, one step back447async def test_response_iterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 448why, one step back448 def hello_world() -> typing.Iterator[bytes]:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 449–451why, one step back449 yield b"Hello, "450 yield b"world!"451Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 452–454why, one step back452 response = httpx.Response(200, content=hello_world())453 assert isinstance(response.stream, typing.Iterable)454 assert not isinstance(response.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 455why, one step back455Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 456why, one step back456 content = b"".join([part for part in response.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 457why, one step back457Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 458why, one step back458 assert response.headers == {"Transfer-Encoding": "chunked"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 459–461why, one step back459 assert content == b"Hello, world!"460461 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 462why, one step back462 [part for part in response.stream]Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 463–464why, one step back463464replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8
line 465why, one step back465@pytest.mark.anyioAllow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 466why, one step back466async def test_response_aiterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 467why, one step back467 async def hello_world() -> typing.AsyncIterator[bytes]:Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 468–470why, one step back468 yield b"Hello, "469 yield b"world!"470Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 471–473why, one step back471 response = httpx.Response(200, content=hello_world())472 assert not isinstance(response.stream, typing.Iterable)473 assert isinstance(response.stream, typing.AsyncIterable)Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 474why, one step back474Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 475why, one step back475 content = b"".join([part async for part in response.stream])Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
line 476why, one step back476Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 477why, one step back477 assert response.headers == {"Transfer-Encoding": "chunked"}Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 478–480why, one step back478 assert content == b"Hello, world!"479480 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 481why, one step back481 [part async for part in response.stream]Allow rich-11 (#2057)Michał Górnybefore adoption2146c75
lines 482–485why, one step back482483484def test_response_invalid_argument():485 with pytest.raises(TypeError):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 486why, one step back486 httpx.Response(200, content=123) # type: ignore