homebrew-fonts/tests/test_formula_content.py
Matt Troutman 76743cdc4d
Convert from Homebrew Formulae to Casks for font installation
Formulae can't install to ~/Library/Fonts/ due to Homebrew sandboxing.
Casks have a built-in `font` artifact that handles this automatically.

- Replace Formula/ with Casks/ directory
- Rewrite generator to produce cask files instead of formulae
- Add .ttc (TrueType Collection) support
- Update all tests for cask format
- Update CLI and documentation
- Fonts with no installable files (TTF/OTF/TTC) are skipped

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 21:38:59 -06:00

61 lines
2.3 KiB
Python

"""Tests for cask content: correct font paths and valid cask identifier."""
import re
import pytest
from tests.conftest import CASKS_DIR, FONT_FILES_DIR, get_font_dir_names
def _skip_if_no_cask(font_name):
cask_path = CASKS_DIR / f"{font_name}.rb"
if not cask_path.exists():
pytest.skip(f"No cask for {font_name} (no installable font files)")
@pytest.mark.parametrize("font_name", get_font_dir_names())
def test_cask_references_correct_font_path(font_name):
"""Generated cask contains the correct font_files/font-<name>/ path."""
_skip_if_no_cask(font_name)
cask_path = CASKS_DIR / f"{font_name}.rb"
content = cask_path.read_text()
assert f"font_files/{font_name}/" in content, (
f"{font_name}: cask does not reference font_files/{font_name}/"
)
@pytest.mark.parametrize("font_name", get_font_dir_names())
def test_cask_identifier_matches(font_name):
"""Cask declares the correct identifier matching the file name."""
_skip_if_no_cask(font_name)
cask_path = CASKS_DIR / f"{font_name}.rb"
content = cask_path.read_text()
match = re.search(r'cask\s+"([^"]+)"\s+do', content)
assert match, f"{font_name}: no 'cask \"...\" do' found"
assert match.group(1) == font_name, (
f"{font_name}: expected cask \"{font_name}\", got \"{match.group(1)}\""
)
@pytest.mark.parametrize("font_name", get_font_dir_names())
def test_cask_has_font_artifacts(font_name):
"""Cask declares at least one font artifact."""
_skip_if_no_cask(font_name)
cask_path = CASKS_DIR / f"{font_name}.rb"
content = cask_path.read_text()
font_lines = re.findall(r'^\s*font\s+"[^"]+"', content, re.MULTILINE)
assert font_lines, f"{font_name}: cask has no font artifacts"
@pytest.mark.parametrize("font_name", get_font_dir_names())
def test_cask_font_files_exist_on_disk(font_name):
"""Every font artifact declared in the cask corresponds to a real file in font_files/."""
_skip_if_no_cask(font_name)
cask_path = CASKS_DIR / f"{font_name}.rb"
content = cask_path.read_text()
# Extract paths from font "..." lines
paths = re.findall(r'^\s*font\s+"([^"]+)"', content, re.MULTILINE)
for rel_path in paths:
full_path = FONT_FILES_DIR.parent / rel_path
assert full_path.is_file(), (
f"{font_name}: font artifact references missing file: {rel_path}"
)