Skip to content

Commit

Permalink
various fixes to config tests (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl authored Nov 15, 2024
1 parent 63c2e81 commit 9ce7039
Showing 1 changed file with 83 additions and 5 deletions.
88 changes: 83 additions & 5 deletions tests/test_config_and_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_200_from_config_subprocess(tmp_path: Path):
assert res.stdout == err_msg.encode("ascii")


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


def test_async200_from_config_subprocess_cli_ignore(tmp_path: Path):
_ = _test_async200_from_config_common(tmp_path)
res = subprocess.run(
["flake8", "--ignore=ASYNC200"],
cwd=tmp_path,
capture_output=True,
check=False,
encoding="utf8",
)
assert not res.stderr
assert not res.stdout
assert res.returncode == 0


def test_900_default_off(capsys: pytest.CaptureFixture[str]):
from flake8.main.cli import main

returnvalue = main(
argv=[
"tests/trio900.py",
"tests/eval_files/async900.py",
]
)
out, err = capsys.readouterr()
assert returnvalue == 1
assert not err
assert "E501" in out
assert "ASYNC900" not in out


def test_910_can_be_selected(tmp_path: Path):
myfile = tmp_path.joinpath("foo.py")
myfile.write_text("""async def foo():\n print()""")

res = subprocess.run(
["flake8", "--select=ASYNC910", "foo.py"],
cwd=tmp_path,
capture_output=True,
check=False,
encoding="utf8",
)

assert not res.stderr
assert res.stdout == (
"foo.py:1:1: ASYNC910 exit from async function with no guaranteed"
" checkpoint or exception since function definition on line 1.\n"
)
assert res.returncode == 1


def test_enable(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
):
Expand Down Expand Up @@ -418,12 +453,12 @@ def test_disable_noqa_ast(
)


@pytest.mark.xfail(reason="flake8>=6 enforces three-letter error codes in config")
def test_config_ignore_error_code(tmp_path: Path) -> None:
def test_config_select_error_code(tmp_path: Path) -> None:
assert tmp_path.joinpath(".flake8").write_text(
"""
[flake8]
ignore = ASYNC100
select = ASYNC100
extend-select = ASYNC100
"""
)
res = subprocess.run(
Expand All @@ -433,6 +468,49 @@ def test_config_ignore_error_code(tmp_path: Path) -> None:
assert res.returncode == 0


# flake8>=6 enforces three-letter error codes in config
def test_config_ignore_error_code(tmp_path: Path) -> None:
assert tmp_path.joinpath(".flake8").write_text(
"""
[flake8]
ignore = ASYNC100
"""
)
res = subprocess.run(
["flake8", "--help"],
cwd=tmp_path,
capture_output=True,
check=False,
encoding="utf8",
)
assert (
"Error code 'ASYNC100' supplied to 'ignore' option does not match" in res.stderr
)
assert res.returncode == 1


# flake8>=6 enforces three-letter error codes in config
def test_config_extend_ignore_error_code(tmp_path: Path) -> None:
assert tmp_path.joinpath(".flake8").write_text(
"""
[flake8]
extend-ignore = ASYNC100
"""
)
res = subprocess.run(
["flake8", "--help"],
cwd=tmp_path,
capture_output=True,
check=False,
encoding="utf8",
)
assert (
"Error code 'ASYNC100' supplied to 'extend-ignore' option does not match"
in res.stderr
)
assert res.returncode == 1


# but make sure we can disable selected codes
def test_config_disable_error_code(tmp_path: Path) -> None:
# select ASYNC200 and create file that induces ASYNC200
Expand Down

0 comments on commit 9ce7039

Please sign in to comment.