Skip to content

Commit

Permalink
Change back to codecov (sanic-org#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins authored and ChihweiLHBird committed Jun 1, 2022
1 parent f1a695f commit e2dc070
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 69 deletions.
28 changes: 0 additions & 28 deletions .codeclimate.yml

This file was deleted.

14 changes: 11 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ branch = True
source = sanic
omit =
site-packages
sanic/application/logo.py
sanic/application/motd.py
sanic/cli
sanic/__main__.py
sanic/compat.py
sanic/reloader_helpers.py
sanic/simple.py
sanic/utils.py
sanic/cli

[html]
directory = coverage
Expand All @@ -21,3 +20,12 @@ exclude_lines =
noqa
NOQA
pragma: no cover
omit =
site-packages
sanic/__main__.py
sanic/compat.py
sanic/reloader_helpers.py
sanic/simple.py
sanic/utils.py
sanic/cli
skip_empty = True
11 changes: 5 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -29,9 +28,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- uses: paambaati/codeclimate-action@v2.5.3
if: always()
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE }}
- name: Run coverage
run: tox -e coverage
- uses: codecov/codecov-action@v2
with:
coverageCommand: tox -e coverage
files: ./coverage.xml
fail_ci_if_error: false
27 changes: 27 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
coverage:
status:
patch:
default:
target: auto
threshold: 0.75
project:
default:
target: auto
threshold: 0.5
precision: 3
codecov:
require_ci_to_pass: false
ignore:
- "sanic/__main__.py"
- "sanic/compat.py"
- "sanic/reloader_helpers.py"
- "sanic/simple.py"
- "sanic/utils.py"
- "sanic/cli"
- ".github/"
- "changelogs/"
- "docker/"
- "docs/"
- "examples/"
- "scripts/"
- "tests/"
16 changes: 8 additions & 8 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
Extend = TypeVar("Extend") # type: ignore


if OS_IS_WINDOWS:
if OS_IS_WINDOWS: # no cov
enable_windows_color_support()

