Skip to content

Commit e2afa39

Browse files
committed
test(docs[sphinx_fonts]): fix ruff lint errors in test_sphinx_fonts
why: CI ruff check fails on EM101 (string literal in exception), TRY003 (long exception message), and D403 (uncapitalized docstring). what: - Extract exception messages to variables for EM101/TRY003 - Capitalize docstrings starting with "setup" for D403
1 parent 745caca commit e2afa39

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/docs/_ext/test_sphinx_fonts.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ def test_download_font_url_error(
145145
"""_download_font returns False and warns on URLError."""
146146
dest = tmp_path / "font.woff2"
147147

148+
msg = "network error"
149+
148150
def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
149-
raise urllib.error.URLError("network error")
151+
raise urllib.error.URLError(msg)
150152

151153
monkeypatch.setattr("sphinx_fonts.urllib.request.urlretrieve", fake_urlretrieve)
152154

@@ -166,8 +168,10 @@ def test_download_font_os_error(
166168
"""_download_font returns False and warns on OSError."""
167169
dest = tmp_path / "font.woff2"
168170

171+
msg = "disk full"
172+
169173
def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
170-
raise OSError("disk full")
174+
raise OSError(msg)
171175

172176
monkeypatch.setattr("sphinx_fonts.urllib.request.urlretrieve", fake_urlretrieve)
173177

@@ -261,8 +265,10 @@ def test_on_builder_inited_download_failure(
261265
"""_on_builder_inited still builds font_faces entry on download failure."""
262266
monkeypatch.setattr("sphinx_fonts._cache_dir", lambda: tmp_path / "cache")
263267

268+
msg = "offline"
269+
264270
def fake_urlretrieve(url: str, filename: t.Any) -> t.NoReturn:
265-
raise urllib.error.URLError("offline")
271+
raise urllib.error.URLError(msg)
266272

267273
monkeypatch.setattr("sphinx_fonts.urllib.request.urlretrieve", fake_urlretrieve)
268274

@@ -446,7 +452,7 @@ def test_on_html_page_context_without_attrs() -> None:
446452

447453

448454
def test_setup_return_value() -> None:
449-
"""setup returns correct metadata dict."""
455+
"""Verify setup() returns correct metadata dict."""
450456
config_values: list[tuple[str, t.Any, str]] = []
451457
connections: list[tuple[str, t.Any]] = []
452458

@@ -467,7 +473,7 @@ def test_setup_return_value() -> None:
467473

468474

469475
def test_setup_config_values() -> None:
470-
"""setup registers all expected config values."""
476+
"""Verify setup() registers all expected config values."""
471477
config_values: list[tuple[str, t.Any, str]] = []
472478
connections: list[tuple[str, t.Any]] = []
473479

@@ -489,7 +495,7 @@ def test_setup_config_values() -> None:
489495

490496

491497
def test_setup_event_connections() -> None:
492-
"""setup connects to builder-inited and html-page-context events."""
498+
"""Verify setup() connects to builder-inited and html-page-context events."""
493499
config_values: list[tuple[str, t.Any, str]] = []
494500
connections: list[tuple[str, t.Any]] = []
495501

0 commit comments

Comments
 (0)