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
Provenance
- Commit
b8394f1- Tree
ebe7565- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
f5d4bb8
9 files changed+30 added−15 removed
modified:httpx/dispatch/proxy_http.py+1 added-1 removed
44 unmodified lines45 http2: bool = False,46 backend: typing.Union[str, ConcurrencyBackend] = "auto",47 ):48 49- 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 linesmodified:httpx/client.py+4 added-4 removed
221 unmodified lines222 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 )232 233- 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 )239 240- 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 )246 247- 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 linesmodified:httpx/config.py+1 added-1 removed
177 unmodified lines178 if ssl.HAS_ALPN:179 alpn_idents = ["http/1.1", "h2"] if http2 else ["http/1.1"]180 context.set_alpn_protocols(alpn_idents)181 182- 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 linesmodified:httpx/models.py+4 added-4 removed
858 unmodified lines859 return self._content860 861 @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: nocover868 869 @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: nocover876 877 async def aiter_bytes(self) -> typing.AsyncIterator[bytes]:878 """879 A byte-iterator over the decoded response content.238 unmodified linesmodified:tests/client/test_redirects.py+1 added
75 unmodified lines76 content = json.dumps({"headers": headers}).encode()77 return Response(codes.OK, content=content, request=request)78 79 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)83 84 elif request.url.path == "/redirect_no_body":290 unmodified linesmodified:tests/dispatch/test_http2.py+2 added-2 removed
141 unmodified lines142 async 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 lines140 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 linesmodified:tests/models/test_responses.py+9 added
233 unmodified lines234 with pytest.raises(httpx.ResponseClosed):235 await response.aread()236 237 238+@pytest.mark.asyncio239+async def test_elapsed_not_available_until_closed():240+ stream = AsyncIteratorStream(aiterator=async_streaming_body())241+ response = httpx.Response(200, stream=stream, request=REQUEST)242+243+ with pytest.raises(RuntimeError):244+ response.elapsed245+246+247 def test_unknown_status_code():248 response = httpx.Response(600, request=REQUEST)249 assert response.status_code == 600250 assert response.reason_phrase == ""59 unmodified linesmodified:tests/test_decoders.py+7 added
153 unmodified lines154 nonlocal data155 for chunk in data:156 yield chunk157 158+ # 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)163 164+ # 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)169 170+171 @pytest.mark.asyncio172 async def test_text_decoder_known_encoding():173 async def iterator():174 yield b"\x83g"72 unmodified lines