[chore] clear all 64 pre-existing mypy errors in tests/ (no type:ignore)

Convention: no type:ignore/noqa, and pre-existing violations still
violate. The make-quality gate runs 'mypy roboco/ tests/', but the
prior commits' gates only ran mypy on production files, masking 64
type errors across 15 test files (method-assign, unused-ignore,
no-untyped-def, attr-defined, union-attr, has-type, index, misc).

Fixed without any type:ignore:
- method-assign (svc.session.X = / svc.method = AsyncMock()): hold a
  local 'session: MagicMock'/'AsyncMock' and assert on it, or stub via
  object.__setattr__ / monkeypatch / a typed '_bind' helper returning
  Any, or alias 'cc: Any = c' (the pattern the file already used).
- unused 'type: ignore[assignment]' (real code was method-assign):
  removed; replaced with the no-suppression patterns above.
- 'Callable[...] has no attribute assert_*': keep a typed local ref to
  the AsyncMock and assert on the local, not the method-typed attr.
- no-untyped-def: annotate helper params (Any / pytest.MonkeyPatch).
- attr-defined / index / union-attr: type the helper as Any, narrow
  with an 'is not None' assert, or add the missing attr to a fake.
- has-type / return-value: fix the declared return type to the tuple
  the function actually returns.
- PLC0415 inline imports: hoisted to top-level.

test_pr_gate_notifies_pm._stub_gate_path converted fully to the
'cc: Any = c' alias (it already used it for one attr) so its five
'# type: ignore[method-assign]' suppressions are gone.

mypy tests/: 64 errors -> 0 (538 files). ruff check tests/: clean.
All 84 tests in the touched files pass.
This commit is contained in:
Renn F
2026-06-28 16:47:09 +02:00
parent 54fc69c499
commit 4d4bf084c5
16 changed files with 124 additions and 75 deletions
+5 -2
View File
@@ -14,6 +14,7 @@ public step the caller runs AFTER committing. Both helpers stay gated on
from __future__ import annotations
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from uuid import uuid4
@@ -23,7 +24,9 @@ from roboco.models.base import PlaybookStatus
from roboco.services.playbook import PlaybookService
def _mock_playbook(playbook_id, *, status=PlaybookStatus.APPROVED.value):
def _mock_playbook(
playbook_id: Any, *, status: str = PlaybookStatus.APPROVED.value
) -> MagicMock:
pb = MagicMock()
pb.id = playbook_id
pb.status = status
@@ -36,7 +39,7 @@ def _mock_playbook(playbook_id, *, status=PlaybookStatus.APPROVED.value):
return pb
def _session_with(pb) -> MagicMock:
def _session_with(pb: Any) -> MagicMock:
session = MagicMock()
result = MagicMock()
result.scalar_one_or_none.return_value = pb