generated from john/python-template
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""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_uses_cli_factory_import_string(monkeypatch):
|
|
"""Startup uses an importable factory so Uvicorn owns app creation."""
|
|
settings = SimpleNamespace(host="127.0.0.1", port=8123, log_level="debug", reload=False)
|
|
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",
|
|
"factory": True,
|
|
"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
|