From c117ef5440897f72d17d0d1335f8a6cc198dfc64 Mon Sep 17 00:00:00 2001 From: Edern Deneuville Date: Fri, 11 Sep 2026 13:44:14 +0200 Subject: [PATCH] Add AI timeout tests --- tests/test_ai_client.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_ai_client.py b/tests/test_ai_client.py index dc8cbf7..3e78a78 100644 --- a/tests/test_ai_client.py +++ b/tests/test_ai_client.py @@ -1,4 +1,7 @@ -from ai_typewriter.ai_client import ask_ai +import pytest +import requests + +from ai_typewriter.ai_client import AIClientError, ask_ai from ai_typewriter.config import AppConfig @@ -27,6 +30,19 @@ def test_ollama_payload_contains_strict_system_prompt(monkeypatch): assert "Uniquement la réponse brute" in seen["json"]["messages"][0]["content"] +def test_ollama_timeout_message_suggests_config_change(monkeypatch): + def fake_post(url, json, timeout, **kwargs): + raise requests.Timeout("too slow") + monkeypatch.setattr("ai_typewriter.ai_client.requests.post", fake_post) + + with pytest.raises(AIClientError) as exc: + ask_ai("texte", AppConfig(provider="ollama", model="m", request_timeout_seconds=300)) + + assert "300 s" in str(exc.value) + assert "request_timeout_seconds" in str(exc.value) + assert "0 pour désactiver" in str(exc.value) + + def test_gemini_payload(monkeypatch): seen = {} def fake_post(url, params, json, timeout):