Skip to content
Myr

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

3 files+25 added−23 removed

modified:httpcore/connections.py+4 added-3 removed
38 unmodified lines
39 )40 except asyncio.TimeoutError:41 raise ConnectTimeout()4243 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 lines
76 status_code = event.status_code77 headers = event.headers7879 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)8283 #  Get the response body.84 body = b""85 event = await self._receive_event()
4 unmodified lines
90 await self.close()9192 return Response(status_code=status_code, headers=headers, body=body)9393 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 lines
modified:tests/conftest.py+9 added-13 removed
1import asyncio2import json23import pytest4from uvicorn.config import Config5from uvicorn.main import Server678async 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!"})181920@pytest.fixture21async def server():
9 unmodified lines
modified:tests/test_api.py+12 added-7 removed
1import pytest23import httpcore456@pytest.mark.asyncio7async 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!"121314@pytest.mark.asyncio15async 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 == 200212223@pytest.mark.asyncio24async 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!"313233@pytest.mark.asyncio34async def test_stream_request(server):
1 unmodified line
36 yield b"Hello, "37 yield b"world!"3839 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