Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiohttp/_websocket/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _websocket_mask_python(mask: bytes, data: bytearray) -> None:
data[3::4] = data[3::4].translate(d)


if TYPE_CHECKING or NO_EXTENSIONS: # pragma: no cover
if TYPE_CHECKING or NO_EXTENSIONS:
websocket_mask = _websocket_mask_python
else:
try:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/_websocket/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ..helpers import NO_EXTENSIONS

if TYPE_CHECKING or NO_EXTENSIONS: # pragma: no cover
if TYPE_CHECKING or NO_EXTENSIONS:
from .reader_py import (
WebSocketDataQueue as WebSocketDataQueuePython,
WebSocketReader as WebSocketReaderPython,
Expand Down
6 changes: 2 additions & 4 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,7 @@ def links(self) -> "MultiDictProxy[MultiDictProxy[Union[str, URL]]]":

for val in re.split(r",(?=\s*<)", links_str):
match = re.match(r"\s*<(.*)>(.*)", val)
if match is None: # pragma: no cover
# the check exists to suppress mypy error
if match is None: # Malformed link
continue
url, params_str = match.groups()
params = params_str.split(";")[1:]
Expand All @@ -963,8 +962,7 @@ def links(self) -> "MultiDictProxy[MultiDictProxy[Union[str, URL]]]":

for param in params:
match = re.match(r"^\s*(\S*)\s*=\s*(['\"]?)(.*?)(\2)\s*$", param, re.M)
if match is None: # pragma: no cover
# the check exists to suppress mypy error
if match is None: # Malformed param
continue
key, _, value, _ = match.groups()

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/compression_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import brotli

HAS_BROTLI = True
except ImportError: # pragma: no cover
except ImportError:
HAS_BROTLI = False

MAX_SYNC_CHUNK_SIZE = 1024
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def netrc_from_env() -> Optional[netrc.netrc]:
else:
try:
home_dir = Path.home()
except RuntimeError as e: # pragma: no cover
except RuntimeError as e:
# if pathlib can't resolve home, it may raise a RuntimeError
client_logger.debug(
"Could not resolve home directory when "
Expand Down Expand Up @@ -776,7 +776,7 @@ def set_exception(
self,
exc: Union[Type[BaseException], BaseException],
exc_cause: BaseException = ...,
) -> None: ... # pragma: no cover
) -> None: ...


def set_exception(
Expand Down
6 changes: 2 additions & 4 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def __init__(self, out: StreamReader, encoding: Optional[str]) -> None:

self.decompressor: Union[BrotliDecompressor, ZLibDecompressor]
if encoding == "br":
if not HAS_BROTLI: # pragma: no cover
if not HAS_BROTLI:
raise ContentEncodingError(
"Can not decode content-encoding: brotli (br). "
"Please install `Brotli`"
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def end_http_chunk_receiving(self) -> None:
RawRequestMessagePy = RawRequestMessage
RawResponseMessagePy = RawResponseMessage

try:
with suppress(ImportError):
if not NO_EXTENSIONS:
from ._http_parser import ( # type: ignore[import-not-found,no-redef]
HttpRequestParser,
Expand All @@ -1016,5 +1016,3 @@ def end_http_chunk_receiving(self) -> None:
HttpResponseParserC = HttpResponseParser
RawRequestMessageC = RawRequestMessage
RawResponseMessageC = RawResponseMessage
except ImportError: # pragma: no cover
pass
8 changes: 4 additions & 4 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

try:
import uvloop
except ImportError: # pragma: no cover
except ImportError:
uvloop = None # type: ignore[assignment]

_Request = TypeVar("_Request", bound=BaseRequest)
Expand Down Expand Up @@ -243,7 +243,7 @@ def pytest_generate_tests(metafunc): # type: ignore[no-untyped-def]
avail_factories: Dict[str, Type[asyncio.AbstractEventLoopPolicy]]
avail_factories = {"pyloop": asyncio.DefaultEventLoopPolicy}

if uvloop is not None: # pragma: no cover
if uvloop is not None:
avail_factories["uvloop"] = uvloop.EventLoopPolicy

if loops == "all":
Expand All @@ -253,7 +253,7 @@ def pytest_generate_tests(metafunc): # type: ignore[no-untyped-def]
for name in loops.split(","):
required = not name.endswith("?")
name = name.strip(" ?")
if name not in avail_factories: # pragma: no cover
if name not in avail_factories:
if required:
raise ValueError(
"Unknown loop '%s', available loops: %s"
Expand All @@ -274,7 +274,7 @@ def loop(loop_factory, fast, loop_debug): # type: ignore[no-untyped-def]
asyncio.set_event_loop_policy(policy)
with loop_context(fast=fast) as _loop:
if loop_debug:
_loop.set_debug(True) # pragma: no cover
_loop.set_debug(True)
asyncio.set_event_loop(_loop)
yield _loop

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import aiodns

aiodns_default = hasattr(aiodns.DNSResolver, "getaddrinfo")
except ImportError: # pragma: no cover
except ImportError:
aiodns = None # type: ignore[assignment]
aiodns_default = False

Expand Down
5 changes: 2 additions & 3 deletions aiohttp/tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import socket
from contextlib import suppress
from typing import Optional # noqa

__all__ = ("tcp_keepalive", "tcp_nodelay")

Expand All @@ -17,8 +16,8 @@ def tcp_keepalive(transport: asyncio.Transport) -> None:

else:

def tcp_keepalive(transport: asyncio.Transport) -> None: # pragma: no cover
pass
def tcp_keepalive(transport: asyncio.Transport) -> None:
"""Noop when keepalive not supported."""


def tcp_nodelay(transport: asyncio.Transport, value: bool) -> None:
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ async def start_server(self, **kwargs: Any) -> None:
self.scheme = "https" if self._ssl else "http"
self._root = URL(f"{self.scheme}://{absolute_host}:{self.port}")

@abstractmethod # pragma: no cover
@abstractmethod
async def _make_runner(self, **kwargs: Any) -> BaseRunner[_Request]:
pass
"""Return a new runner for the server."""

def make_url(self, path: StrOrURL) -> URL:
assert self._root is not None
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def run_app(
try:
asyncio.set_event_loop(loop)
loop.run_until_complete(main_task)
except (GracefulExit, KeyboardInterrupt): # pragma: no cover
except (GracefulExit, KeyboardInterrupt):
pass
finally:
try:
Expand Down
3 changes: 1 addition & 2 deletions aiohttp/web_routedef.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
import dataclasses
import os # noqa
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -48,7 +47,7 @@
class AbstractRouteDef(abc.ABC):
@abc.abstractmethod
def register(self, router: UrlDispatcher) -> List[AbstractRoute]:
pass # pragma: no cover
"""Register itself into the given router."""


_HandlerType = Union[Type[AbstractView], Handler]
Expand Down
10 changes: 5 additions & 5 deletions aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
@property
@abstractmethod
def name(self) -> str:
pass # pragma: no cover
"""Return the name of the site (e.g. a URL)."""

@abstractmethod
async def start(self) -> None:
Expand Down Expand Up @@ -276,7 +276,7 @@ async def setup(self) -> None:
try:
loop.add_signal_handler(signal.SIGINT, _raise_graceful_exit)
loop.add_signal_handler(signal.SIGTERM, _raise_graceful_exit)
except NotImplementedError: # pragma: no cover
except NotImplementedError:
# add_signal_handler is not implemented on Windows
pass

Expand Down Expand Up @@ -309,17 +309,17 @@ async def cleanup(self) -> None:
try:
loop.remove_signal_handler(signal.SIGINT)
loop.remove_signal_handler(signal.SIGTERM)
except NotImplementedError: # pragma: no cover
except NotImplementedError:
# remove_signal_handler is not implemented on Windows
pass

@abstractmethod
async def _make_server(self) -> Server[_Request]:
pass # pragma: no cover
"""Return a new server for the runner to serve requests."""

@abstractmethod
async def _cleanup_server(self) -> None:
pass # pragma: no cover
"""Run any cleanup steps after the server is shutdown."""

def _reg_site(self, site: BaseSite) -> None:
if site in self._sites:
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def current_app(self) -> "Application":

@current_app.setter
def current_app(self, app: "Application") -> None:
if DEBUG: # pragma: no cover
if DEBUG:
if app not in self._apps:
raise RuntimeError(
"Expected one of the following apps {!r}, got {!r}".format(
Expand Down Expand Up @@ -368,7 +368,7 @@ async def resolve(self, request: Request) -> _Resolve:

@abc.abstractmethod
def _match(self, path: str) -> Optional[Dict[str, str]]:
pass # pragma: no cover
"""Return dict of path values if path matches this resource, otherwise None."""

def __len__(self) -> int:
return len(self._routes)
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GunicornWebWorker(base.Worker): # type: ignore[misc,no-any-unimported]
DEFAULT_AIOHTTP_LOG_FORMAT = AccessLogger.LOG_FORMAT
DEFAULT_GUNICORN_LOG_FORMAT = GunicornAccessLogFormat.default

def __init__(self, *args: Any, **kw: Any) -> None: # pragma: no cover
def __init__(self, *args: Any, **kw: Any) -> None:
super().__init__(*args, **kw)

self._task: Optional[asyncio.Task[None]] = None
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ async def handler(request: web.Request) -> web.Response:

with pytest.raises(aiohttp.ClientResponseError):
async with aiohttp.request("GET", url, raise_for_status=True):
assert False, "never executed" # pragma: no cover
assert False


async def test_session_raise_for_status_coro(aiohttp_client: AiohttpClient) -> None:
Expand Down Expand Up @@ -3414,7 +3414,7 @@ async def handler(request: web.Request) -> NoReturn:
async def test_aiohttp_request_ctx_manager_not_found() -> None:
with pytest.raises(aiohttp.ClientConnectionError):
async with aiohttp.request("GET", "http://wrong-dns-name.com"):
assert False, "never executed" # pragma: no cover
assert False


async def test_raising_client_connector_dns_error_on_dns_failure() -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import re
from contextlib import suppress
from typing import Any, Dict, Iterable, List, Type
from unittest import mock
from urllib.parse import quote
Expand Down Expand Up @@ -36,13 +37,11 @@
REQUEST_PARSERS = [HttpRequestParserPy]
RESPONSE_PARSERS = [HttpResponseParserPy]

try:
with suppress(ImportError):
from aiohttp.http_parser import HttpRequestParserC, HttpResponseParserC

REQUEST_PARSERS.append(HttpRequestParserC)
RESPONSE_PARSERS.append(HttpResponseParserC)
except ImportError: # pragma: no cover
pass


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def __init__(self, *args: Any, **kwargs: Any):
async def test() -> None:
await asyncio.sleep(0.5)
async with ClientSession() as sess:
for _ in range(5): # pragma: no cover
for _ in range(5): # Retry for flaky tests # pragma: no cover
try:
with pytest.raises(asyncio.TimeoutError):
async with sess.get(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_app_run_middlewares() -> None:
assert root._run_middlewares is False

async def middleware(request: web.Request, handler: Handler) -> web.StreamResponse:
return await handler(request) # pragma: no cover
assert False

root = web.Application(middlewares=[middleware])
sub = web.Application()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ async def test_handler_metadata_persistence() -> None:

async def async_handler(request: web.Request) -> web.Response:
"""Doc"""
return web.Response() # pragma: no cover
assert False

app.router.add_get("/async", async_handler)

Expand Down Expand Up @@ -696,7 +696,7 @@ def test_reuse_last_added_resource(path: str) -> None:
app = web.Application()

async def handler(request: web.Request) -> web.Response:
return web.Response() # pragma: no cover
assert False

app.router.add_get(path, handler, name="a")
app.router.add_post(path, handler, name="a")
Expand All @@ -708,7 +708,7 @@ def test_resource_raw_match() -> None:
app = web.Application()

async def handler(request: web.Request) -> web.Response:
return web.Response() # pragma: no cover
assert False

route = app.router.add_get("/a", handler, name="a")
assert route.resource is not None
Expand Down
Loading
Loading