Skip to content

Commit b4962b3

Browse files
committed
test(docs[sphinx_fonts]): remove type: ignore comments for mypy compat
why: CI mypy fails with unused-ignore because sphinx_fonts is imported as an untyped module via sys.path, making arg-type suppression unnecessary. what: - Remove all type: ignore[arg-type] comments from test_sphinx_fonts.py
1 parent a06ea11 commit b4962b3

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

tests/docs/_ext/test_sphinx_fonts.py

Lines changed: 36 additions & 16 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

@@ -213,14 +234,14 @@ def _make_app(
213234
def test_on_builder_inited_non_html(tmp_path: pathlib.Path) -> None:
214235
"""_on_builder_inited returns early for non-HTML builders."""
215236
app = _make_app(tmp_path, builder_format="latex")
216-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
237+
sphinx_fonts._on_builder_inited(app)
217238
assert not hasattr(app, "_font_faces")
218239

219240

220241
def test_on_builder_inited_empty_fonts(tmp_path: pathlib.Path) -> None:
221242
"""_on_builder_inited returns early when no fonts configured."""
222243
app = _make_app(tmp_path, fonts=[])
223-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
244+
sphinx_fonts._on_builder_inited(app)
224245
assert not hasattr(app, "_font_faces")
225246

226247

@@ -247,7 +268,7 @@ def test_on_builder_inited_with_fonts(
247268
for weight in [400, 700]:
248269
(cache / f"open-sans-latin-{weight}-normal.woff2").write_bytes(b"data")
249270

250-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
271+
sphinx_fonts._on_builder_inited(app)
251272

252273
assert len(app._font_faces) == 2
253274
assert app._font_faces[0]["family"] == "Open Sans"
@@ -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"
@@ -283,10 +304,9 @@ def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
283304
]
284305
app = _make_app(tmp_path, fonts=fonts)
285306

286-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
307+
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(
@@ -312,7 +332,7 @@ def test_on_builder_inited_explicit_subset(
312332
cache.mkdir(parents=True)
313333
(cache / "noto-sans-latin-ext-400-normal.woff2").write_bytes(b"data")
314334

315-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
335+
sphinx_fonts._on_builder_inited(app)
316336

317337
assert app._font_faces[0]["filename"] == "noto-sans-latin-ext-400-normal.woff2"
318338

@@ -340,7 +360,7 @@ def test_on_builder_inited_preload_match(
340360
cache.mkdir(parents=True)
341361
(cache / "open-sans-latin-400-normal.woff2").write_bytes(b"data")
342362

343-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
363+
sphinx_fonts._on_builder_inited(app)
344364

345365
assert app._font_preload_hrefs == ["open-sans-latin-400-normal.woff2"]
346366

@@ -368,7 +388,7 @@ def test_on_builder_inited_preload_no_match(
368388
cache.mkdir(parents=True)
369389
(cache / "open-sans-latin-400-normal.woff2").write_bytes(b"data")
370390

371-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
391+
sphinx_fonts._on_builder_inited(app)
372392

373393
assert app._font_preload_hrefs == []
374394

@@ -397,7 +417,7 @@ def test_on_builder_inited_fallbacks_and_variables(
397417
cache.mkdir(parents=True)
398418
(cache / "inter-latin-400-normal.woff2").write_bytes(b"data")
399419

400-
sphinx_fonts._on_builder_inited(app) # type: ignore[arg-type]
420+
sphinx_fonts._on_builder_inited(app)
401421

402422
assert app._font_fallbacks == fallbacks
403423
assert app._font_css_variables == variables
@@ -428,7 +448,7 @@ def test_on_html_page_context_with_attrs() -> None:
428448
"index",
429449
"page.html",
430450
context,
431-
None, # type: ignore[arg-type]
451+
None,
432452
)
433453

434454
assert context["font_preload_hrefs"] == ["font-400.woff2"]
@@ -447,7 +467,7 @@ def test_on_html_page_context_without_attrs() -> None:
447467
"index",
448468
"page.html",
449469
context,
450-
None, # type: ignore[arg-type]
470+
None,
451471
)
452472

453473
assert context["font_preload_hrefs"] == []
@@ -471,7 +491,7 @@ def test_setup_return_value() -> None:
471491
connect=lambda event, handler: connections.append((event, handler)),
472492
)
473493

474-
result = sphinx_fonts.setup(app) # type: ignore[arg-type]
494+
result = sphinx_fonts.setup(app)
475495

476496
assert result == {
477497
"version": "1.0",
@@ -492,7 +512,7 @@ def test_setup_config_values() -> None:
492512
connect=lambda event, handler: connections.append((event, handler)),
493513
)
494514

495-
sphinx_fonts.setup(app) # type: ignore[arg-type]
515+
sphinx_fonts.setup(app)
496516

497517
config_names = [c[0] for c in config_values]
498518
assert "sphinx_fonts" in config_names
@@ -514,7 +534,7 @@ def test_setup_event_connections() -> None:
514534
connect=lambda event, handler: connections.append((event, handler)),
515535
)
516536

517-
sphinx_fonts.setup(app) # type: ignore[arg-type]
537+
sphinx_fonts.setup(app)
518538

519539
event_names = [c[0] for c in connections]
520540
assert "builder-inited" in event_names

0 commit comments

Comments
 (0)