Type the fake host modules in the tests so mypy passes on them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 19:47:09 +02:00
1 parent 2ff5046993
commit 0448a34ddb
2 files changed
+9 -7

No files matched your search

+5 -5
View File
@@ -120,7 +120,7 @@ def test_the_registry_refuses_a_module_missing_a_required_name(
def test_the_contract_check_names_each_problem() -> None: def test_the_contract_check_names_each_problem() -> None:
module = types.ModuleType("odd") module: Any = types.ModuleType("odd")
module.NAME, module.LABEL, module.PATTERNS = "other", "", ("(",) module.NAME, module.LABEL, module.PATTERNS = "other", "", ("(",)
module.slug_ok = module.allowed = module.careers_url = lambda slug: "" module.slug_ok = module.allowed = module.careers_url = lambda slug: ""
module.page = lambda get, slug, cursor: None module.page = lambda get, slug, cursor: None
@@ -246,7 +246,7 @@ def _fake_host(*, detail: Callable[..., Any] | None = None,
"""A host `fake` whose feed is a JSON list of ids, each role with a """A host `fake` whose feed is a JSON list of ids, each role with a
teaser for a description, and, with `detail`, a per-role page; with teaser for a description, and, with `detail`, a per-role page; with
`robots`, its listing is the page robots.txt must allow.""" `robots`, its listing is the page robots.txt must allow."""
module = types.ModuleType("fake") module: Any = types.ModuleType("fake")
module.NAME, module.LABEL, module.PATTERNS = "fake", "Fake", () module.NAME, module.LABEL, module.PATTERNS = "fake", "Fake", ()
module.slug_ok = lambda slug: slug.isalnum() module.slug_ok = lambda slug: slug.isalnum()
module.allowed = lambda slug: lambda h: h == "jobs.fake.example" module.allowed = lambda slug: lambda h: h == "jobs.fake.example"
@@ -293,7 +293,7 @@ def web(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]:
def _run(monkeypatch: pytest.MonkeyPatch, module: types.ModuleType, def _run(monkeypatch: pytest.MonkeyPatch, module: types.ModuleType,
state: dict[str, str] | None = None) -> tuple[list[Any], dict[str, str]]: state: dict[str, str] | None = None) -> tuple[list[Any], Any]:
monkeypatch.setitem(atshosts.HOSTS, "fake", module) monkeypatch.setitem(atshosts.HOSTS, "fake", module)
source = ats.ATSSource({"boards": [{"url": "fake:acme", "label": "Acme"}], "run": "r"}) source = ats.ATSSource({"boards": [{"url": "fake:acme", "label": "Acme"}], "run": "r"})
if state is not None: if state is not None:
@@ -500,7 +500,7 @@ def test_detail_fills_only_the_fields_a_later_pull_keeps(
def _paged_host() -> types.ModuleType: def _paged_host() -> types.ModuleType:
"""A host `fake` that pages its listing, one id a page, and has `detail`.""" """A host `fake` that pages its listing, one id a page, and has `detail`."""
module = _fake_host(detail=_detail) module: Any = _fake_host(detail=_detail)
del module.feed_url, module.parse del module.feed_url, module.parse
def page(get: Any, slug: str, cursor: Any) -> tuple[Any, list[dict[str, Any]], Any, Any]: def page(get: Any, slug: str, cursor: Any) -> tuple[Any, list[dict[str, Any]], Any, Any]:
@@ -552,7 +552,7 @@ def test_a_pull_stopped_half_way_through_a_board_keeps_no_detail_ids(
web["answers"].update({f"{base}/list": b'["1", "2"]', f"{base}/1": b"one", f"{base}/2": b"two"}) web["answers"].update({f"{base}/list": b'["1", "2"]', f"{base}/1": b"one", f"{base}/2": b"two"})
monkeypatch.setitem(atshosts.HOSTS, "fake", _fake_host(detail=_detail)) monkeypatch.setitem(atshosts.HOSTS, "fake", _fake_host(detail=_detail))
source = ats.ATSSource({"boards": [{"url": "fake:acme", "label": "Acme"}], "run": "r"}) source = ats.ATSSource({"boards": [{"url": "fake:acme", "label": "Acme"}], "run": "r"})
roles = source.fetch() roles: Any = source.fetch() # a generator, which `close` stops
assert next(roles).body == "one" assert next(roles).body == "one"
roles.close() roles.close()
assert "ats:detailed:fake:acme" not in source.state assert "ats:detailed:fake:acme" not in source.state
+4 -2
View File
@@ -6,7 +6,9 @@ from __future__ import annotations
import json import json
import re import re
import types import types
from collections.abc import Set
from pathlib import Path from pathlib import Path
from typing import Any
import httpx import httpx
import pytest import pytest
@@ -83,7 +85,7 @@ def test_no_module_of_the_eight_keeps_its_case() -> None:
def test_a_host_that_gains_a_module_replaces_its_unreadable_pattern() -> None: def test_a_host_that_gains_a_module_replaces_its_unreadable_pattern() -> None:
"""Wave by wave, a host named here becomes readable by its module alone.""" """Wave by wave, a host named here becomes readable by its module alone."""
taleo = types.ModuleType("taleo") taleo: Any = types.ModuleType("taleo")
taleo.PATTERNS = (r"https?://([a-z0-9-]+)\.taleo\.net",) taleo.PATTERNS = (r"https?://([a-z0-9-]+)\.taleo\.net",)
hosts = mod._hosts({"taleo": taleo}, mod._UNREADABLE) hosts = mod._hosts({"taleo": taleo}, mod._UNREADABLE)
assert [pattern.pattern for host, pattern in hosts if host == "taleo"] == [ assert [pattern.pattern for host, pattern in hosts if host == "taleo"] == [
@@ -126,7 +128,7 @@ class Site:
is a page that did not answer. Remembers the order of fetches.""" is a page that did not answer. Remembers the order of fetches."""
def __init__(self, pages: dict[str, tuple[str, str] | str], def __init__(self, pages: dict[str, tuple[str, str] | str],
boards: set[tuple[str, str]] = frozenset()) -> None: boards: Set[tuple[str, str]] = frozenset()) -> None:
self.pages = {k: (v if isinstance(v, tuple) else (k, v)) for k, v in pages.items()} self.pages = {k: (v if isinstance(v, tuple) else (k, v)) for k, v in pages.items()}
self.boards = boards self.boards = boards
self.fetched: list[str] = [] self.fetched: list[str] = []