test: 清理 backlog——chat_structured 超限检测 + client 上下文管理器

This commit is contained in:
lhl
2026-08-09 09:15:36 +08:00
parent a5eaec4de8
commit cb2deda08a
5 changed files with 56 additions and 5 deletions
+18
View File
@@ -54,6 +54,24 @@ def test_chat_requires_api_key():
HttpLLMClient(base_url="https://x", api_key="")
def test_client_context_manager_closes_transport():
# with 块退出后底层 httpx.Client 应被关闭(释放连接)
with HttpLLMClient(
base_url="https://api.test.local",
api_key="sk-test",
transport=httpx.MockTransport(_ok_handler),
) as client:
assert isinstance(client, HttpLLMClient)
text, _ = client.chat(
model="deepseek-chat",
messages=[ChatMessage(role="user", content="hi")],
temperature=0.2,
max_tokens=100,
)
assert text == "Hello"
assert client._client.is_closed is True
def test_chat_timeout():
def slow(request):
raise httpx.ReadTimeout("slow")