filterwarnings("once", category=DeprecationWarning)
Expand Down Expand Up @@ -1554,7 +1554,7 @@ def _loop_add_task(
) -> Task:
if not isinstance(task, Future):
prepped = cls._prep_task(task, app, loop)
if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # no cov
if name:
error_logger.warning(
"Cannot set a name for a task when using Python 3.7. "
Expand Down Expand Up @@ -1598,7 +1598,7 @@ def add_task(
:param task: future, couroutine or awaitable
"""
if name and sys.version_info == (3, 7):
if name and sys.version_info < (3, 8): # no cov
name = None
error_logger.warning(
"Cannot set a name for a task when using Python 3.7. Your "
Expand Down Expand Up @@ -1626,7 +1626,7 @@ def add_task(
def get_task(
self, name: str, *, raise_exception: bool = True
) -> Optional[Task]:
if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # no cov
error_logger.warning(
"This feature (get_task) is only supported on using "
"Python 3.8+."
Expand All @@ -1648,7 +1648,7 @@ async def cancel_task(
*,
raise_exception: bool = True,
) -> None:
if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # no cov
error_logger.warning(
"This feature (cancel_task) is only supported on using "
"Python 3.8+."
Expand All @@ -1660,7 +1660,7 @@ async def cancel_task(
if msg:
if sys.version_info >= (3, 9):
args = (msg,)
else:
else: # no cov
raise RuntimeError(
"Cancelling a task with a message is only supported "
"on Python 3.9+."
Expand All @@ -1672,7 +1672,7 @@ async def cancel_task(
...

def purge_tasks(self):
if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # no cov
error_logger.warning(
"This feature (purge_tasks) is only supported on using "
"Python 3.8+."
Expand Down Expand Up @@ -1709,7 +1709,7 @@ def shutdown_tasks(

@property
def tasks(self):
if sys.version_info < (3, 8):
if sys.version_info < (3, 8): # no cov
error_logger.warning(
"This feature (tasks) is only supported on using "
"Python 3.8+."
Expand Down
8 changes: 4 additions & 4 deletions sanic/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def __init__(
self._warn_fallback_deprecation()

@property
def fallback(self):
def fallback(self): # no cov
# This is for backwards compat and can be removed in v22.6
if self._fallback is _default:
return DEFAULT_FORMAT
return self._fallback

@fallback.setter
def fallback(self, value: str):
def fallback(self, value: str): # no cov
self._warn_fallback_deprecation()
if not isinstance(value, str):
raise SanicException(
Expand Down Expand Up @@ -236,7 +236,7 @@ def response(self, request, exception):
except Exception:
try:
url = repr(request.url)
except AttributeError:
except AttributeError: # no cov
url = "unknown"
response_message = (
"Exception raised in exception handler " '"%s" for uri: %s'
Expand Down Expand Up @@ -281,7 +281,7 @@ def log(request, exception):
if quiet is False or noisy is True:
try:
url = repr(request.url)
except AttributeError:
except AttributeError: # no cov
url = "unknown"

error_logger.exception(
Expand Down
12 changes: 6 additions & 6 deletions sanic/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from warnings import warn


LOGGING_CONFIG_DEFAULTS: Dict[str, Any] = dict(
LOGGING_CONFIG_DEFAULTS: Dict[str, Any] = dict( # no cov
version=1,
disable_existing_loggers=False,
loggers={
Expand Down Expand Up @@ -57,31 +57,31 @@
)


class Colors(str, Enum):
class Colors(str, Enum): # no cov
END = "\033[0m"
BLUE = "\033[01;34m"
GREEN = "\033[01;32m"
YELLOW = "\033[01;33m"
RED = "\033[01;31m"


logger = logging.getLogger("sanic.root")
logger = logging.getLogger("sanic.root") # no cov
"""
General Sanic logger
"""

error_logger = logging.getLogger("sanic.error")
error_logger = logging.getLogger("sanic.error") # no cov
"""
Logger used by Sanic for error logging
"""

access_logger = logging.getLogger("sanic.access")
access_logger = logging.getLogger("sanic.access") # no cov
"""
Logger used by Sanic for access logging
"""


def deprecation(message: str, version: float):
def deprecation(message: str, version: float): # no cov
version_info = f"[DEPRECATION v{version}] "
if sys.stdout.isatty():
version_info = f"{Colors.RED}{version_info}"
Expand Down
4 changes: 2 additions & 2 deletions sanic/models/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ASGIReceive = Callable[[], Awaitable[ASGIMessage]]


class MockProtocol:
class MockProtocol: # no cov
def __init__(self, transport: "MockTransport", loop):
# This should be refactored when < 3.8 support is dropped
self.transport = transport
Expand Down Expand Up @@ -56,7 +56,7 @@ async def drain(self) -> None:
await self._not_paused.wait()


class MockTransport:
class MockTransport: # no cov
_protocol: Optional[MockProtocol]

def __init__(
Expand Down
12 changes: 6 additions & 6 deletions sanic/server/websockets/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sanic.exceptions import ServerError


if TYPE_CHECKING:
if TYPE_CHECKING: # no cov
from .impl import WebsocketImplProtocol

UTF8Decoder = codecs.getincrementaldecoder("utf-8")
Expand Down Expand Up @@ -37,7 +37,7 @@ class WebsocketFrameAssembler:
"get_id",
"put_id",
)
if TYPE_CHECKING:
if TYPE_CHECKING: # no cov
protocol: "WebsocketImplProtocol"
read_mutex: asyncio.Lock
write_mutex: asyncio.Lock
Expand Down Expand Up @@ -131,7 +131,7 @@ async def get(self, timeout: Optional[float] = None) -> Optional[Data]:
if self.paused:
self.protocol.resume_frames()
self.paused = False
if not self.get_in_progress:
if not self.get_in_progress: # no cov
# This should be guarded against with the read_mutex,
# exception is here as a failsafe
raise ServerError(
Expand Down Expand Up @@ -204,23 +204,23 @@ async def get_iter(self) -> AsyncIterator[Data]:
if self.paused:
self.protocol.resume_frames()
self.paused = False
if not self.get_in_progress:
if not self.get_in_progress: # no cov
# This should be guarded against with the read_mutex,
# exception is here as a failsafe
raise ServerError(
"State of Websocket frame assembler was modified while an "
"asynchronous get was in progress."
)
self.get_in_progress = False
if not self.message_complete.is_set():
if not self.message_complete.is_set(): # no cov
# This should be guarded against with the read_mutex,
# exception is here as a failsafe
raise ServerError(
"Websocket frame assembler chunks queue ended before "
"message was complete."
)
self.message_complete.clear()
if self.message_fetched.is_set():
if self.message_fetched.is_set(): # no cov
# This should be guarded against with the read_mutex,
# and get_in_progress check, this exception is
# here as a failsafe
Expand Down
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import base64
import logging
import random
import re
Expand Down Expand Up @@ -205,7 +204,3 @@ def sanic_ext(ext_instance): # noqa
yield sanic_ext
with suppress(KeyError):
del sys.modules["sanic_ext"]


def encode_basic_auth_credentials(username, password):
return base64.b64encode(f"{username}:{password}".encode()).decode("ascii")
6 changes: 5 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import logging

from json import dumps as json_dumps
Expand All @@ -18,7 +19,10 @@
from sanic.exceptions import ServerError
from sanic.request import DEFAULT_HTTP_CONTENT_TYPE, RequestParameters
from sanic.response import html, json, text
from tests.conftest import encode_basic_auth_credentials


def encode_basic_auth_credentials(username, password):
return base64.b64encode(f"{username}:{password}".encode()).decode("ascii")


# ------------------------------------------------------------ #
Expand Down
Loading

0 comments on commit e2dc070

Please sign in to comment.