Skip to content

Commit 895c550

Browse files
authored
add coverage-conditional, rejig some config stuff (#356)
* add coverage-conditional, rejig some config stuff * add back pytest-cov
1 parent c512a1f commit 895c550

File tree

7 files changed

+62
-36
lines changed

7 files changed

+62
-36
lines changed

flake8_async/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(
138138
self.module: cst.Module = cst_parse_module_native(source)
139139

140140
@classmethod
141-
def from_filename(cls, filename: str | PathLike[str]) -> Plugin: # pragma: no cover
141+
def from_filename(cls, filename: str | PathLike[str]) -> Plugin:
142142
# only used with --runslow
143143
with tokenize.open(filename) as f:
144144
source = f.read()
@@ -204,7 +204,7 @@ def add_options(option_manager: OptionManager | ArgumentParser):
204204
'lines with "# noqa" at the end.'
205205
),
206206
)
207-
else: # if run as a flake8 plugin
207+
else: # pragma: no-cov-no-flake8
208208
Plugin.standalone = False
209209
# Disable ASYNC9xx calls by default
210210
option_manager.extend_default_ignore(default_disabled_error_codes)
@@ -380,7 +380,7 @@ def get_matching_codes(
380380
}
381381
assert all_codes
382382

383-
if options.autofix and not Plugin.standalone:
383+
if options.autofix and not Plugin.standalone: # pragma: no-cov-no-flake8
384384
print("Cannot autofix when run as a flake8 plugin.", file=sys.stderr)
385385
sys.exit(1)
386386
autofix_codes = set(get_matching_codes(options.autofix, all_codes))
@@ -457,6 +457,7 @@ def parse_async200_dict(raw_value: str) -> dict[str, str]:
457457

458458

459459
# not run if flake8 is installed
460+
# TODO: this is not tested at all atm, I'm not even sure if it works
460461
def parse_per_file_disable( # pragma: no cover
461462
raw_value: str,
462463
) -> dict[str, tuple[str, ...]]:

