From f256b9d9a980110049fd64280df36654d7ef05a9 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Fri, 19 Jun 2020 07:14:28 -0700 Subject: [PATCH] improve async coverage --- dns/_asyncio_backend.py | 5 +++-- dns/_curio_backend.py | 7 ++++--- dns/_trio_backend.py | 9 +++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dns/_asyncio_backend.py b/dns/_asyncio_backend.py index f82eb823..4120624d 100644 --- a/dns/_asyncio_backend.py +++ b/dns/_asyncio_backend.py @@ -57,7 +57,7 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): self.transport = transport self.protocol = protocol - async def sendto(self, what, destination, timeout): + async def sendto(self, what, destination, timeout): # pragma: no cover # no timeout for asyncio sendto self.transport.sendto(what, destination) @@ -127,7 +127,8 @@ class Backend(dns._asyncbackend.Backend): server_hostname=server_hostname), timeout) return StreamSocket(af, r, w) - raise NotImplementedError(f'unsupported socket type {socktype}') + raise NotImplementedError('unsupported socket ' + + f'type {socktype}') # pragma: no cover async def sleep(self, interval): await asyncio.sleep(interval) diff --git a/dns/_curio_backend.py b/dns/_curio_backend.py index d5eba68d..dca966df 100644 --- a/dns/_curio_backend.py +++ b/dns/_curio_backend.py @@ -30,7 +30,7 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): async def sendto(self, what, destination, timeout): async with _maybe_timeout(timeout): return await self.socket.sendto(what, destination) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # pragma: no cover async def recvfrom(self, size, timeout): async with _maybe_timeout(timeout): @@ -78,7 +78,7 @@ class Backend(dns._asyncbackend.Backend): try: if source: s.bind(_lltuple(source, af)) - except Exception: + except Exception: # pragma: no cover await s.close() raise return DatagramSocket(s) @@ -93,7 +93,8 @@ class Backend(dns._asyncbackend.Backend): source_addr=source_addr, server_hostname=server_hostname) return StreamSocket(s) - raise NotImplementedError(f'unsupported socket type {socktype}') + raise NotImplementedError('unsupported socket ' + + f'type {socktype}') # pragma: no cover async def sleep(self, interval): await curio.sleep(interval) diff --git a/dns/_trio_backend.py b/dns/_trio_backend.py index cfb0e1d1..0f1378f3 100644 --- a/dns/_trio_backend.py +++ b/dns/_trio_backend.py @@ -30,7 +30,7 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): async def sendto(self, what, destination, timeout): with _maybe_timeout(timeout): return await self.socket.sendto(what, destination) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # pragma: no cover async def recvfrom(self, size, timeout): with _maybe_timeout(timeout): @@ -85,7 +85,7 @@ class Backend(dns._asyncbackend.Backend): if socktype == socket.SOCK_STREAM: with _maybe_timeout(timeout): await s.connect(_lltuple(destination, af)) - except Exception: + except Exception: # pragma: no cover s.close() raise if socktype == socket.SOCK_DGRAM: @@ -99,11 +99,12 @@ class Backend(dns._asyncbackend.Backend): try: stream = trio.SSLStream(stream, ssl_context, server_hostname=server_hostname) - except Exception: + except Exception: # pragma: no cover await stream.aclose() raise return StreamSocket(af, stream, tls) - raise NotImplementedError(f'unsupported socket type {socktype}') + raise NotImplementedError('unsupported socket ' + + f'type {socktype}') # pragma: no cover async def sleep(self, interval): await trio.sleep(interval) -- 2.47.3