test: 清理 backlog——chat_structured 超限检测 + client 上下文管理器
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user