(data, encoding)
| 242 | ) |
| 243 | @pytest.mark.anyio |
| 244 | async def test_text_decoder_with_autodetect(data, encoding): |
| 245 | async def iterator() -> typing.AsyncIterator[bytes]: |
| 246 | nonlocal data |
| 247 | for chunk in data: |
| 248 | yield chunk |
| 249 | |
| 250 | def autodetect(content): |
| 251 | return chardet.detect(content).get("encoding") |
| 252 | |
| 253 | # Accessing `.text` on a read response. |
| 254 | response = httpx.Response(200, content=iterator(), default_encoding=autodetect) |
| 255 | await response.aread() |
| 256 | assert response.text == (b"".join(data)).decode(encoding) |
| 257 | |
| 258 | # Streaming `.aiter_text` iteratively. |
| 259 | # Note that if we streamed the text *without* having read it first, then |
| 260 | # we won't get a `charset_normalizer` guess, and will instead always rely |
| 261 | # on utf-8 if no charset is specified. |
| 262 | text = "".join([part async for part in response.aiter_text()]) |
| 263 | assert text == (b"".join(data)).decode(encoding) |
| 264 | |
| 265 | |
| 266 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected