test: cover deferred import branches

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-09-17 09:26:35 +00:00
parent 293a96332c
commit 25949a87ac
3 changed files with 30 additions and 1 deletions

View file

@ -131,6 +131,13 @@ class TestGCSBucketBase:
class TestGCSBucketLoggerBucketName:
@pytest.mark.asyncio
async def test_constructor_rejects_non_premium_user(self, monkeypatch):
monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", False)
with pytest.raises(ValueError, match="GCS Bucket logging is a premium feature"):
GCSBucketLogger(bucket_name="config-bucket")
@pytest.mark.asyncio
async def test_the_bucket_name_it_is_constructed_with_survives(self, monkeypatch):
"""Reading config.yaml out of a GCS bucket asks for that bucket, not the logging one (LIT-6982)."""
@ -145,3 +152,11 @@ class TestGCSBucketLoggerBucketName:
monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", True)
assert GCSBucketLogger().BUCKET_NAME == "logging-bucket"
@pytest.mark.asyncio
async def test_async_logging_rejects_non_premium_user(self, monkeypatch):
monkeypatch.setattr("litellm.proxy.proxy_server.premium_user", False)
logger = object.__new__(GCSBucketLogger)
with pytest.raises(ValueError, match="GCS Bucket logging is a premium feature"):
await logger.async_log_success_event({}, None, None, None)

View file

@ -1754,6 +1754,20 @@ class TestCustomGuardrailSpendLogMatchRedaction:
class TestGuardrailInterventionClassification:
"""A routing decision is a deliberate guardrail intervention, not a failure."""
def test_http_exception_classification_returns_false_without_fastapi(self, monkeypatch):
import builtins
real_import = builtins.__import__
def import_without_fastapi(name, *args, **kwargs):
if name == "fastapi.exceptions":
raise ImportError("fastapi is unavailable")
return real_import(name, *args, **kwargs)
monkeypatch.setattr(builtins, "__import__", import_without_fastapi)
assert CustomGuardrail._is_guardrail_intervention(Exception("not an intervention")) is False
def test_sensitive_data_route_exception_is_intervention(self):
from litellm.exceptions import SensitiveDataRouteException

View file

@ -102,7 +102,7 @@ def test_token_counter_default_encoding_matches_cl100k():
encoding: Final = tiktoken.get_encoding("cl100k_base")
expected: Final = len(encoding.encode("hello world", disallowed_special=()))
assert token_counter_new(model="", text="hello world") == expected
assert token_counter_new(model=None, text="hello world") == expected
def test_token_counter_text_over_chunk_boundary_stays_close_to_tiktoken():