add coverage condition annotation (#1858)

This commit is contained in:
Ju4tCode 2023-03-29 11:57:33 +08:00 committed by GitHub
parent ae08568daf
commit 1213e89bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 8 deletions

View File

@ -27,7 +27,7 @@ HANDLED_SIGNALS = (
signal.SIGINT, # Unix signal 2. Sent by Ctrl+C.
signal.SIGTERM, # Unix signal 15. Sent by `kill <pid>`.
)
if WINDOWS:
if WINDOWS: # pragma: py-win32
HANDLED_SIGNALS += (signal.SIGBREAK,) # Windows signal 21. Sent by Ctrl+Break.

View File

@ -15,9 +15,9 @@ from .plugin import Plugin
from .manager import PluginManager
from . import _managers, get_plugin, _module_name_to_plugin_name
try:
try: # pragma: py-gte-311
import tomllib # pyright: reportMissingImports=false
except ModuleNotFoundError:
except ModuleNotFoundError: # pragma: py-lt-311
import tomli as tomllib

View File

@ -541,7 +541,7 @@ class ShellCommandRule:
try:
args = self.parser.parse_args(state[SHELL_ARGV])
state[SHELL_ARGS] = args
except ArgumentError as e:
except ArgumentError as e: # pragma: py-gte-39
state[SHELL_ARGS] = ParserExit(status=2, message=str(e))
except ParserExit as e:
state[SHELL_ARGS] = e

25
poetry.lock generated
View File

@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand.
# This file is automatically @generated by Poetry 1.4.1 and should not be changed by hand.
[[package]]
name = "aiodns"
@ -709,6 +709,23 @@ tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.1
[package.extras]
toml = ["tomli"]
[[package]]
name = "coverage-conditional-plugin"
version = "0.8.0"
description = "Conditional coverage based on any rules you define!"
category = "dev"
optional = false
python-versions = ">=3.7,<4.0"
files = [
{file = "coverage-conditional-plugin-0.8.0.tar.gz", hash = "sha256:e6564944a32ccc962f8c0000ac618efa5f5ff232cb9bcc677ce98546dfa61e6d"},
{file = "coverage_conditional_plugin-0.8.0-py3-none-any.whl", hash = "sha256:421079fbf9676c48397dd14254746e5e2656280b87ef83835701dd233053b9cd"},
]
[package.dependencies]
coverage = ">=5,<8"
importlib_metadata = {version = "*", markers = "python_version < \"3.10\""}
packaging = ">=20.4"
[[package]]
name = "distlib"
version = "0.3.6"
@ -1083,7 +1100,7 @@ name = "importlib-metadata"
version = "6.0.0"
description = "Read metadata from Python packages"
category = "main"
optional = true
optional = false
python-versions = ">=3.7"
files = [
{file = "importlib_metadata-6.0.0-py3-none-any.whl", hash = "sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad"},
@ -2448,7 +2465,7 @@ name = "zipp"
version = "3.15.0"
description = "Backport of pathlib-compatible object wrapper for zip files"
category = "main"
optional = true
optional = false
python-versions = ">=3.7"
files = [
{file = "zipp-3.15.0-py3-none-any.whl", hash = "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556"},
@ -2470,4 +2487,4 @@ websockets = ["websockets"]
[metadata]
lock-version = "2.0"
python-versions = "^3.8"
content-hash = "521db6409b1c3f5432b3f3eb5cdf85f7c3b199c0aac668f8a129b3b90f21d5ed"
content-hash = "6b7553642e99d6353153e941103a82f7ddcaff2b0453c8b3d8a85a3e2de41874"

View File

@ -49,6 +49,7 @@ nonebug = "^0.3.0"
pytest-cov = "^4.0.0"
pytest-xdist = "^3.0.2"
pytest-asyncio = "^0.20.0"
coverage-conditional-plugin = "^0.8.0"
[tool.poetry.group.docs.dependencies]
nb-autodoc = "^1.0.0a5"

View File

@ -1,3 +1,7 @@
[run]
plugins =
coverage_conditional_plugin
[report]
exclude_lines =
pragma: no cover
@ -10,3 +14,12 @@ exclude_lines =
\.\.\.
pass
if __name__ == .__main__.:
[coverage_conditional_plugin]
rules =
"sys_platform == 'win32'": py-win32
"sys_platform == 'linux'": py-linux
"sys_platform == 'darwin'": py-darwin
"sys_version_info >= (3, 9)": py-gte-39
"sys_version_info >= (3, 11)": py-gte-311
"sys_version_info < (3, 11)": py-lt-311