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
Provenance
- Commit
f5eaec7- Tree
6121063- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
11e7604
5 files changed+2 added−37 removed
modified:httpx/backends/auto.py+1 added-1 removed
16 unmodified lines17 @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 linesmodified:httpx/utils.py-9 removed
251 unmodified lines252 253 return typing.cast(Logger, logger)254 255 256-def kv_format(**kwargs: typing.Any) -> str:257- """Format arguments into a key=value line.258-259- >>> formatkv(x=1, name="Bob")260- "x=1 name='Bob'"261- """262- return " ".join(f"{key}={value!r}" for key, value in kwargs.items())263-264-256 def should_not_be_proxied(url: "URL") -> bool:257 """ Return True if url should not be proxied,258 return False otherwise.259 """96 unmodified linesmodified:tests/dispatch/utils.py-3 removed
5 unmodified lines6 import h2.events7 8 from httpx import Request, Timeout9 from httpx.backends.base import BaseSocketStream, lookup_backend10-from tests.concurrency import sleep10 11 12 class MockHTTP2Backend:13 def __init__(self, app, backend="auto"):33 unmodified lines47 def get_http_version(self) -> str:48 return "HTTP/2"49 50 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 send53 54 async def write(self, data: bytes, timeout) -> None:137 unmodified lines192 return193 self.backend.received_data.append(data)194 195 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 linesmodified:tests/concurrency.py-20 removed
13 unmodified lines14 from httpx.backends.trio import TrioBackend15 16 17 @functools.singledispatch18-async def sleep(backend, seconds: int):19- raise NotImplementedError # pragma: no cover20-21-22-@sleep.register(AutoBackend)23-async def _sleep_auto(backend, seconds: int):24- return await sleep(backend.backend, seconds=seconds)25-26-27-@sleep.register(AsyncioBackend)28-async def _sleep_asyncio(backend, seconds: int):29- await asyncio.sleep(seconds)30-31-32-@sleep.register(TrioBackend)33-async def _sleep_trio(backend, seconds: int):34- await trio.sleep(seconds)35-36-37-@functools.singledispatch18 async def run_concurrently(backend, *coroutines: typing.Callable[[], typing.Awaitable]):19 raise NotImplementedError # pragma: no cover20 21 36 unmodified linesmodified:tests/test_decoders.py+1 added-4 removed
123 unmodified lines124 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)129 130 131 @pytest.mark.parametrize(132 ["data", "encoding"],111 unmodified lines