generated from john/python-template
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from transcription.errors import AppError
|
||||
from transcription.errors import ErrorCategory
|
||||
from transcription.ui.components.error_presenter import display_error_category
|
||||
from transcription.ui.components.error_presenter import run_ui_action
|
||||
|
||||
|
||||
def test_display_error_category_uses_canonical_taxonomy():
|
||||
@@ -12,3 +15,48 @@ def test_display_error_category_uses_canonical_taxonomy():
|
||||
assert display_error_category(AppError("x", category=ErrorCategory.INFRA_TRANSIENT)) == "timeout"
|
||||
assert display_error_category(AppError("x", category=ErrorCategory.PROCESSING)) == "internal"
|
||||
assert display_error_category(AppError("x", category=ErrorCategory.INFRA_PERSISTENT)) == "internal"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_ui_action_returns_success_value():
|
||||
outcome = await run_ui_action(
|
||||
operation="ui.test.success",
|
||||
title="Should not show",
|
||||
action=lambda: _async_value(123),
|
||||
)
|
||||
|
||||
assert outcome.ok is True
|
||||
assert outcome.value == 123
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_ui_action_shows_error_and_returns_failed(monkeypatch):
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def _capture(exc: Exception, *, title: str, operation: str) -> None:
|
||||
captured["exc"] = exc
|
||||
captured["title"] = title
|
||||
captured["operation"] = operation
|
||||
|
||||
monkeypatch.setattr("transcription.ui.components.error_presenter.show_error", _capture)
|
||||
|
||||
outcome = await run_ui_action(
|
||||
operation="ui.test.failure",
|
||||
title="Load failed",
|
||||
action=lambda: _async_raises(RuntimeError("boom")),
|
||||
)
|
||||
|
||||
assert outcome.ok is False
|
||||
assert outcome.value is None
|
||||
assert isinstance(captured["exc"], RuntimeError)
|
||||
assert str(captured["exc"]) == "boom"
|
||||
assert captured["title"] == "Load failed"
|
||||
assert captured["operation"] == "ui.test.failure"
|
||||
|
||||
|
||||
async def _async_value(value: int) -> int:
|
||||
return value
|
||||
|
||||
|
||||
async def _async_raises(exc: Exception) -> int:
|
||||
raise exc
|
||||
|
||||
Reference in New Issue
Block a user