Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than ecbece1 point at it.

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 1–7why, one step back
1import io
2import typing34import pytest56import httpx7

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 8–9why, one step back
8method = "POST"
9url = "https://www.example.com"

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 10why, one step back
10

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 11why, one step back
11

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 12why, one step back
12@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 13why, one step back
13async def test_empty_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 14–16why, one step back
14 request = httpx.Request(method, url)
15 assert isinstance(request.stream, httpx.SyncByteStream)16 assert isinstance(request.stream, httpx.AsyncByteStream)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 17why, one step back
17

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 18–19why, one step back
18 sync_content = b"".join([part for part in request.stream])
19 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 20why, one step back
20

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 21why, one step back
21 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 22–25why, one step back
22 assert sync_content == b""
23 assert async_content == b""2425

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 26why, one step back
26@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 27why, one step back
27async def test_bytes_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 28–30why, one step back
28 request = httpx.Request(method, url, content=b"Hello, world!")
29 assert isinstance(request.stream, typing.Iterable)30 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 31why, one step back
31

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 32–33why, one step back
32 sync_content = b"".join([part for part in request.stream])
33 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 34why, one step back
34

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 35why, one step back
35 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 36–40why, one step back
36 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 back
41 request = httpx.Request(method, url, data=b"Hello, world!") # type: ignore
42 assert isinstance(request.stream, typing.Iterable)43 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 44why, one step back
44

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 45–46why, one step back
45 sync_content = b"".join([part for part in request.stream])
46 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 47why, one step back
47

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 48why, one step back
48 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 49–52why, one step back
49 assert sync_content == b"Hello, world!"
50 assert async_content == b"Hello, world!"5152

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 53why, one step back
53@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 54why, one step back
54async def test_bytesio_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 55–57why, one step back
55 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)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 58why, one step back
58

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 59why, one step back
59 content = b"".join([part for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 60why, one step back
60

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 61why, one step back
61 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 62–64why, one step back
62 assert content == b"Hello, world!"
6364

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 65why, one step back
65@pytest.mark.anyio

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

lines 66–67why, one step back
66async def test_async_bytesio_content():
67 class AsyncBytesIO:

Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c

line 68why, one step back
68 def __init__(self, content: bytes) -> None:

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

lines 69–71why, one step back
69 self._idx = 0
70 self._content = content71

Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5

line 72why, one step back
72 async def aread(self, chunk_size: int) -> bytes:

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

lines 73–77why, one step back
73 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 back
78 yield self._content # pragma: no cover

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

line 79why, one step back
79

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 80–82why, one step back
80 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)

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

line 83why, one step back
83

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 84why, one step back
84 content = b"".join([part async for part in request.stream])

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

line 85why, one step back
85

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 86–89why, one step back
86 assert request.headers == {
87 "Host": "www.example.com",88 "Transfer-Encoding": "chunked",89 }

Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f

lines 90–92why, one step back
90 assert content == b"Hello, world!"
9192

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 93why, one step back
93@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 94why, one step back
94async def test_iterator_content():

Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c

line 95why, one step back
95 def hello_world() -> typing.Iterator[bytes]:

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 96–98why, one step back
96 yield b"Hello, "
97 yield b"world!"98

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 99–101why, one step back
99 request = httpx.Request(method, url, content=hello_world())
100 assert isinstance(request.stream, typing.Iterable)101 assert not isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 102why, one step back
102

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 103why, one step back
103 content = b"".join([part for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 104why, one step back
104

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 105–108why, one step back
105 assert request.headers == {
106 "Host": "www.example.com",107 "Transfer-Encoding": "chunked",108 }

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 109–111why, one step back
109 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 back
112 [part for part in request.stream]

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 113–115why, one step back
113
114 # 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 back
116 request = httpx.Request(method, url, data=hello_world()) # type: ignore
117 assert isinstance(request.stream, typing.Iterable)118 assert not isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 119why, one step back
119

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 120why, one step back
120 content = b"".join([part for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 121why, one step back
121

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 122–125why, one step back
122 assert request.headers == {
123 "Host": "www.example.com",124 "Transfer-Encoding": "chunked",125 }

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 126–128why, one step back
126 assert content == b"Hello, world!"
127128

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 129why, one step back
129@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 130why, one step back
130async def test_aiterator_content():

Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c

line 131why, one step back
131 async def hello_world() -> typing.AsyncIterator[bytes]:

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 132–134why, one step back
132 yield b"Hello, "
133 yield b"world!"134

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 135–137why, one step back
135 request = httpx.Request(method, url, content=hello_world())
136 assert not isinstance(request.stream, typing.Iterable)137 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 138why, one step back
138

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 139why, one step back
139 content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 140why, one step back
140

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 141–144why, one step back
141 assert request.headers == {
142 "Host": "www.example.com",143 "Transfer-Encoding": "chunked",144 }

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 145–147why, one step back
145 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 back
148 [part async for part in request.stream]

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 149–151why, one step back
149
150 # 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 back
152 request = httpx.Request(method, url, data=hello_world()) # type: ignore
153 assert not isinstance(request.stream, typing.Iterable)154 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 155why, one step back
155

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 156why, one step back
156 content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 157why, one step back
157

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 158–161why, one step back
158 assert request.headers == {
159 "Host": "www.example.com",160 "Transfer-Encoding": "chunked",161 }

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 162–164why, one step back
162 assert content == b"Hello, world!"
163164

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 165why, one step back
165@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 166why, one step back
166async def test_json_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 167–169why, one step back
167 request = httpx.Request(method, url, json={"Hello": "world!"})
168 assert isinstance(request.stream, typing.Iterable)169 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 170why, one step back
170

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 171–172why, one step back
171 sync_content = b"".join([part for part in request.stream])
172 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 173why, one step back
173

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 174–175why, one step back
174 assert request.headers == {
175 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 176–182why, one step back
176 "Content-Length": "19",
177 "Content-Type": "application/json",178 }179 assert sync_content == b'{"Hello": "world!"}'180 assert async_content == b'{"Hello": "world!"}'181182

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 183why, one step back
183@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 184why, one step back
184async def test_urlencoded_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 185–187why, one step back
185 request = httpx.Request(method, url, data={"Hello": "world!"})
186 assert isinstance(request.stream, typing.Iterable)187 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 188why, one step back
188

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 189–190why, one step back
189 sync_content = b"".join([part for part in request.stream])
190 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 191why, one step back
191

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 192–193why, one step back
192 assert request.headers == {
193 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 194–200why, one step back
194 "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"199200

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 201why, one step back
201@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 202why, one step back
202async def test_urlencoded_boolean():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 203–205why, one step back
203 request = httpx.Request(method, url, data={"example": True})
204 assert isinstance(request.stream, typing.Iterable)205 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 206why, one step back
206

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 207–208why, one step back
207 sync_content = b"".join([part for part in request.stream])
208 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 209why, one step back
209

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 210–211why, one step back
210 assert request.headers == {
211 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 212–218why, one step back
212 "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"217218

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 219why, one step back
219@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 220why, one step back
220async def test_urlencoded_none():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 221–223why, one step back
221 request = httpx.Request(method, url, data={"example": None})
222 assert isinstance(request.stream, typing.Iterable)223 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 224why, one step back
224

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 225–226why, one step back
225 sync_content = b"".join([part for part in request.stream])
226 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 227why, one step back
227

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 228–229why, one step back
228 assert request.headers == {
229 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 230–236why, one step back
230 "Content-Length": "8",
231 "Content-Type": "application/x-www-form-urlencoded",232 }233 assert sync_content == b"example="234 assert async_content == b"example="235236

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 237why, one step back
237@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 238why, one step back
238async def test_urlencoded_list():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 239–241why, one step back
239 request = httpx.Request(method, url, data={"example": ["a", 1, True]})
240 assert isinstance(request.stream, typing.Iterable)241 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 242why, one step back
242

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 243–244why, one step back
243 sync_content = b"".join([part for part in request.stream])
244 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 245why, one step back
245

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 246–247why, one step back
246 assert request.headers == {
247 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 248–254why, one step back
248 "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"253254

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 255why, one step back
255@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 256–257why, one step back
256async 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 back
258 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)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 267why, one step back
267

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 268–269why, one step back
268 sync_content = b"".join([part for part in request.stream])
269 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 270why, one step back
270

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 271–272why, one step back
271 assert request.headers == {
272 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 273–297why, one step back
273 "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 )296297

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 298why, one step back
298@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 299–301why, one step back
299async 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 back
302 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)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 306why, one step back
306

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 307–308why, one step back
307 sync_content = b"".join([part for part in request.stream])
308 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 309why, one step back
309

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 310–311why, one step back
310 assert request.headers == {
311 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 312–344why, one step back
312 "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 )343344

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 345why, one step back
345@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 346why, one step back
346async def test_empty_request():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 347–349why, one step back
347 request = httpx.Request(method, url, data={}, files={})
348 assert isinstance(request.stream, typing.Iterable)349 assert isinstance(request.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 350why, one step back
350

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 351–352why, one step back
351 sync_content = b"".join([part for part in request.stream])
352 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 353why, one step back
353

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 354why, one step back
354 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 355–360why, one step back
355 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 back
361 httpx.Request(method, url, content=123) # type: ignore

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 362why, one step back
362

Raise TypeError if content is passed a 'dict' instance. (#2495)Tom Christiebefore adoptiona8dd079

lines 363–365why, one step back
363 with pytest.raises(TypeError):
364 httpx.Request(method, url, content={"a": "b"}) # type: ignore365

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 366why, one step back
366

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 367why, one step back
367@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 368–372why, one step back
368async 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 back
373 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)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 377why, one step back
377

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 378–379why, one step back
378 sync_content = b"".join([part for part in request.stream])
379 async_content = b"".join([part async for part in request.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 380why, one step back
380

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 381–382why, one step back
381 assert request.headers == {
382 "Host": "www.example.com",

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 383–417why, one step back
383 "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 )416417

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 418why, one step back
418@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 419why, one step back
419async def test_response_empty_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 420–422why, one step back
420 response = httpx.Response(200)
421 assert isinstance(response.stream, typing.Iterable)422 assert isinstance(response.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 423why, one step back
423

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 424–425why, one step back
424 sync_content = b"".join([part for part in response.stream])
425 async_content = b"".join([part async for part in response.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 426why, one step back
426

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 427why, one step back
427 assert response.headers == {}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 428–431why, one step back
428 assert sync_content == b""
429 assert async_content == b""430431

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 432why, one step back
432@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 433why, one step back
433async def test_response_bytes_content():

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 434–436why, one step back
434 response = httpx.Response(200, content=b"Hello, world!")
435 assert isinstance(response.stream, typing.Iterable)436 assert isinstance(response.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 437why, one step back
437

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 438–439why, one step back
438 sync_content = b"".join([part for part in response.stream])
439 async_content = b"".join([part async for part in response.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 440why, one step back
440

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 441why, one step back
441 assert response.headers == {"Content-Length": "13"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 442–445why, one step back
442 assert sync_content == b"Hello, world!"
443 assert async_content == b"Hello, world!"444445

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 446why, one step back
446@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 447why, one step back
447async def test_response_iterator_content():

Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c

line 448why, one step back
448 def hello_world() -> typing.Iterator[bytes]:

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 449–451why, one step back
449 yield b"Hello, "
450 yield b"world!"451

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 452–454why, one step back
452 response = httpx.Response(200, content=hello_world())
453 assert isinstance(response.stream, typing.Iterable)454 assert not isinstance(response.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 455why, one step back
455

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 456why, one step back
456 content = b"".join([part for part in response.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 457why, one step back
457

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 458why, one step back
458 assert response.headers == {"Transfer-Encoding": "chunked"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 459–461why, one step back
459 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 back
462 [part for part in response.stream]

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 463–464why, one step back
463
464

replace pytest-asyncio and pytest-trio with anyio (#2512)Thomas Graingerbefore adoptione27d1b8

line 465why, one step back
465@pytest.mark.anyio

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 466why, one step back
466async def test_response_aiterator_content():

Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c

line 467why, one step back
467 async def hello_world() -> typing.AsyncIterator[bytes]:

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 468–470why, one step back
468 yield b"Hello, "
469 yield b"world!"470

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

lines 471–473why, one step back
471 response = httpx.Response(200, content=hello_world())
472 assert not isinstance(response.stream, typing.Iterable)473 assert isinstance(response.stream, typing.AsyncIterable)

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 474why, one step back
474

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 475why, one step back
475 content = b"".join([part async for part in response.stream])

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

line 476why, one step back
476

Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589

line 477why, one step back
477 assert response.headers == {"Transfer-Encoding": "chunked"}

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 478–480why, one step back
478 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 back
481 [part async for part in response.stream]

:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1

lines 482–485why, one step back
482
483484def 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 back
486 httpx.Response(200, content=123) # type: ignore