Skip to content
Myr

Bump coverage (#705)

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

* 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

authored by Tom Christie · committed by GitHub · parent f5d4bb8 · Browse files · 9 files+30 added−15 removed
This commit

State

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

Diff stats

9 files+30 added−15 removed

  • tests:+20 added−5 removed
  • other:+10 added−10 removed

9 files+30 added−15 removed

modified:httpx/dispatch/proxy_http.py+1 added-1 removed
44 unmodified lines
45 http2: bool = False,46 backend: typing.Union[str, ConcurrencyBackend] = "auto",47 ):4849 if isinstance(proxy_mode, HTTPProxyMode):49 if isinstance(proxy_mode, HTTPProxyMode): # pragma: nocover50 warnings.warn(51 "The 'HTTPProxyMode' enum is pending deprecation. "52 "Use a plain string instead. proxy_mode='FORWARD_ONLY', or "53 "proxy_mode='TUNNEL_ONLY'."
147 unmodified lines
modified:httpx/client.py+4 added-4 removed
221 unmodified lines
222 verify: VerifyTypes = None,223 timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,224 trust_env: bool = None,225 ) -> Response:226 if cert is not None:226 if cert is not None: # pragma: nocover227 raise RuntimeError(228 "Passing a 'cert' argument when making a request on a client "229 "is not supported anymore. Instantiate a new client instead, "230 "passing any 'cert' arguments to the client itself."231 )232233 if verify is not None:233 if verify is not None: # pragma: nocover234 raise RuntimeError(235 "Passing a 'verify' argument when making a request on a client "236 "is not supported anymore. Instantiate a new client instead, "237 "passing any 'verify' arguments to the client itself."238 )239240 if trust_env is not None:240 if trust_env is not None: # pragma: nocover241 raise RuntimeError(242 "Passing a 'trust_env' argument when making a request on a client "243 "is not supported anymore. Instantiate a new client instead, "244 "passing any 'trust_env' argument to the client itself."245 )246247 if stream:247 if stream: # pragma: nocover248 warnings.warn(249 "The 'stream=True' argument is due to be deprecated. "250 "Use 'async with client.stream(method, url, ...) as response' instead."251 )
710 unmodified lines
modified:httpx/config.py+1 added-1 removed
177 unmodified lines
178 if ssl.HAS_ALPN:179 alpn_idents = ["http/1.1", "h2"] if http2 else ["http/1.1"]180 context.set_alpn_protocols(alpn_idents)181182 if hasattr(context, "keylog_filename"):182 if hasattr(context, "keylog_filename"): # pragma: nocover (Available in 3.8+)183 keylogfile = os.environ.get("SSLKEYLOGFILE")184 if keylogfile and self.trust_env:185 context.keylog_filename = keylogfile # type: ignore186
135 unmodified lines
modified:httpx/models.py+4 added-4 removed
858 unmodified lines
859 return self._content860861 @property862 def stream(self): # type: ignore863 warnings.warn(863 warnings.warn( # pragma: nocover864 "Response.stream() is due to be deprecated. "865 "Use Response.aiter_bytes() instead."866 )867 return self.aiter_bytes867 return self.aiter_bytes # pragma: nocover868869 @property870 def raw(self): # type: ignore871 warnings.warn(871 warnings.warn( # pragma: nocover872 "Response.raw() is due to be deprecated. "873 "Use Response.aiter_raw() instead."874 )875 return self.aiter_raw875 return self.aiter_raw # pragma: nocover876877 async def aiter_bytes(self) -> typing.AsyncIterator[bytes]:878 """879 A byte-iterator over the decoded response content.
238 unmodified lines
modified:tests/client/test_redirects.py+1 added
75 unmodified lines
76 content = json.dumps({"headers": headers}).encode()77 return Response(codes.OK, content=content, request=request)7879 elif request.url.path == "/redirect_body":80 body = b"".join([part async for part in request.stream])81 headers = {"location": "/redirect_body_target"}82 return Response(codes.PERMANENT_REDIRECT, headers=headers, request=request)8384 elif request.url.path == "/redirect_no_body":
290 unmodified lines
modified:tests/dispatch/test_http2.py+2 added-2 removed
141 unmodified lines
142async def test_http2_live_request():143 async with AsyncClient(http2=True) as client:144 try:145 resp = await client.get("https://nghttp2.org/httpbin/anything")146 except TimeoutException:146 except TimeoutException: # pragma: nocover147 pytest.xfail(reason="nghttp2.org appears to be unresponsive")148 except socket.gaierror:148 except socket.gaierror: # pragma: nocover149 pytest.xfail(reason="You appear to be offline")150 assert resp.status_code == 200151 assert resp.http_version == "HTTP/2"
modified:tests/dispatch/utils.py+1 added-3 removed
139 unmodified lines
140 len(self.return_data[stream_id]),141 flow_control,142 self.conn.max_outbound_frame_size,143 )144 if chunk_size == 0:145 return146 else:144 if chunk_size > 0:145 chunk, self.return_data[stream_id] = (146 self.return_data[stream_id][:chunk_size],147 self.return_data[stream_id][chunk_size:],148 )
59 unmodified lines
modified:tests/models/test_responses.py+9 added
233 unmodified lines
234 with pytest.raises(httpx.ResponseClosed):235 await response.aread()236237238@pytest.mark.asyncio239async def test_elapsed_not_available_until_closed():240 stream = AsyncIteratorStream(aiterator=async_streaming_body())241 response = httpx.Response(200, stream=stream, request=REQUEST)242243 with pytest.raises(RuntimeError):244 response.elapsed245246247def test_unknown_status_code():248 response = httpx.Response(600, request=REQUEST)249 assert response.status_code == 600250 assert response.reason_phrase == ""
59 unmodified lines
modified:tests/test_decoders.py+7 added
153 unmodified lines
154 nonlocal data155 for chunk in data:156 yield chunk157158 # Accessing `.text` on a read response.159 stream = AsyncIteratorStream(aiterator=iterator())160 response = httpx.Response(200, stream=stream, request=REQUEST)161 await response.aread()162 assert response.text == (b"".join(data)).decode(encoding)163164 # Streaming `.aiter_text` iteratively.165 stream = AsyncIteratorStream(aiterator=iterator())166 response = httpx.Response(200, stream=stream, request=REQUEST)167 text = "".join([part async for part in response.aiter_text()])168 assert text == (b"".join(data)).decode(encoding)169170171@pytest.mark.asyncio172async def test_text_decoder_known_encoding():173 async def iterator():174 yield b"\x83g"
72 unmodified lines