Skip to content
Myr

Get test suite back to ~100% line coverage (#406)

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

authored by Seth Michael Larson · committed by GitHub · parent 5ced56b · Browse files · 10 files+107 added−16 removed
This commit

State

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

Diff stats

10 files+107 added−16 removed

  • tests:+104 added−6 removed
  • other:+3 added−10 removed

10 files+107 added−16 removed

modified:httpx/concurrency/asyncio/backend.py-4 removed
52 unmodified lines
53 if ssl_object is None:54 return "HTTP/1.1"5556 ident = ssl_object.selected_alpn_protocol()5758 if ident is None:59 return "HTTP/1.1"6057 return "HTTP/2" if ident == "h2" else "HTTP/1.1"5859 async def read(60 self, n: int, timeout: TimeoutConfig = None, flag: TimeoutFlag = None
207 unmodified lines
modified:httpx/concurrency/trio.py+1 added-4 removed
37 unmodified lines
38 if not isinstance(self.stream, trio.SSLStream):39 return "HTTP/1.1"4041 ident = self.stream.selected_alpn_protocol()42 if ident is None:43 return "HTTP/1.1"4442 return "HTTP/2" if ident == "h2" else "HTTP/1.1"4344 async def read(45 self, n: int, timeout: TimeoutConfig = None, flag: TimeoutFlag = None
28 unmodified lines
74 # See: https://github.com/encode/httpx/pull/143#issuecomment-51518177875 return stream.socket.is_readable()7677 def write_no_block(self, data: bytes) -> None:81 self.write_buffer += data78 self.write_buffer += data # pragma: no cover7980 async def write(81 self, data: bytes, timeout: TimeoutConfig = None, flag: TimeoutFlag = None82 ) -> None:
170 unmodified lines
modified:httpx/dispatch/http2.py+1 added-1 removed
219 unmodified lines
220 window_update_event.set()221 else:222 try:223 self.window_update_received[event_stream_id].set()224 except KeyError:224 except KeyError: # pragma: no cover225 # the window_update_received dictionary is only relevant226 # when sending data, which should never raise a KeyError227 # here.228 pass
23 unmodified lines
modified:httpx/models.py+1 added-1 removed
39 unmodified lines
40 parse_header_links,41 str_query_param,42)4344if typing.TYPE_CHECKING:44if typing.TYPE_CHECKING: # pragma: no cover45 from .middleware.base import BaseMiddleware # noqa: F40146 from .dispatch.base import AsyncDispatcher # noqa: F4014748PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]]
1244 unmodified lines
modified:tests/client/test_auth.py-3 removed
89 unmodified lines
90 ("www-authenticate", 'Digest realm="httpx@example.org", ' + challenge_str)91 ]92 return AsyncResponse(401, headers=headers, content=b"", request=request)9394 def reset(self) -> None:95 self._response_count = 0949795def test_basic_auth():96 url = "https://example.org/"97 auth = ("tomchristie", "password123")98
257 unmodified lines
modified:tests/client/test_proxies.py+71 added-1 removed
28 unmodified lines
29 assert len(expected_proxies) == len(client.proxies)303132def test_proxies_has_same_properties_as_dispatch():33 client = httpx.AsyncClient(proxies="http://127.0.0.1")33 client = httpx.AsyncClient(34 proxies="http://127.0.0.1",35 verify="/path/to/verify",36 cert="/path/to/cert",37 trust_env=False,38 timeout=30,39 http_versions=["HTTP/1.1"],40 )41 pool = client.dispatch42 proxy = client.proxies["all"]4344 assert isinstance(pool, httpx.ConnectionPool)
7 unmodified lines
52 "http_versions",53 "backend",54 ]:55 assert getattr(pool, prop) == getattr(proxy, prop)565758PROXY_URL = "http://[::1]"596061@pytest.mark.parametrize(62 ["url", "proxies", "expected"],63 [64 ("http://example.com", None, None),65 ("http://example.com", {}, None),66 ("http://example.com", {"https": PROXY_URL}, None),67 ("http://example.com", {"http://example.net": PROXY_URL}, None),68 ("http://example.com:443", {"http://example.com": PROXY_URL}, None),69 ("http://example.com", {"all": PROXY_URL}, PROXY_URL),70 ("http://example.com", {"http": PROXY_URL}, PROXY_URL),71 ("http://example.com", {"all://example.com": PROXY_URL}, PROXY_URL),72 ("http://example.com", {"all://example.com:80": PROXY_URL}, PROXY_URL),73 ("http://example.com", {"http://example.com": PROXY_URL}, PROXY_URL),74 ("http://example.com", {"http://example.com:80": PROXY_URL}, PROXY_URL),75 ("http://example.com:8080", {"http://example.com:8080": PROXY_URL}, PROXY_URL),76 ("http://example.com:8080", {"http://example.com": PROXY_URL}, None),77 (78 "http://example.com",79 {80 "all": PROXY_URL + ":1",81 "http": PROXY_URL + ":2",82 "all://example.com": PROXY_URL + ":3",83 "http://example.com": PROXY_URL + ":4",84 },85 PROXY_URL + ":4",86 ),87 (88 "http://example.com",89 {90 "all": PROXY_URL + ":1",91 "http": PROXY_URL + ":2",92 "all://example.com": PROXY_URL + ":3",93 },94 PROXY_URL + ":3",95 ),96 (97 "http://example.com",98 {"all": PROXY_URL + ":1", "http": PROXY_URL + ":2"},99 PROXY_URL + ":2",100 ),101 ],102)103def test_dispatcher_for_request(url, proxies, expected):104 client = httpx.AsyncClient(proxies=proxies)105 request = httpx.AsyncRequest("GET", url)106 dispatcher = client._dispatcher_for_request(request, client.proxies)107108 if expected is None:109 assert isinstance(dispatcher, httpx.ConnectionPool)110 assert dispatcher is client.dispatch111 else:112 assert isinstance(dispatcher, httpx.HTTPProxy)113 assert dispatcher.proxy_url == expected114115116def test_unsupported_proxy_scheme():117 with pytest.raises(ValueError):118 httpx.AsyncClient(proxies="ftp://127.0.0.1")
modified:tests/client/test_queryparams.py+5 added
35 unmodified lines
36 client = Client(params="a=b")37 assert isinstance(client.params, QueryParams)38 assert client.params["a"] == "b"3940 client = Client()41 client.params = "a=b"42 assert isinstance(client.params, QueryParams)43 assert client.params["a"] == "b"444546def test_client_queryparams_echo():47 url = "http://example.org/echo_queryparams"48 client_queryparams = "first=str"49 request_queryparams = {"second": "dict"}
7 unmodified lines
modified:tests/dispatch/test_http2.py+8 added
202 unmodified lines
203 assert len(settings.changed_settings) == len(expected_settings)204 for setting_code, changed_setting in settings.changed_settings.items():205 assert isinstance(changed_setting, h2.settings.ChangedSetting)206 assert changed_setting.new_value == expected_settings[setting_code]207208209async def test_http2_live_request(backend):210 async with AsyncClient(backend=backend) as client:211 resp = await client.get("https://nghttp2.org/httpbin/anything")212213 assert resp.status_code == 200214 assert resp.http_version == "HTTP/2"
modified:tests/dispatch/test_proxy_http.py+9 added-2 removed
164 unmodified lines
165 ),166 backend=backend,167 )168 async with httpx.HTTPProxy(169 proxy_url="http://127.0.0.1:8000", backend=raw_io, proxy_mode=proxy_mode169 proxy_url="http://127.0.0.1:8000",170 backend=raw_io,171 proxy_mode=proxy_mode,172 proxy_headers={"Proxy-Authorization": "test", "Override": "2"},173 ) as proxy:171 response = await proxy.request("GET", f"http://example.com")174 response = await proxy.request(175 "GET", f"http://example.com", headers={"override": "1"}176 )177178 assert response.status_code == 200179 assert response.headers["Server"] == "origin-server"180
7 unmodified lines
188 assert recv[0] == b"--- CONNECT(127.0.0.1, 8000) ---"189 assert recv[1].startswith(190 b"GET http://example.com HTTP/1.1\r\nhost: example.com\r\n"191 )192 assert b"proxy-authorization: test" in recv[1]193 assert b"override: 1" in recv[1]194195196def test_proxy_url_with_username_and_password():197 proxy = httpx.HTTPProxy("http://user:password@example.com:1080")
17 unmodified lines
modified:tests/models/test_queryparams.py+11 added
49 unmodified lines
50 assert str(q) == "a=1.23"5152 q = QueryParams({"a": 123})53 assert str(q) == "a=123"545556def test_queryparam_setters():57 q = QueryParams({"a": 1})58 q.update([])5960 assert str(q) == "a=1"6162 q = QueryParams([("a", 1), ("a", 2)])63 q["a"] = "3"64 assert str(q) == "a=3"