Skip to content

Add # pragma: no cover for unnecessary pieces of the code #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2022
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
8 changes: 4 additions & 4 deletions proxy/common/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
try:
# pylint: disable=unused-import
from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436
except ImportError:
except ImportError: # pragma: no cover
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
__version__ = _get_dist('proxy.py').version # noqa: WPS440


def _to_int_or_str(inp: str) -> Union[int, str]:
def _to_int_or_str(inp: str) -> Union[int, str]: # pragma: no cover
try:
return int(inp)
except ValueError:
return inp


def _split_version_parts(inp: str) -> Tuple[str, ...]:
def _split_version_parts(inp: str) -> Tuple[str, ...]: # pragma: no cover
public_version, _plus, local_version = inp.partition('+')
return (*public_version.split('.'), local_version)


try:
VERSION = _ver_tup
except NameError:
except NameError: # pragma: no cover
VERSION = tuple(
map(_to_int_or_str, _split_version_parts(__version__)),
)
Expand Down
6 changes: 3 additions & 3 deletions proxy/common/backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import deque


class cached_property:
class cached_property: # pragma: no cover
"""Decorator for read-only properties evaluated only once within TTL period.
It can be used to create a cached property like this::

Expand Down Expand Up @@ -111,8 +111,8 @@ def get(self) -> Any:

def empty(self) -> bool:
'''Return True if the queue is empty, False otherwise (not reliable!).'''
return len(self._queue) == 0
return len(self._queue) == 0 # pragma: no cover

def qsize(self) -> int:
'''Return the approximate size of the queue (not reliable!).'''
return len(self._queue)
return len(self._queue) # pragma: no cover
2 changes: 1 addition & 1 deletion proxy/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(
log_level: str = DEFAULT_LOG_LEVEL,
log_format: str = DEFAULT_LOG_FORMAT,
) -> None:
if log_file:
if log_file: # pragma: no cover
logging.basicConfig(
filename=log_file,
filemode='a',
Expand Down
4 changes: 2 additions & 2 deletions proxy/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from typing import TYPE_CHECKING, Dict, Any, List, Tuple, Union


if TYPE_CHECKING:
DictQueueType = queue.Queue[Dict[str, Any]] # pragma: no cover
if TYPE_CHECKING: # pragma: no cover
DictQueueType = queue.Queue[Dict[str, Any]]
else:
DictQueueType = queue.Queue

Expand Down
5 changes: 3 additions & 2 deletions proxy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
DEFAULT_TIMEOUT, DEFAULT_THREADLESS, IS_WINDOWS,
)

if not IS_WINDOWS:
if not IS_WINDOWS: # pragma: no cover
import resource

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -282,7 +282,8 @@ def get_available_port() -> int:

def set_open_file_limit(soft_limit: int) -> None:
"""Configure open file description soft limit on supported OS."""
if IS_WINDOWS: # resource module not available on Windows OS
# resource module not available on Windows OS
if IS_WINDOWS: # pragma: no cover
return

curr_soft_limit, curr_hard_limit = resource.getrlimit(
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/acceptor/acceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _work(self, conn: socket.socket, addr: Optional[Tuple[str, int]]) -> None:
event_queue=self.event_queue,
publisher_id=self.__class__.__name__,
)
logger.debug(
logger.debug( # pragma: no cover
'Started work#{0}.{1}.{2} in thread#{3}'.format(
conn.fileno(), self.idd, self._total, thread.ident,
),
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/connection/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def handle_events(self, readables: Readables, _writables: Writables) -> bo
has somehow reached an illegal state e.g. upstream sending data for previous
connection acquisition lifecycle."""
for fileno in readables:
if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
assert isinstance(fileno, int)
logger.debug('Upstream fd#{0} is read ready'.format(fileno))
self._remove(fileno)
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/work/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import TYPE_CHECKING, Optional, Tuple
from multiprocessing.reduction import send_handle

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
import socket
import multiprocessing
from multiprocessing import connection
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/work/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ...common.flag import flags
from ...common.constants import DEFAULT_NUM_WORKERS, DEFAULT_THREADLESS

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..event import EventQueue

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/work/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..connection import TcpClientConnection
from ..event import EventQueue, eventNames

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from .work import Work


Expand Down
2 changes: 1 addition & 1 deletion proxy/core/work/threadless.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..connection import TcpClientConnection, UpstreamConnectionPool
from ..event import eventNames

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from typing import Any

from ..event import EventQueue
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/work/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..event import eventNames, EventQueue
from ...common.types import Readables, SelectableEvents, Writables

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..connection import UpstreamConnectionPool

T = TypeVar('T')
Expand Down
2 changes: 1 addition & 1 deletion proxy/http/exception/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
from typing import Any, Optional, TYPE_CHECKING

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..parser import HttpParser


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/exception/http_request_rejected.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ...common.utils import build_http_response

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..parser import HttpParser


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/exception/proxy_auth_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ..responses import PROXY_AUTH_FAILED_RESPONSE_PKT

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..parser import HttpParser


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/exception/proxy_conn_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from ..responses import BAD_GATEWAY_RESPONSE_PKT

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..parser import HttpParser


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .descriptors import DescriptorsHandlerMixin
from .mixins import TlsInterceptionPropertyMixin

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ..core.connection import UpstreamConnectionPool


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/proxy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ...core.event import EventQueue
from ...core.connection import TcpClientConnection

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ...core.connection import UpstreamConnectionPool


Expand Down
2 changes: 1 addition & 1 deletion proxy/http/server/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ...core.connection import TcpClientConnection
from ...core.event import EventQueue

if TYPE_CHECKING:
if TYPE_CHECKING: # pragma: no cover
from ...core.connection import UpstreamConnectionPool


Expand Down
1 change: 1 addition & 0 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ h2==4.1.0
hpack==4.0.0
hyperframe==6.0.1
pre-commit==2.16.0
types-setuptools==57.4.7