mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
# What this tests?
|
|
## This tests the litellm support for the openai /generations endpoint
|
|
|
|
import logging
|
|
import traceback
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
from openai.types.image import Image
|
|
from litellm.caching import InMemoryCache
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
load_dotenv()
|
|
import asyncio
|
|
import pytest
|
|
|
|
import litellm
|
|
import json
|
|
import tempfile
|
|
from base_image_generation_test import BaseImageGenTest
|
|
import logging
|
|
from litellm._logging import verbose_logger
|
|
from io import BytesIO
|
|
from PIL import Image as PILImage
|
|
|
|
verbose_logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
@pytest.fixture
|
|
def image_url():
|
|
# DALL-E 2 image variations require a square PNG (less than 4MB)
|
|
# Generate a 1024x1024 square PNG programmatically to avoid network dependency
|
|
# and the non-square aspect ratio of the old LiteLLM logo URL
|
|
img = PILImage.new("RGBA", (1024, 1024), color=(128, 128, 128, 255))
|
|
image_file = BytesIO()
|
|
img.save(image_file, format="PNG")
|
|
image_file.seek(0)
|
|
# openai>=2.24.0 requires BytesIO to have .name for MIME type detection in multipart uploads
|
|
image_file.name = "litellm_logo.png"
|
|
|
|
return image_file
|
|
|
|
|
|
# Commented out: OpenAI /images/variations endpoint deprecated (DALL-E 2 shutdown May 12, 2026)
|
|
# def test_openai_image_variation_openai_sdk(image_url):
|
|
# from openai import OpenAI
|
|
#
|
|
# client = OpenAI()
|
|
# response = client.images.create_variation(image=image_url, n=2, size="1024x1024")
|
|
# print(response)
|
|
#
|
|
#
|
|
# @pytest.mark.parametrize("sync_mode", [True, False])
|
|
# @pytest.mark.asyncio
|
|
# async def test_openai_image_variation_litellm_sdk(image_url, sync_mode):
|
|
# from litellm import image_variation, aimage_variation
|
|
#
|
|
# if sync_mode:
|
|
# image_variation(image=image_url, n=2, size="1024x1024")
|
|
# else:
|
|
# await aimage_variation(image=image_url, n=2, size="1024x1024")
|
|
#
|
|
#
|
|
# def test_topaz_image_variation(image_url):
|
|
# from litellm import image_variation, aimage_variation
|
|
# from litellm.llms.custom_httpx.http_handler import HTTPHandler
|
|
# from unittest.mock import patch
|
|
#
|
|
# client = HTTPHandler()
|
|
# with patch.object(client, "post") as mock_post:
|
|
# try:
|
|
# image_variation(
|
|
# model="topaz/Standard V2",
|
|
# image=image_url,
|
|
# n=2,
|
|
# size="1024x1024",
|
|
# client=client,
|
|
# )
|
|
# except Exception as e:
|
|
# print(e)
|
|
# mock_post.assert_called_once()
|
|
|
|
|
|
def test_image_variation_placeholder():
|
|
"""Placeholder: variation tests commented out - OpenAI /images/variations deprecated (DALL-E 2 shutdown May 12, 2026)."""
|
|
pass
|