Linting
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tom Christie · committed by Tom Christie · parent 86263fa · Browse files · 3 files·+25 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+25 added−23 removed
- tests:+21 added−20 removed
- other:+4 added−3 removed
Provenance
- Commit
ba1953c- Tree
f496096- Author
Tom Christie <tom@tomchristie.com>- Committer
Tom Christie <tom@tomchristie.com>- Parent
86263fa
3 files changed+25 added−23 removed
modified:httpcore/connections.py+4 added-3 removed
38 unmodified lines39 )40 except asyncio.TimeoutError:41 raise ConnectTimeout()42 43- async def send(self, request: Request, stream: bool=False) -> Response:43+ async def send(self, request: Request, stream: bool = False) -> Response:44 method = request.method.encode()45 target = request.url.target46 host_header = (b"host", request.url.netloc.encode("ascii"))47 if request.is_streaming:28 unmodified lines76 status_code = event.status_code77 headers = event.headers78 79 if stream:80+ body_iter = self.body_iter()80- return Response(status_code=status_code, headers=headers, body=self.body_iter())81+ return Response(status_code=status_code, headers=headers, body=body_iter)82 83 # Get the response body.84 body = b""85 event = await self._receive_event()4 unmodified lines90 await self.close()91 92 return Response(status_code=status_code, headers=headers, body=body)93 93- async def body_iter(self) -> typing.Iterable[bytes]:94+ async def body_iter(self) -> typing.AsyncIterator[bytes]:95 event = await self._receive_event()96 while isinstance(event, h11.Data):97 yield event.data98 event = await self._receive_event()31 unmodified linesmodified:tests/conftest.py+9 added-13 removed
1 import asyncio2-import json2 3 import pytest4 from uvicorn.config import Config5 from uvicorn.main import Server6 7 8 async def app(scope, receive, send):10- assert scope['type'] == 'http'11- await send({12- 'type': 'http.response.start',13- 'status': 200,14- 'headers': [15- [b'content-type', b'text/plain'],16- ]17- })18- await send({19- 'type': 'http.response.body',20- 'body': b'Hello, world!',21- })9+ assert scope["type"] == "http"10+ await send(11+ {12+ "type": "http.response.start",13+ "status": 200,14+ "headers": [[b"content-type", b"text/plain"]],15+ }16+ )17+ await send({"type": "http.response.body", "body": b"Hello, world!"})18 19 20 @pytest.fixture21 async def server():9 unmodified linesmodified:tests/test_api.py+12 added-7 removed
1 import pytest2+3 import httpcore4 5 6 @pytest.mark.asyncio7 async def test_get(server):8 async with httpcore.ConnectionPool() as http:8- response = await http.request('GET', "http://127.0.0.1:8000/")9+ response = await http.request("GET", "http://127.0.0.1:8000/")10 assert response.status_code == 20010- assert response.body == b'Hello, world!'11+ assert response.body == b"Hello, world!"12 13 14 @pytest.mark.asyncio15 async def test_post(server):16 async with httpcore.ConnectionPool() as http:16- response = await http.request('POST', "http://127.0.0.1:8000/", body=b"Hello, world!")17+ response = await http.request(18+ "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"19+ )20 assert response.status_code == 20021 22 23 @pytest.mark.asyncio24 async def test_stream_response(server):25 async with httpcore.ConnectionPool() as http:23- response = await http.request('GET', "http://127.0.0.1:8000/", stream=True)26+ response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)27 assert response.status_code == 20025- assert not hasattr(response, 'body')28+ assert not hasattr(response, "body")29 body = await response.read()27- assert body == b'Hello, world!'30+ assert body == b"Hello, world!"31 32 33 @pytest.mark.asyncio34 async def test_stream_request(server):1 unmodified line36 yield b"Hello, "37 yield b"world!"38 39 async with httpcore.ConnectionPool() as http:37- response = await http.request('POST', "http://127.0.0.1:8000/", body=hello_world())40+ response = await http.request(41+ "POST", "http://127.0.0.1:8000/", body=hello_world()42+ )43 assert response.status_code == 200