Skip to content
Myr

More coverage improvements (#711)

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

* More coverage improvements * Drop redundant 'sleep' usage in test utils

authored by Tom Christie · committed by GitHub · parent 11e7604 · Browse files · 5 files+2 added−37 removed
This commit

State

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

Diff stats

5 files+2 added−37 removed

  • tests:+1 added−27 removed
  • other:+1 added−10 removed

5 files+2 added−37 removed

modified:httpx/backends/auto.py+1 added-1 removed
16 unmodified lines
17 @property18 def backend(self) -> ConcurrencyBackend:19 if not hasattr(self, "_backend_implementation"):20 backend = sniffio.current_async_library()21 if backend not in ("asyncio", "trio"):21 if backend not in ("asyncio", "trio"): # pragma: nocover22 raise RuntimeError(f"Unsupported concurrency backend {backend!r}")23 self._backend_implementation = lookup_backend(backend)24 return self._backend_implementation25
31 unmodified lines
modified:httpx/utils.py-9 removed
251 unmodified lines
252253 return typing.cast(Logger, logger)254255256def kv_format(**kwargs: typing.Any) -> str:257 """Format arguments into a key=value line.258259 >>> formatkv(x=1, name="Bob")260 "x=1 name='Bob'"261 """262 return " ".join(f"{key}={value!r}" for key, value in kwargs.items())263264256def should_not_be_proxied(url: "URL") -> bool:257 """ Return True if url should not be proxied,258 return False otherwise.259 """
96 unmodified lines
modified:tests/dispatch/utils.py-3 removed
5 unmodified lines
6import h2.events78from httpx import Request, Timeout9from httpx.backends.base import BaseSocketStream, lookup_backend10from tests.concurrency import sleep101112class MockHTTP2Backend:13 def __init__(self, app, backend="auto"):
33 unmodified lines
47 def get_http_version(self) -> str:48 return "HTTP/2"4950 async def read(self, n, timeout, flag=None) -> bytes:52 await sleep(self.backend, 0)51 send, self.buffer = self.buffer[:n], self.buffer[n:]52 return send5354 async def write(self, data: bytes, timeout) -> None:
137 unmodified lines
192 return193 self.backend.received_data.append(data)194195 async def read(self, n, timeout, flag=None) -> bytes:198 await sleep(self.backend.backend, 0)196 if not self.backend.data_to_send:197 return b""198 return self.backend.data_to_send.pop(0)199
5 unmodified lines
modified:tests/concurrency.py-20 removed
13 unmodified lines
14from httpx.backends.trio import TrioBackend151617@functools.singledispatch18async def sleep(backend, seconds: int):19 raise NotImplementedError # pragma: no cover202122@sleep.register(AutoBackend)23async def _sleep_auto(backend, seconds: int):24 return await sleep(backend.backend, seconds=seconds)252627@sleep.register(AsyncioBackend)28async def _sleep_asyncio(backend, seconds: int):29 await asyncio.sleep(seconds)303132@sleep.register(TrioBackend)33async def _sleep_trio(backend, seconds: int):34 await trio.sleep(seconds)353637@functools.singledispatch18async def run_concurrently(backend, *coroutines: typing.Callable[[], typing.Awaitable]):19 raise NotImplementedError # pragma: no cover2021
36 unmodified lines
modified:tests/test_decoders.py+1 added-4 removed
123 unmodified lines
124 headers = [(b"Content-Encoding", header_value)]125 body = b"test 123"126 compressed_body = brotli.compress(body)[3:]127 with pytest.raises(httpx.DecodingError):128 response = httpx.Response(129 200, headers=headers, content=compressed_body, request=REQUEST130 )131 response.content128 httpx.Response(200, headers=headers, content=compressed_body, request=REQUEST)129130131@pytest.mark.parametrize(132 ["data", "encoding"],
111 unmodified lines