Merge origin/main into docs/agents-pr-only
CI / Backend (push) Successful in 11s
CI / CLI (push) Successful in 11s

This commit is contained in:
2026-06-04 17:44:34 +02:00
7 changed files with 146 additions and 17 deletions
+43 -3
View File
@@ -1,9 +1,10 @@
import os
from argparse import Namespace
from dataclasses import dataclass
from pathlib import Path
import sys
from dataclasses import dataclass
import httpx
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
@@ -32,6 +33,37 @@ def test_infer_output_path_for_explicit_file(tmp_path: Path) -> None:
assert destination == tmp_path / "custom-name.txt"
def test_format_http_error_with_body() -> None:
request = httpx.Request("POST", "http://localhost:8000/transcriptions")
response = httpx.Response(500, text="Internal Server Error", request=request)
message = main.format_http_error(response, "http://localhost:8000/transcriptions")
assert message == "HTTP 500 from http://localhost:8000/transcriptions: Internal Server Error"
def test_format_http_error_with_empty_body() -> None:
request = httpx.Request("POST", "http://localhost:8000/transcriptions")
response = httpx.Response(500, text="", request=request)
message = main.format_http_error(response, "http://localhost:8000/transcriptions")
assert message == "HTTP 500 from http://localhost:8000/transcriptions: <empty response body>"
def test_format_request_error_timeout() -> None:
request = httpx.Request("POST", "http://localhost:8000/transcriptions")
exc = httpx.ReadTimeout("read timed out", request=request)
message = main.format_request_error(exc, "http://localhost:8000/transcriptions")
assert message == "Request to http://localhost:8000/transcriptions timed out."
def test_format_request_error_network_failure() -> None:
request = httpx.Request("POST", "http://localhost:8000/transcriptions")
exc = httpx.ConnectError("connection refused", request=request)
message = main.format_request_error(exc, "http://localhost:8000/transcriptions")
assert (
message
== "Request to http://localhost:8000/transcriptions failed: connection refused"
)
@dataclass
class FakeResponse:
content: bytes
@@ -61,8 +93,16 @@ def test_main_writes_transcript_to_file(monkeypatch, tmp_path: Path, capsys) ->
destination = tmp_path / "saved" / "clip.txt"
monkeypatch.setenv("WHISPER_REMOTE", "http://localhost:8000")
monkeypatch.setattr(main.httpx, "Client", lambda timeout: FakeClient(FakeResponse(b"hello world", "hello world")))
monkeypatch.setattr(sys, "argv", ["whisper-remote", str(input_file), "--model", "base", "--to-file", str(destination)])
monkeypatch.setattr(
main.httpx,
"Client",
lambda timeout: FakeClient(FakeResponse(b"hello world", "hello world")),
)
monkeypatch.setattr(
sys,
"argv",
["whisper-remote", str(input_file), "--model", "base", "--to-file", str(destination)],
)
exit_code = main.main()