py-topdir.mk: Add test tree to default check roots #96

Merged
Jan Lindemann merged 3 commits from jan/feature/20260913-py-topdir-mk-add-test-tree-to-default-check-roots into master 2026-09-13 16:26:59 +02:00 AGit
Owner

$(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.

$(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.
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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
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.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
py-topdir.mk: Add test tree to default check roots
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 2m31s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 2m25s
CI / Packaging test (pull_request) Failing after 0s
c58ddda3b1
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 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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Jan Lindemann force-pushed jan/feature/20260913-py-topdir-mk-add-test-tree-to-default-check-roots from c58ddda3b1
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 2m31s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 2m25s
CI / Packaging test (pull_request) Failing after 0s
to 18f1c580f1
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m45s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m30s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m8s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m23s
CI / Packaging test (push) Successful in 0s
2026-09-13 16:16:50 +02:00
Compare
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
janware/jw-pkg!96
No description provided.