Skip to content

test(docs[sphinx_fonts]): add tests for sphinx_fonts extension#1023

Merged
tony merged 7 commits into
masterfrom
docs-fonts-tests
Mar 14, 2026
Merged

test(docs[sphinx_fonts]): add tests for sphinx_fonts extension#1023
tony merged 7 commits into
masterfrom
docs-fonts-tests

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented Mar 14, 2026

Summary

  • Add 21 tests covering all functions in docs/_ext/sphinx_fonts.py
  • Add docstrings to sphinx_fonts extension for ruff D101/D103 compliance
  • Tests use SimpleNamespace stubs and monkeypatch for I/O isolation

Test coverage

Area Tests
_cache_dir() 1
_cdn_url() 3
_download_font() 4 (cached, success, URLError, OSError)
_on_builder_inited() 7 (non-html, empty, fonts, failure, subset, preload, fallbacks)
_on_html_page_context() 2 (with/without attrs)
setup() 4 (return value, config values, event connections, full roundtrip)

Commits

  • docs(fonts[lint]): add docstrings to sphinx_fonts extension
  • test(docs[sphinx_fonts]): add tests for sphinx_fonts extension
  • test(docs[sphinx_fonts]): fix ruff lint errors
  • test(docs[sphinx_fonts]): apply ruff format
  • test(docs[sphinx_fonts]): remove type: ignore comments for mypy compat

tony added 5 commits March 14, 2026 07:01
why: ruff D101/D103 rules flag missing docstrings on SetupDict
and setup(), causing CI lint failures in repos that lint docs/_ext/.
what:
- Add docstring to SetupDict TypedDict class
- Add docstring to setup() function
why: codecov drops because docs/_ext/sphinx_fonts.py is measured
for coverage but has zero tests across all repos.
what:
- Add test_sphinx_fonts.py with 21 tests covering all functions
- Test pure functions, I/O with monkeypatch, Sphinx events with SimpleNamespace
- Cover all branches: cached/success/URLError/OSError, html/non-html, empty/with 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
why: CI ruff format check fails on multi-line function call formatting.
what:
- Apply ruff format to test_sphinx_fonts.py
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
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.01%. Comparing base (9c0caa1) to head (d0f7dde).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1023   +/-   ##
=======================================
  Coverage   81.01%   81.01%           
=======================================
  Files          28       28           
  Lines        2628     2628           
  Branches      492      492           
=======================================
  Hits         2129     2129           
  Misses        368      368           
  Partials      131      131           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
Copy link
Copy Markdown
Member Author

tony commented Mar 14, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

tony added 2 commits March 14, 2026 13:06
why: font_faces.append() ran unconditionally, emitting @font-face CSS
rules pointing to missing files when download failed (browser 404s).
what:
- Move font_faces.append() inside the if _download_font() block
- Update test to expect 0 entries on download failure
why: urlretrieve can leave partial .woff2 on OSError mid-transfer,
poisoning the cache and delivering corrupt fonts on subsequent builds.
what:
- Add dest.unlink() in except block to remove partial files
- Add test for partial file cleanup behavior
@tony tony force-pushed the docs-fonts-tests branch from 6c74173 to d0f7dde Compare March 14, 2026 18:45
@tony tony merged commit b850021 into master Mar 14, 2026
13 checks passed
@tony tony deleted the docs-fonts-tests branch March 14, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant