Skip to content

Commit

Permalink
Make the test_mypy_annotate changes nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
A5rocks committed Aug 7, 2024
1 parent 72c1c68 commit 3e90307
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/trio/_tests/tools/test_mypy_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from trio._tools.mypy_annotate import Result, export, main, process_line
import trio._tools.mypy_annotate as mypy_annotate

if TYPE_CHECKING:
from pathlib import Path
Expand All @@ -19,7 +19,7 @@
("a regular line\n", None),
(
"package\\filename.py:42:8: note: Some info\n",
Result(
mypy_annotate.Result(
kind="notice",
filename="package\\filename.py",
start_line=42,
Expand All @@ -31,7 +31,7 @@
),
(
"package/filename.py:42:1:46:3: error: Type error here [code]\n",
Result(
mypy_annotate.Result(
kind="error",
filename="package/filename.py",
start_line=42,
Expand All @@ -43,7 +43,7 @@
),
(
"package/module.py:87: warn: Bad code\n",
Result(
mypy_annotate.Result(
kind="warning",
filename="package/module.py",
start_line=87,
Expand All @@ -53,14 +53,14 @@
],
ids=["blank", "normal", "note-wcol", "error-wend", "warn-lineonly"],
)
def test_processing(src: str, expected: Result | None) -> None:
result = process_line(src)
def test_processing(src: str, expected: mypy_annotate.Result | None) -> None:
result = mypy_annotate.process_line(src)
assert result == expected


def test_export(capsys: pytest.CaptureFixture[str]) -> None:
results = {
Result(
mypy_annotate.Result(
kind="notice",
filename="package\\filename.py",
start_line=42,
Expand All @@ -69,7 +69,7 @@ def test_export(capsys: pytest.CaptureFixture[str]) -> None:
end_col=None,
message=" Some info",
): ["Windows", "Mac"],
Result(
mypy_annotate.Result(
kind="error",
filename="package/filename.py",
start_line=42,
Expand All @@ -78,14 +78,14 @@ def test_export(capsys: pytest.CaptureFixture[str]) -> None:
end_col=3,
message=" Type error here [code]",
): ["Linux", "Mac"],
Result(
mypy_annotate.Result(
kind="warning",
filename="package/module.py",
start_line=87,
message=" Bad code",
): ["Linux"],
}
export(results)
mypy_annotate.export(results)
std = capsys.readouterr()
assert std.err == ""
assert std.out == (
Expand All @@ -105,7 +105,6 @@ def test_endtoend(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
import trio._tools.mypy_annotate as mypy_annotate

inp_text = """\
Mypy begun
Expand All @@ -128,7 +127,7 @@ def test_endtoend(

assert result_file.exists()

main(["--dumpfile", str(result_file)])
mypy_annotate.main(["--dumpfile", str(result_file)])

std = capsys.readouterr()
assert std.err == ""
Expand Down

0 comments on commit 3e90307

Please sign in to comment.