py-topdir.mk: Add test tree to default check roots #96
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20260913-py-topdir-mk-add-test-tree-to-default-check-roots"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
$(TOPDIR)/test is currently not considered for "make check" and "make format", neither for jw-pkg nor for downstream projects. This PR enforces that by default. It fixes jw-pkg-internal fallout first, and nails it down. Every single commit should be green.
test: Fix mypy strict errors in unit tests
The unit test files below test/unit/python/jw/pkg/lib/ define Cmd and App subclasses with unannotated methods: init(), add_arguments(), _run() and close() lack signatures, the made class attribute lacks a type, and the _cleanup() and exit_context() helpers are untyped, so a strict mypy run over the test tree fails on them. Likewise, the ExecApp and version tests carry list formatting that yapf rejects.
Annotate the test classes following the library conventions: parent is App | Cmd, the parser is ArgumentParser, and args is Namespace, and mark every overridden method with @override. Guard the imports that are only used for annotations behind TYPE_CHECKING, and add the future annotations import so they stay out of the runtime path. Then reformat the test tree with yapf. That folds the opts list of the ExecApp test and re-indents the rejected operator list of the version test.
python-tools.sh: Annotate generated conftest.py
create-conftest-py generates the conftest.py that pytest test directories pick up at build time, and make clean removes it. The generated file lacks type annotations, though: pytest_configure() and the nested patched() take untyped parameters, and the replacement of .pytest_sessionstart() on the class is rejected by strict mypy.
Emit a type-annotated version instead: add a future annotations import, type both functions, move the types that are only used in annotations behind a TYPE_CHECKING guard, and silence the method replacement with a targeted type ignore.
py-topdir.mk: Add test tree to default check roots
PY_CHECK_ROOTS defaults to the src and tools directories, so the ruff, mypy, pyright, and yapf checks and the bad-pattern scan silently skip test trees. Python tests below test/ therefore escape linting, type checking, and formatting enforcement, even though py-check.mk itself defaults to the whole directory when no roots are given at all.
Add $(TOPDIR)/test to the default PY_CHECK_ROOTS after the build is through, so that the test tree receives the same checks and formatting as src and tools. The previous commit prepared this repo's unit tests for the strict type check and the formatter, so the extended roots pass cleanly here.
c58ddda3b118f1c580f1