generated from john/python-template
WIP theming
This commit is contained in:
+2
-2
@@ -27,7 +27,7 @@ class TestAppLifespan:
|
||||
"""Startup initializes logging, schema, directories, and worker resources."""
|
||||
calls = []
|
||||
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda: calls.append("logging"))
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda _settings: calls.append("logging"))
|
||||
|
||||
async def _create_all(**_kwargs):
|
||||
calls.append("schema")
|
||||
@@ -80,7 +80,7 @@ class TestAppLifespan:
|
||||
"""Shutdown signals and stops worker resources cleanly."""
|
||||
calls = []
|
||||
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda: calls.append("logging"))
|
||||
monkeypatch.setattr("transcription.app.configure_logging", lambda _settings: calls.append("logging"))
|
||||
|
||||
async def _create_all(**_kwargs):
|
||||
calls.append("schema")
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import ValidationError
|
||||
|
||||
from transcription.config import Provider
|
||||
from transcription.config import Settings
|
||||
from transcription.config import parse_cli_settings
|
||||
|
||||
|
||||
def _make_settings(**overrides) -> Settings:
|
||||
@@ -31,6 +32,30 @@ class TestSettingsLoading:
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(_env_file=None)
|
||||
|
||||
def test_ignores_process_cli_arguments(self, monkeypatch):
|
||||
"""Ordinary settings construction does not consume tooling arguments."""
|
||||
monkeypatch.setattr("sys.argv", ["pytest", "--rootdir=/tmp/project"])
|
||||
|
||||
settings = _make_settings()
|
||||
|
||||
assert settings.port == 8000
|
||||
|
||||
def test_explicit_cli_parser_reads_arguments(self):
|
||||
"""The executable settings boundary accepts application CLI flags."""
|
||||
settings = parse_cli_settings(
|
||||
[
|
||||
"--openrouter-api-key",
|
||||
"test-key",
|
||||
"--port",
|
||||
"8123",
|
||||
"--reload",
|
||||
]
|
||||
)
|
||||
|
||||
assert settings.openrouter_api_key == "test-key"
|
||||
assert settings.port == 8123
|
||||
assert settings.reload is True
|
||||
|
||||
|
||||
class TestProviderSettings:
|
||||
"""Verify provider enum defaults and validation."""
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Tests for the executable application entry point."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from transcription import __main__ as entrypoint
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_passes_constructed_app_to_uvicorn(monkeypatch):
|
||||
"""Non-reload execution keeps the parsed settings instance in the app."""
|
||||
settings = SimpleNamespace(host="127.0.0.1", port=8123, log_level="debug", reload=False)
|
||||
application = object()
|
||||
captured = {}
|
||||
|
||||
def create_app(*, settings: object) -> object:
|
||||
assert settings is expected_settings
|
||||
return application
|
||||
|
||||
expected_settings = settings
|
||||
monkeypatch.setattr(entrypoint, "parse_cli_settings", lambda: settings)
|
||||
monkeypatch.setattr(entrypoint, "create_app", create_app)
|
||||
monkeypatch.setattr(
|
||||
entrypoint.uvicorn,
|
||||
"run",
|
||||
lambda app, **kwargs: captured.update(application=app, **kwargs),
|
||||
)
|
||||
|
||||
entrypoint.main()
|
||||
|
||||
assert captured == {
|
||||
"application": application,
|
||||
"factory": False,
|
||||
"host": "127.0.0.1",
|
||||
"port": 8123,
|
||||
"log_level": "debug",
|
||||
"reload": False,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_uses_cli_factory_for_reload(monkeypatch):
|
||||
"""Reload execution gives Uvicorn an importable CLI-aware factory."""
|
||||
settings = SimpleNamespace(host="127.0.0.1", port=8123, log_level="info", reload=True)
|
||||
captured = {}
|
||||
monkeypatch.setattr(entrypoint, "parse_cli_settings", lambda: settings)
|
||||
monkeypatch.setattr(
|
||||
entrypoint.uvicorn,
|
||||
"run",
|
||||
lambda app, **kwargs: captured.update(application=app, **kwargs),
|
||||
)
|
||||
|
||||
entrypoint.main()
|
||||
|
||||
assert captured["application"] == "transcription.__main__:create_cli_app"
|
||||
assert captured["factory"] is True
|
||||
assert captured["reload"] is True
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Tests for global UI theme registration."""
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
|
||||
from transcription.ui import register_pages
|
||||
from transcription.ui.resources import read_css
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_page_registration_uses_vibescribe_theme(monkeypatch):
|
||||
"""Global UI registration loads the standalone VibeScribe theme in light mode."""
|
||||
registered_css: list[str] = []
|
||||
run_options: dict[str, object] = {}
|
||||
|
||||
monkeypatch.setattr("transcription.ui.ui.add_css", lambda css, **_kwargs: registered_css.append(css))
|
||||
monkeypatch.setattr("transcription.ui.register_upload_page", lambda: None)
|
||||
monkeypatch.setattr("transcription.ui.register_jobs_page", lambda: None)
|
||||
monkeypatch.setattr(
|
||||
"transcription.ui.ui.run_with",
|
||||
lambda _app, **options: run_options.update(options),
|
||||
)
|
||||
|
||||
register_pages(FastAPI())
|
||||
|
||||
theme_css = read_css("theme.css")
|
||||
assert registered_css == [theme_css]
|
||||
assert set(re.findall(r"#[0-9a-fA-F]{6}", theme_css)) == {
|
||||
"#1c2321",
|
||||
"#7d98a1",
|
||||
"#5e6572",
|
||||
"#a9b4c2",
|
||||
"#eef1ef",
|
||||
}
|
||||
assert "--q-primary" in theme_css
|
||||
assert run_options["dark"] is False
|
||||
@@ -29,6 +29,7 @@ class TestPageRendering:
|
||||
response = client.get("/ui/upload")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "VibeScribe" in response.text
|
||||
assert "Upload Document" in response.text
|
||||
assert "Select document file" in response.text
|
||||
assert "Upload" in response.text
|
||||
|
||||
Reference in New Issue
Block a user