flake8_async/visitors/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def with_has_call(
371371
372372
"""
373373
if isinstance(base, str):
374-
base = (base,) # pragma: no cover
374+
base = (base,)
375375

376376
# build matcher, using SaveMatchedNode to save the base and the function name.
377377
matcher = m.Call(

flake8_async/visitors/visitor123.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def visit_ExceptHandler(self, node: ast.ExceptHandler):
7878
self.exception_group_names = {node.name}
7979

8080
# ast.TryStar added in py311
81-
# we run strict codecov on all python versions, this one doesn't run on <py311
82-
def visit_TryStar(self, node: ast.TryStar): # type: ignore[name-defined] # pragma: no cover
81+
def visit_TryStar(self, node: ast.TryStar): # type: ignore[name-defined] # pragma: no-cov-py-lt-311
8382
self.save_state(node, "try_star", copy=False)
8483
self.try_star = True
8584

flake8_async/visitors/visitor91x.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def __init__(self, *args: Any, **kwargs: Any):
386386
self.new_body: cst.BaseSuite | None = None
387387

388388
def should_autofix(self, node: cst.CSTNode, code: str | None = None) -> bool:
389-
if code is None: # pragma: no branch
389+
if code is None:
390390
code = "ASYNC911" if self.has_yield else "ASYNC910"
391391

392392
return (

pyproject.toml

+32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ force-exclude = "tests/autofix_files/.*.py"
1414
[tool.codespell]
1515
ignore-words-list = 'spawnve'
1616

17+
[tool.coverage.coverage_conditional_plugin.rules]
18+
no-cov-has-flake8 = "is_installed('flake8')"
19+
no-cov-no-flake8 = "not is_installed('flake8')"
20+
no-cov-py-lt-311 = "sys.version_info < (3, 11)"
21+
22+
[tool.coverage.paths]
23+
source = [
24+
"flake8_async",
25+
"*/site-packages/flake8_async"
26+
]
27+
28+
[tool.coverage.report]
29+
exclude_lines = [
30+
# Have to re-enable the standard pragma
31+
"pragma: no cover",
32+
# Don't complain about abstract methods, they aren't run:
33+
"@(abc\\.)?abstractmethod",
34+
# Don't check guarded type imports
35+
"if (typing.)?TYPE_CHECKING:"
36+
]
37+
fail_under = 100
38+
skip_covered = true
39+
skip_empty = true
40+
41+
[tool.coverage.run]
42+
branch = true
43+
plugins = ["coverage_conditional_plugin"]
44+
1745
[tool.isort]
1846
only_modified = true
1947
profile = "black"
@@ -45,6 +73,10 @@ reportUnnecessaryTypeIgnoreComment = false
4573
reportUnusedCallResult = false
4674
strict = ["*.py", "tests/*.py", "flake8_async/**/*.py"]
4775

76+
[tool.pytest.ini_options]
77+
filterwarnings = ["error"]
78+
testpaths = ["tests"]
79+
4880
[tool.ruff]
4981
extend-exclude = [
5082
".*",

tests/test_config_and_args.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ def test_async200_from_config_subprocess(tmp_path: Path):
282282
assert res.stdout == err_msg.encode("ascii")
283283

284284

285+
def test_trio200_warning(tmp_path: Path):
286+
fpath = tmp_path / "foo.py"
287+
fpath.touch()
288+
res = subprocess.run(
289+
["flake8-async", "--trio200-blocking-calls=foo->bar", "foo.py"],
290+
cwd=tmp_path,
291+
capture_output=True,
292+
check=False,
293+
encoding="utf8",
294+
)
295+
assert res.returncode == 0
296+
assert res.stderr.endswith(
297+
"UserWarning: trio200-blocking-calls has been deprecated in favor of "
298+
"async200-blocking-calls\n warnings.warn(\n"
299+
)
300+
assert not res.stdout
301+
302+
285303
@pytest.mark.skipif(flake8 is None, reason="flake8 is not installed")
286304
def test_async200_from_config_subprocess_cli_ignore(tmp_path: Path):
287305
_ = _test_async200_from_config_common(tmp_path)
@@ -297,7 +315,7 @@ def test_async200_from_config_subprocess_cli_ignore(tmp_path: Path):
297315
assert res.returncode == 0
298316

299317

300-
def test_900_default_off(capsys: pytest.CaptureFixture[str]):
318+
def test_900_default_off():
301319
res = subprocess.run(
302320
["flake8-async", "tests/eval_files/async900.py"],
303321
capture_output=True,

tox.ini

+4-28
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ deps =
1111
flake8_7: flake8>=7.0
1212
flake8_6: flake8>=6.0, <7.0
1313
pytest
14-
pytest-cov
14+
pytest-cov # to make it easy to pass --no-cov
15+
coverage
16+
coverage-conditional-plugin
1517
pytest-xdist
1618
hypothesis
1719
# 0.3.3 adds py313 support
1820
hypothesmith >= 0.3.3
1921
trio
2022
commands =
21-
pytest {posargs:-n auto}
23+
coverage run -m pytest {posargs:-n auto}
2224

2325
[testenv:docs]
2426
description = Generate docs locally
@@ -32,29 +34,3 @@ skip_install = True
3234
commands =
3335
make clean
3436
make html
35-
36-
# Settings for other tools
37-
[pytest]
38-
addopts =
39-
--cov=flake8_async
40-
--cov-branch
41-
--cov-report=term-missing:skip-covered
42-
--cov-fail-under=100
43-
filterwarnings =
44-
error
45-
46-
[coverage:paths]
47-
source =
48-
flake8_async
49-
*/site-packages/flake8_async
50-
51-
[coverage:report]
52-
exclude_lines =
53-
# Have to re-enable the standard pragma
54-
pragma: no cover
55-
56-
# Don't complain about abstract methods, they aren't run:
57-
@(abc\.)?abstractmethod
58-
59-
# Don't check guarded type imports
60-
if (typing.)?TYPE_CHECKING:

0 commit comments

Comments
 (0)