Skip to content

Commit 8def325

Browse files
committed
pyproject(mypy): add sphinx_fonts to ignore_missing_imports
why: sphinx_fonts is a local docs/_ext extension, not an installed package — mypy cannot resolve it at analysis time. what: - Add sphinx_fonts to [[tool.mypy.overrides]] ignore_missing_imports - Add targeted arg-type disable for test_sphinx_fonts (SimpleNamespace stubs)
1 parent 2f458a7 commit 8def325

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ files = [
135135
"tests",
136136
]
137137

138+
[[tool.mypy.overrides]]
139+
module = ["sphinx_fonts"]
140+
ignore_missing_imports = true
141+
142+
[[tool.mypy.overrides]]
143+
module = ["tests.docs._ext.test_sphinx_fonts"]
144+
disable_error_code = ["arg-type"]
145+
138146
[tool.coverage.run]
139147
branch = true
140148
parallel = true

tests/docs/_ext/test_sphinx_fonts.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
183183
assert any("failed" in r.message for r in warning_records)
184184

185185

186+
def test_download_font_partial_file_cleanup(
187+
tmp_path: pathlib.Path,
188+
monkeypatch: pytest.MonkeyPatch,
189+
) -> None:
190+
"""_download_font removes partial file on failure."""
191+
dest = tmp_path / "cache" / "partial.woff2"
192+
193+
msg = "disk full"
194+
195+
def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
196+
pathlib.Path(filename).write_bytes(b"partial")
197+
raise OSError(msg)
198+
199+
monkeypatch.setattr("sphinx_fonts.urllib.request.urlretrieve", fake_urlretrieve)
200+
201+
result = sphinx_fonts._download_font("https://example.com/font.woff2", dest)
202+
203+
assert result is False
204+
assert not dest.exists()
205+
206+
186207
# --- _on_builder_inited tests ---
187208

188209

@@ -262,7 +283,7 @@ def test_on_builder_inited_download_failure(
262283
tmp_path: pathlib.Path,
263284
monkeypatch: pytest.MonkeyPatch,
264285
) -> None:
265-
"""_on_builder_inited still builds font_faces entry on download failure."""
286+
"""_on_builder_inited skips font_faces entry on download failure."""
266287
monkeypatch.setattr("sphinx_fonts._cache_dir", lambda: tmp_path / "cache")
267288

268289
msg = "offline"
@@ -285,8 +306,7 @@ def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
285306

286307
sphinx_fonts._on_builder_inited(app)
287308

288-
assert len(app._font_faces) == 1
289-
assert app._font_faces[0]["family"] == "Inter"
309+
assert len(app._font_faces) == 0
290310

291311

292312
def test_on_builder_inited_explicit_subset(

0 commit comments

Comments
 (0)