]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Bump coverage (#705)
authorTom Christie <tom@tomchristie.com>
Wed, 1 Jan 2020 15:33:24 +0000 (15:33 +0000)
committerGitHub <noreply@github.com>
Wed, 1 Jan 2020 15:33:24 +0000 (15:33 +0000)
* Bump coverage

* Tests for iterative text decoding with 'aiter_text'

* nocover on xfail exception cases

* nocover API that is pending deprecation

* Tweak test to removed uncovered line

* Ingest request body in RedirectBodyUnavailable test case

httpx/client.py
httpx/config.py
httpx/dispatch/proxy_http.py
httpx/models.py
tests/client/test_redirects.py
tests/dispatch/test_http2.py
tests/dispatch/utils.py
tests/models/test_responses.py
tests/test_decoders.py

index 9b594008f6a20906eb44ba6bfc354ba55fe82d30..b2c2e5eed08d681e598c4deec9589d17e12d3e3f 100644 (file)
@@ -223,28 +223,28 @@ class AsyncClient:
         timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,
         trust_env: bool = None,
     ) -> Response:
-        if cert is not None:
+        if cert is not None:  # pragma: nocover
             raise RuntimeError(
                 "Passing a 'cert' argument when making a request on a client "
                 "is not supported anymore. Instantiate a new client instead, "
                 "passing any 'cert' arguments to the client itself."
             )
 
-        if verify is not None:
+        if verify is not None:  # pragma: nocover
             raise RuntimeError(
                 "Passing a 'verify' argument when making a request on a client "
                 "is not supported anymore. Instantiate a new client instead, "
                 "passing any 'verify' arguments to the client itself."
             )
 
-        if trust_env is not None:
+        if trust_env is not None:  # pragma: nocover
             raise RuntimeError(
                 "Passing a 'trust_env' argument when making a request on a client "
                 "is not supported anymore. Instantiate a new client instead, "
                 "passing any 'trust_env' argument to the client itself."
             )
 
-        if stream:
+        if stream:  # pragma: nocover
             warnings.warn(
                 "The 'stream=True' argument is due to be deprecated. "
                 "Use 'async with client.stream(method, url, ...) as response' instead."
index 0e837a232f534673f5f7bf5017be5b51b4e4e9d7..088642606799fc52aef33296f3db2ce02cf2e4e7 100644 (file)
@@ -179,7 +179,7 @@ class SSLConfig:
             alpn_idents = ["http/1.1", "h2"] if http2 else ["http/1.1"]
             context.set_alpn_protocols(alpn_idents)
 
-        if hasattr(context, "keylog_filename"):
+        if hasattr(context, "keylog_filename"):  # pragma: nocover (Available in 3.8+)
             keylogfile = os.environ.get("SSLKEYLOGFILE")
             if keylogfile and self.trust_env:
                 context.keylog_filename = keylogfile  # type: ignore
index 01aaa7db466e8f9e147b86cc0f4538745e64b73b..748cffa5c1f2404ada13282599e5f8f635634b6e 100644 (file)
@@ -46,7 +46,7 @@ class HTTPProxy(ConnectionPool):
         backend: typing.Union[str, ConcurrencyBackend] = "auto",
     ):
 
