Skip to content

Commit 9ce7039

Browse files
authored
various fixes to config tests (#318)
1 parent 63c2e81 commit 9ce7039

1 file changed

Lines changed: 83 additions & 5 deletions

File tree

tests/test_config_and_args.py

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_200_from_config_subprocess(tmp_path: Path):
262262
assert res.stdout == err_msg.encode("ascii")
263263

264264

265-
def test_trio200_from_config_subprocess(tmp_path: Path):
265+
def test_async200_from_config_subprocess(tmp_path: Path):
266266
err_msg = _test_async200_from_config_common(tmp_path, code="trio200")
267267
res = subprocess.run(["flake8"], cwd=tmp_path, capture_output=True, check=False)
268268
assert res.returncode == 1
@@ -273,20 +273,55 @@ def test_trio200_from_config_subprocess(tmp_path: Path):
273273
assert res.stdout == err_msg.encode("ascii")
274274

275275

276+
def test_async200_from_config_subprocess_cli_ignore(tmp_path: Path):
277+
_ = _test_async200_from_config_common(tmp_path)
278+
res = subprocess.run(
279+
["flake8", "--ignore=ASYNC200"],
280+
cwd=tmp_path,
281+
capture_output=True,
282+
check=False,
283+
encoding="utf8",
284+
)
285+
assert not res.stderr
286+
assert not res.stdout
287+
assert res.returncode == 0
288+
289+
276290
def test_900_default_off(capsys: pytest.CaptureFixture[str]):
277291
from flake8.main.cli import main
278292

279293
returnvalue = main(
280294
argv=[
281-
"tests/trio900.py",
295+
"tests/eval_files/async900.py",
282296
]
283297
)
284298
out, err = capsys.readouterr()
285299
assert returnvalue == 1
286300
assert not err
301+
assert "E501" in out
287302
assert "ASYNC900" not in out
288303

289304

305+
def test_910_can_be_selected(tmp_path: Path):
306+
myfile = tmp_path.joinpath("foo.py")
307+
myfile.write_text("""async def foo():\n print()""")
308+
309+
res = subprocess.run(
310+
["flake8", "--select=ASYNC910", "foo.py"],
311+
cwd=tmp_path,
312+
capture_output=True,
313+
check=False,
314+
encoding="utf8",
315+
)
316+
317+
assert not res.stderr
318+
assert res.stdout == (
319+
"foo.py:1:1: ASYNC910 exit from async function with no guaranteed"
320+
" checkpoint or exception since function definition on line 1.\n"
321+
)
322+
assert res.returncode == 1
323+
324+
290325
def test_enable(
291326
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
292327
):
@@ -418,12 +453,12 @@ def test_disable_noqa_ast(
418453
)
419454

420455

421-
@pytest.mark.xfail(reason="flake8>=6 enforces three-letter error codes in config")
422-
def test_config_ignore_error_code(tmp_path: Path) -> None:
456+
def test_config_select_error_code(tmp_path: Path) -> None:
423457
assert tmp_path.joinpath(".flake8").write_text(
424458
"""
425459
[flake8]
426-
ignore = ASYNC100
460+
select = ASYNC100
461+
extend-select = ASYNC100
427462
"""
428463
)
429464
res = subprocess.run(
@@ -433,6 +468,49 @@ def test_config_ignore_error_code(tmp_path: Path) -> None:
433468
assert res.returncode == 0
434469

435470

471+
# flake8>=6 enforces three-letter error codes in config
472+
def test_config_ignore_error_code(tmp_path: Path) -> None:
473+
assert tmp_path.joinpath(".flake8").write_text(
474+
"""
475+
[flake8]
476+
ignore = ASYNC100
477+
"""
478+
)
479+
res = subprocess.run(
480+
["flake8", "--help"],
481+
cwd=tmp_path,
482+
capture_output=True,
483+
check=False,
484+
encoding="utf8",
485+
)
486+
assert (
487+
"Error code 'ASYNC100' supplied to 'ignore' option does not match" in res.stderr
488+
)
489+
assert res.returncode == 1
490+
491+
492+
# flake8>=6 enforces three-letter error codes in config
493+
def test_config_extend_ignore_error_code(tmp_path: Path) -> None:
494+
assert tmp_path.joinpath(".flake8").write_text(
495+
"""
496+
[flake8]
497+
extend-ignore = ASYNC100
498+
"""
499+
)
500+
res = subprocess.run(
501+
["flake8", "--help"],
502+
cwd=tmp_path,
503+
capture_output=True,
504+
check=False,
505+
encoding="utf8",
506+
)
507+
assert (
508+
"Error code 'ASYNC100' supplied to 'extend-ignore' option does not match"
509+
in res.stderr
510+
)
511+
assert res.returncode == 1
512+
513+
436514
# but make sure we can disable selected codes
437515
def test_config_disable_error_code(tmp_path: Path) -> None:
438516
# select ASYNC200 and create file that induces ASYNC200

0 commit comments

Comments
 (0)