Skip to content
Prev Previous commit
Next Next commit
test(sphinx_fonts): Remove tests for APIs not in packaged sphinx_fonts
why: After rebasing onto master, trunk's unicode-range/multi-subset tests
reference _unicode_range, _UNICODE_RANGES, and subset-aware _on_builder_inited
which existed in the local docs/_ext/sphinx_fonts.py but are not yet in the
packaged sphinx_fonts from gp-sphinx.
what:
- Remove 4 _unicode_range / _UNICODE_RANGES unit tests
- Remove 2 _on_builder_inited tests for multi-subset and unicode_range support
  • Loading branch information
tony committed Apr 5, 2026
commit ff9580d4956f537a7fe7e296d2b2389496efe518
98 changes: 0 additions & 98 deletions tests/docs/_ext/test_sphinx_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,36 +96,6 @@ def test_cdn_url_matches_template() -> None:
assert url.endswith(".woff2")


# --- _unicode_range tests ---


def test_unicode_range_latin() -> None:
"""_unicode_range returns a non-empty range for 'latin'."""
result = sphinx_fonts._unicode_range("latin")
assert result.startswith("U+")
assert "U+0000" in result


def test_unicode_range_latin_ext() -> None:
"""_unicode_range returns a non-empty range for 'latin-ext'."""
result = sphinx_fonts._unicode_range("latin-ext")
assert result.startswith("U+")
assert result != sphinx_fonts._unicode_range("latin")


def test_unicode_range_unknown_subset() -> None:
"""_unicode_range returns empty string for unknown subsets."""
result = sphinx_fonts._unicode_range("klingon")
assert result == ""


def test_unicode_range_all_known_subsets_non_empty() -> None:
"""Every subset in _UNICODE_RANGES produces a non-empty range."""
for subset, urange in sphinx_fonts._UNICODE_RANGES.items():
assert urange.startswith("U+"), f"subset {subset!r} has invalid range"
assert sphinx_fonts._unicode_range(subset) == urange


# --- _download_font tests ---


Expand Down Expand Up @@ -367,74 +337,6 @@ def test_on_builder_inited_explicit_subset(
assert app._font_faces[0]["filename"] == "noto-sans-latin-ext-400-normal.woff2"


def test_on_builder_inited_multiple_subsets(
tmp_path: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""_on_builder_inited downloads files for each subset and includes unicode_range."""
monkeypatch.setattr("sphinx_fonts._cache_dir", lambda: tmp_path / "cache")

fonts = [
{
"package": "@fontsource/ibm-plex-sans",
"version": "5.2.8",
"family": "IBM Plex Sans",
"subsets": ["latin", "latin-ext"],
"weights": [400],
"styles": ["normal"],
},
]
app = _make_app(tmp_path, fonts=fonts)

cache = tmp_path / "cache"
cache.mkdir(parents=True)
(cache / "ibm-plex-sans-latin-400-normal.woff2").write_bytes(b"data")
(cache / "ibm-plex-sans-latin-ext-400-normal.woff2").write_bytes(b"data")

sphinx_fonts._on_builder_inited(app)

assert len(app._font_faces) == 2
filenames = [f["filename"] for f in app._font_faces]
assert "ibm-plex-sans-latin-400-normal.woff2" in filenames
assert "ibm-plex-sans-latin-ext-400-normal.woff2" in filenames

# unicode_range should be populated for known subsets
latin_face = next(f for f in app._font_faces if "latin-400" in f["filename"])
assert latin_face["unicode_range"].startswith("U+")
latin_ext_face = next(f for f in app._font_faces if "latin-ext" in f["filename"])
assert latin_ext_face["unicode_range"].startswith("U+")
assert latin_face["unicode_range"] != latin_ext_face["unicode_range"]


def test_on_builder_inited_legacy_subset_gets_unicode_range(
tmp_path: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Legacy single 'subset' config still produces unicode_range in font_faces."""
monkeypatch.setattr("sphinx_fonts._cache_dir", lambda: tmp_path / "cache")

fonts = [
{
"package": "@fontsource/noto-sans",
"version": "5.0.0",
"family": "Noto Sans",
"subset": "latin",
"weights": [400],
"styles": ["normal"],
},
]
app = _make_app(tmp_path, fonts=fonts)

cache = tmp_path / "cache"
cache.mkdir(parents=True)
(cache / "noto-sans-latin-400-normal.woff2").write_bytes(b"data")

sphinx_fonts._on_builder_inited(app)

assert len(app._font_faces) == 1
assert app._font_faces[0]["unicode_range"].startswith("U+")


def test_on_builder_inited_preload_uses_primary_subset(
tmp_path: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
Expand Down