From: Tom Christie Date: Sat, 6 Apr 2019 12:20:47 +0000 (+0100) Subject: Linting X-Git-Tag: 0.0.3~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba1953cdd01f48a9847ad8481dd8786415a8c58a;p=thirdparty%2Fhttpx.git Linting --- diff --git a/httpcore/connections.py b/httpcore/connections.py index db27b03c..312fc46c 100644 --- a/httpcore/connections.py +++ b/httpcore/connections.py @@ -40,7 +40,7 @@ class Connection: except asyncio.TimeoutError: raise ConnectTimeout() - async def send(self, request: Request, stream: bool=False) -> Response: + async def send(self, request: Request, stream: bool = False) -> Response: method = request.method.encode() target = request.url.target host_header = (b"host", request.url.netloc.encode("ascii")) @@ -77,7 +77,8 @@ class Connection: headers = event.headers if stream: - return Response(status_code=status_code, headers=headers, body=self.body_iter()) + body_iter = self.body_iter() + return Response(status_code=status_code, headers=headers, body=body_iter) #  Get the response body. body = b"" @@ -90,7 +91,7 @@ class Connection: return Response(status_code=status_code, headers=headers, body=body) - async def body_iter(self) -> typing.Iterable[bytes]: + async def body_iter(self) -> typing.AsyncIterator[bytes]: event = await self._receive_event() while isinstance(event, h11.Data): yield event.data diff --git a/tests/conftest.py b/tests/conftest.py index 08e36702..234cf43b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import asyncio -import json import pytest from uvicorn.config import Config @@ -7,18 +6,15 @@ from uvicorn.main import Server async def app(scope, receive, send): - assert scope['type'] == 'http' - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - [b'content-type', b'text/plain'], - ] - }) - await send({ - 'type': 'http.response.body', - 'body': b'Hello, world!', - }) + assert scope["type"] == "http" + await send( + { + "type": "http.response.start", + "status": 200, + "headers": [[b"content-type", b"text/plain"]], + } + ) + await send({"type": "http.response.body", "body": b"Hello, world!"}) @pytest.fixture diff --git a/tests/test_api.py b/tests/test_api.py index c24e7373..6b80587d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,30 +1,33 @@ import pytest + import httpcore @pytest.mark.asyncio async def test_get(server): async with httpcore.ConnectionPool() as http: - response = await http.request('GET', "http://127.0.0.1:8000/") + response = await http.request("GET", "http://127.0.0.1:8000/") assert response.status_code == 200 - assert response.body == b'Hello, world!' + assert response.body == b"Hello, world!" @pytest.mark.asyncio async def test_post(server): async with httpcore.ConnectionPool() as http: - response = await http.request('POST', "http://127.0.0.1:8000/", body=b"Hello, world!") + response = await http.request( + "POST", "http://127.0.0.1:8000/", body=b"Hello, world!" + ) assert response.status_code == 200 @pytest.mark.asyncio async def test_stream_response(server): async with httpcore.ConnectionPool() as http: - response = await http.request('GET', "http://127.0.0.1:8000/", stream=True) + response = await http.request("GET", "http://127.0.0.1:8000/", stream=True) assert response.status_code == 200 - assert not hasattr(response, 'body') + assert not hasattr(response, "body") body = await response.read() - assert body == b'Hello, world!' + assert body == b"Hello, world!" @pytest.mark.asyncio @@ -34,5 +37,7 @@ async def test_stream_request(server): yield b"world!" async with httpcore.ConnectionPool() as http: - response = await http.request('POST', "http://127.0.0.1:8000/", body=hello_world()) + response = await http.request( + "POST", "http://127.0.0.1:8000/", body=hello_world() + ) assert response.status_code == 200