Skip to content
Myr

map_exceptions in request.aclose() (#1465)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* map_exceptions in request.aclose()

authored by Adam Hooper · committed by GitHub · parent bd4caa8 · Browse files · 2 files+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−1 removed

  • tests:+19 added−0 removed
  • other:+2 added−1 removed

2 files+21 added−1 removed

modified:httpx/_client.py+2 added-1 removed
1498 unmodified lines
14991500 async def on_close(response: Response) -> None:1501 response.elapsed = datetime.timedelta(seconds=await timer.async_elapsed())1502 if hasattr(stream, "aclose"):1503 with map_exceptions(HTTPCORE_EXC_MAP, request=request):1503 await stream.aclose()1504 await stream.aclose()15051506 response = Response(1507 status_code,1508 headers=headers,
329 unmodified lines
modified:tests/client/test_async_client.py+19 added
302 unmodified lines
303 assert response.json() == {"app": "mounted"}304305306@pytest.mark.usefixtures("async_environment")307async def test_response_aclose_map_exceptions():308 class BrokenStream:309 async def __aiter__(self):310 # so we're an AsyncIterator311 pass # pragma: nocover312313 async def aclose(self):314 raise httpcore.CloseError(OSError(104, "Connection reset by peer"))315316 def handle(request: httpx.Request) -> httpx.Response:317 return httpx.Response(200, stream=BrokenStream())318319 async with httpx.AsyncClient(transport=httpx.MockTransport(handle)) as client:320 async with client.stream("GET", "http://example.com") as response:321 with pytest.raises(httpx.CloseError):322 await response.aclose()323324325@pytest.mark.usefixtures("async_environment")326async def test_async_mock_transport():327 async def hello_world(request):328 return httpx.Response(200, text="Hello, world!")329
6 unmodified lines