clipwright/tests/test_caption_presets.py
pedro-bento 83ad1feaba
All checks were successful
CI / backend-tests (pull_request) Successful in 30s
CI / frontend-build (pull_request) Successful in 29s
refactor: move backend into the clipwright package
Restructure the 37 root-level Python modules into a proper package:
  clipwright/{core,api,pipeline,layouts,media,integrations,tools}

- Rewrite every local import (module-level and deferred) to absolute
  clipwright.<group>.<mod> form; no legacy root shims or re-exports.
- Add clipwright/core/paths.py and route fonts/assets/cookies through it.
- Entry points: uvicorn clipwright.api.app:app; jobs run as
  python -m clipwright.pipeline.main; probe as -m ...quality_probe.
- child_env() appends REPO_ROOT to PYTHONPATH so the -m workers work.
- transcribe_backends: sys.modules key now clipwright.media.scene_detection.
- Tooling: root pyproject.toml (pytest pythonpath=[.], ruff), shared
  requirements-test.txt, CI installs it, Docker PYTHONPATH=/app.
- Tests: all imports/fakes/source-scans repointed; new tests/test_package_layout.py
  enforces no root modules, docstring-only __init__, and no legacy imports.
- Docs/comments updated for the new layout.

Backend: 744 passed, 19 skipped. Frontend lint+build green.
2026-10-04 20:40:38 +01:00

43 lines
1.8 KiB
Python

"""Caption presets: the API and the dashboard agree on them."""
import asyncio
import re
from clipwright.media.subtitles import AUTO_CAPTION_STYLE, CAPTION_PRESETS, line_budget
def test_dashboard_offers_every_server_preset():
src = open("dashboard/src/components/SubtitleModal.jsx").read()
ids = set(re.findall(r"\{ id: '([a-z]+)'", src))
missing = set(CAPTION_PRESETS) - ids
assert not missing, f"presets the dashboard does not offer: {missing}"
def test_default_preset_is_what_clips_ship_with():
d = CAPTION_PRESETS["default"]
for k in ("font_name", "font_size", "highlight_color", "border_width",
"effect", "uppercase", "max_chars", "max_duration"):
assert d[k] == AUTO_CAPTION_STYLE[k], k
def test_line_budget_shrinks_with_size_and_wide_fonts():
assert line_budget("Anton", 44) == 16
assert line_budget("Anton", 70) < line_budget("Anton", 44) < line_budget("Anton", 34)
assert line_budget("Montserrat ExtraBold", 44) < line_budget("Anton", 44)
def test_unknown_preset_is_a_400():
import pytest
from fastapi import HTTPException
from clipwright.api.app import SubtitleRequest, add_subtitles
with pytest.raises(HTTPException) as exc:
asyncio.run(add_subtitles(SubtitleRequest(job_id="j", clip_index=0, preset="nope"), None))
assert exc.value.status_code == 400
def test_preset_fills_only_fields_not_sent():
from clipwright.api.app import SubtitleRequest
req = SubtitleRequest(job_id="j", clip_index=0, preset="hormozi", highlight_color="#00FF00")
merged = req.model_copy(update={k: v for k, v in CAPTION_PRESETS["hormozi"].items()
if k not in req.model_fields_set})
assert merged.highlight_color == "#00FF00"
assert merged.reveal is True and merged.font_name == "Montserrat ExtraBold"