-        if isinstance(proxy_mode, HTTPProxyMode):
+        if isinstance(proxy_mode, HTTPProxyMode):  # pragma: nocover
             warnings.warn(
                 "The 'HTTPProxyMode' enum is pending deprecation. "
                 "Use a plain string instead. proxy_mode='FORWARD_ONLY', or "
index 401bf49a803a5d114aeed72612be931640ae2bf3..91cf5a5e28d5f0992a2b2954925696ec07810ec2 100644 (file)
@@ -860,19 +860,19 @@ class Response:
 
     @property
     def stream(self):  # type: ignore
-        warnings.warn(
+        warnings.warn(  # pragma: nocover
             "Response.stream() is due to be deprecated. "
             "Use Response.aiter_bytes() instead."
         )
-        return self.aiter_bytes
+        return self.aiter_bytes  # pragma: nocover
 
     @property
     def raw(self):  # type: ignore
-        warnings.warn(
+        warnings.warn(  # pragma: nocover
             "Response.raw() is due to be deprecated. "
             "Use Response.aiter_raw() instead."
         )
-        return self.aiter_raw
+        return self.aiter_raw  # pragma: nocover
 
     async def aiter_bytes(self) -> typing.AsyncIterator[bytes]:
         """
index fdce8ca9239b1dedfb7aa10d94f0e73177e79271..663d2def94bde64a2700783d70ec3e3f05086366 100644 (file)
@@ -77,6 +77,7 @@ class MockDispatch(Dispatcher):
             return Response(codes.OK, content=content, request=request)
 
         elif request.url.path == "/redirect_body":
+            body = b"".join([part async for part in request.stream])
             headers = {"location": "/redirect_body_target"}
             return Response(codes.PERMANENT_REDIRECT, headers=headers, request=request)
 
index 09e5953c9d881bf57690673db08fca95a0ef5c93..07b0229bfa6999de0f1876c1e7375292dff84d82 100644 (file)
@@ -143,9 +143,9 @@ async def test_http2_live_request():
     async with AsyncClient(http2=True) as client:
         try:
             resp = await client.get("https://nghttp2.org/httpbin/anything")
-        except TimeoutException:
+        except TimeoutException:  # pragma: nocover
             pytest.xfail(reason="nghttp2.org appears to be unresponsive")
-        except socket.gaierror:
+        except socket.gaierror:  # pragma: nocover
             pytest.xfail(reason="You appear to be offline")
         assert resp.status_code == 200
         assert resp.http_version == "HTTP/2"
index 74fa311b36b8f1f91c7e63b86d21c02da0aadd7c..fa4d9ab5d2f7fe587645a19f6fbb2da90cc6f79e 100644 (file)
@@ -141,9 +141,7 @@ class MockHTTP2Server(BaseSocketStream):
                 flow_control,
                 self.conn.max_outbound_frame_size,
             )
-            if chunk_size == 0:
-                return
-            else:
+            if chunk_size > 0:
                 chunk, self.return_data[stream_id] = (
                     self.return_data[stream_id][:chunk_size],
                     self.return_data[stream_id][chunk_size:],
index f39d4ff5fd5e62df7d5d8402fa2108f00aee135d..d7d519cc7f6985ed24543154547f2816870a10b8 100644 (file)
@@ -235,6 +235,15 @@ async def test_cannot_read_after_response_closed():
         await response.aread()
 
 
+@pytest.mark.asyncio
+async def test_elapsed_not_available_until_closed():
+    stream = AsyncIteratorStream(aiterator=async_streaming_body())
+    response = httpx.Response(200, stream=stream, request=REQUEST)
+
+    with pytest.raises(RuntimeError):
+        response.elapsed
+
+
 def test_unknown_status_code():
     response = httpx.Response(600, request=REQUEST)
     assert response.status_code == 600
index 5eb26d305ef70a31b47a534100142e08f49be6d0..f0b8b01db166742cfe08b4981690bed9b9324dd7 100644 (file)
@@ -155,11 +155,18 @@ async def test_text_decoder(data, encoding):
         for chunk in data:
             yield chunk
 
+    # Accessing `.text` on a read response.
     stream = AsyncIteratorStream(aiterator=iterator())
     response = httpx.Response(200, stream=stream, request=REQUEST)
     await response.aread()
     assert response.text == (b"".join(data)).decode(encoding)
 
+    # Streaming `.aiter_text` iteratively.
+    stream = AsyncIteratorStream(aiterator=iterator())
+    response = httpx.Response(200, stream=stream, request=REQUEST)
+    text = "".join([part async for part in response.aiter_text()])
+    assert text == (b"".join(data)).decode(encoding)
+
 
 @pytest.mark.asyncio
 async def test_text_decoder_known_encoding():