From d2e6bcfe54cc0ae5464f31465ec14fd9653662b7 Mon Sep 17 00:00:00 2001 From: Fiona Klute Date: Sun, 13 Oct 2024 00:47:25 +0200 Subject: [PATCH] Add typecheck --- nox_report.py | 2 +- noxfile.py | 8 ++++++++ test_nox_report.py | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nox_report.py b/nox_report.py index 7661d5b..141bbe4 100755 --- a/nox_report.py +++ b/nox_report.py @@ -2,7 +2,7 @@ import json -def parse_report(report_file, title): +def parse_report(report_file: str, title: str) -> None: with open(report_file, 'r') as fh: report = json.load(fh) diff --git a/noxfile.py b/noxfile.py index 2ec9079..1936168 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,3 +1,4 @@ +# mypy: disallow-untyped-defs=False, check_untyped_defs=True import nox @@ -8,6 +9,13 @@ def lint(session): session.run('flake8', '--statistics', '.') +@nox.session +def typecheck(session): + """Typecheck using MyPy.""" + session.install('mypy', 'pytest', 'nox') + session.run('mypy', '--strict', '.') + + @nox.session(python=['3.11', '3.12', '3.13']) def test(session): """Run tests.""" diff --git a/test_nox_report.py b/test_nox_report.py index 9ab4a94..731bc9c 100644 --- a/test_nox_report.py +++ b/test_nox_report.py @@ -5,11 +5,12 @@ @pytest.fixture -def sample_report(): +def sample_report() -> Path: return Path(__file__).parent / 'sample_report.json' -def test_output(capsys, sample_report): +def test_output( + capsys: pytest.CaptureFixture[str], sample_report: Path) -> None: nox_report.parse_report(str(sample_report), 'Nox test') out, _ = capsys.readouterr() assert out == textwrap.dedent(