mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-12 03:48:56 +00:00
* test: move offline router, latency-routing, retry and exception tests from local_testing into tests/unit Moves 29 offline nodes into the tests/unit files that mirror the code they exercise. Hosted-provider calls are mocked at the HTTP boundary with respx, and sleeps that only built a start/end gap are replaced by explicit timestamps. Legacy files left empty are deleted. * ci: record the live prompt caching cases left in tests/local_testing as unrun Moving the router prompt caching test to tests/unit leaves only live Anthropic and Vertex cases in tests/local_testing/test_anthropic_prompt_caching.py, which every CircleCI -k already deselects * test: freeze the clock in the moved lowest-latency routing tests The latency logger buckets usage by the current minute, so a run that crosses a minute boundary could grow the cache and fail the memory check. The moved tests now use fixed timestamps and a frozen clock in the logger module * ci: describe the mixed prompt caching file accurately in the coverage allowlist
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import httpx
|
|
import respx
|
|
|
|
import litellm
|
|
|
|
msg1 = [{"role": "user", "content": "hi 1"}]
|
|
msg2 = [{"role": "user", "content": "hi 2"}]
|
|
|
|
|
|
def test_batch_completion_return_exceptions_true(respx_mock: respx.MockRouter):
|
|
"""Test batch_completion's return_exceptions.
|
|
|
|
With an invalid API key, we expect an error to be returned rather than raised.
|
|
The error type may be AuthenticationError (from API) or InternalServerError
|
|
(from connection issues), depending on network conditions.
|
|
"""
|
|
respx_mock.post("https://api.openai.com/v1/chat/completions").mock(
|
|
return_value=httpx.Response(
|
|
401,
|
|
json={
|
|
"error": {
|
|
"message": "Incorrect API key provided: sk_xxx.",
|
|
"type": "invalid_request_error",
|
|
"code": "invalid_api_key",
|
|
}
|
|
},
|
|
)
|
|
)
|
|
res = litellm.batch_completion(
|
|
model="gpt-3.5-turbo",
|
|
messages=[msg1, msg2],
|
|
api_key="sk_xxx",
|
|
)
|
|
|
|
assert isinstance(
|
|
res[0],
|
|
(
|
|
litellm.exceptions.AuthenticationError,
|
|
litellm.exceptions.InternalServerError,
|
|
),
|
|
), f"Expected AuthenticationError or InternalServerError, got {type(res[0])}"
|