mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-28 01:32:17 +00:00
* ci: run the unit_selection.sh shard files on every event instead of only fork pull requests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: rename fork-flag to unit-flag now that it applies on every event * test: move tests/test_litellm root and small trees into tests/unit Pure renames, no content changes. Follow-up commits in this PR fix references, merge the three files that already existed in tests/unit, keep live-provider tests in tests/test_litellm and wire CI. * test: carry tests/test_litellm conftest isolation into tests/unit Callback lists, routing fallbacks, cached HTTP clients, logger state, AWS, proxy-URL and keychain env, and session-end client cleanup now reset for unit tests too. The environment isolation owns its MonkeyPatch so a test's own monkeypatch is undone before the model-cost teardown runs. * test: merge, split and prune the moved root and small-tree tests Merge batches/test_batch_utils.py and the chat_completions and messages dispatch tests into the files that already existed in tests/unit. Keep the live Gemini interactions tests, the async image-fetch format test and the OpenAI embedding scorer test in tests/test_litellm since they need real network or keys. Put test_router.py under tests/unit/test_router so the existing package no longer shadows it. Delete eight tests the audit found superseded by stronger ones kept in this move. * ci: run the moved root and small-tree tests under their legacy flags Add the misc and responses-caching-types flags to unit_selection.sh and CircleCI, extend enterprise-routing and mcp-integration, and point the legacy GHA shards, Makefile, redis-compat workflow, merge smoke manifest and change classifier at the new paths. * test: make the new tests/unit directories packages tests/unit/test_package_layout.py requires every directory to carry an __init__.py, and without one the moved and retained test_litellm_responses_bridge.py modules collide on import. * test: scope the unit socket block to tests/unit in shared sessions The GHA shards collect the legacy test-path and the unit selection in one pytest session. The unit conftest's loopback-only block leaked into legacy modules that reach the network at import. The legacy conftest now lifts the restriction at collect and setup time, and the unit conftest re-applies it when collecting its own modules. * test: give the shard-script tests their own GITHUB_OUTPUT They only passed where the runner set it. The CircleCI unit job's env allowlist drops it, so the script's redirect failed there. * test: point the router and module-deletion checks at tests/unit router_code_coverage and code_qa_check_tests only searched tests/test_litellm, so the moved router tests no longer counted. The two silent-experiment tests the audit deleted were the only direct callers of those methods; they are replaced with tests that assert the forwarded shadow request and the recursion guard. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
import json
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
from typing import Final
|
|
|
|
import pytest
|
|
|
|
import litellm
|
|
|
|
REPO_ROOT: Final = Path(__file__).parents[2]
|
|
MAIN_PATH: Final = REPO_ROOT / "model_prices_and_context_window.json"
|
|
BACKUP_PATH: Final = REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json"
|
|
|
|
FLASH_TTS_KEYS: Final = ("gemini-2.5-flash-preview-tts", "gemini/gemini-2.5-flash-preview-tts")
|
|
PRO_TTS_KEYS: Final = ("gemini-2.5-pro-preview-tts", "gemini/gemini-2.5-pro-preview-tts")
|
|
NATIVE_AUDIO_KEYS: Final = tuple(
|
|
f"{prefix}gemini-2.5-flash-native-audio-{suffix}"
|
|
for prefix in ("", "gemini/")
|
|
for suffix in ("latest", "preview-09-2025", "preview-12-2025")
|
|
)
|
|
|
|
LIVE_NATIVE_AUDIO_KEYS: Final = (
|
|
"gemini-live-2.5-flash-preview-native-audio-09-2025",
|
|
"gemini/gemini-live-2.5-flash-preview-native-audio-09-2025",
|
|
)
|
|
|
|
FLASH_TTS_INPUT: Final = 5e-07
|
|
FLASH_TTS_AUDIO_OUTPUT: Final = 1e-05
|
|
PRO_TTS_INPUT: Final = 1e-06
|
|
PRO_TTS_AUDIO_OUTPUT: Final = 2e-05
|
|
NATIVE_AUDIO_TEXT_INPUT: Final = 5e-07
|
|
NATIVE_AUDIO_AUDIO_INPUT: Final = 3e-06
|
|
NATIVE_AUDIO_TEXT_OUTPUT: Final = 2e-06
|
|
NATIVE_AUDIO_AUDIO_OUTPUT: Final = 1.2e-05
|
|
|
|
PUBLISHED_RATES: Final = {
|
|
**{
|
|
key: {"input_cost_per_token": FLASH_TTS_INPUT, "output_cost_per_token": FLASH_TTS_AUDIO_OUTPUT}
|
|
for key in FLASH_TTS_KEYS
|
|
},
|
|
**{
|
|
key: {"input_cost_per_token": PRO_TTS_INPUT, "output_cost_per_token": PRO_TTS_AUDIO_OUTPUT}
|
|
for key in PRO_TTS_KEYS
|
|
},
|
|
**{
|
|
key: {
|
|
"input_cost_per_token": NATIVE_AUDIO_TEXT_INPUT,
|
|
"input_cost_per_audio_token": NATIVE_AUDIO_AUDIO_INPUT,
|
|
"output_cost_per_token": NATIVE_AUDIO_TEXT_OUTPUT,
|
|
"output_cost_per_audio_token": NATIVE_AUDIO_AUDIO_OUTPUT,
|
|
}
|
|
for key in (*NATIVE_AUDIO_KEYS, *LIVE_NATIVE_AUDIO_KEYS)
|
|
},
|
|
}
|
|
ALL_KEYS: Final = tuple(PUBLISHED_RATES)
|
|
NATIVE_AUDIO_BILLING_CASES: Final = (
|
|
*((key, "gemini") for key in NATIVE_AUDIO_KEYS),
|
|
("gemini-live-2.5-flash-preview-native-audio-09-2025", "vertex_ai"),
|
|
("gemini/gemini-live-2.5-flash-preview-native-audio-09-2025", "gemini"),
|
|
)
|
|
LONG_CONTEXT_TIER_FIELDS: Final = (
|
|
"input_cost_per_token_above_200k_tokens",
|
|
"output_cost_per_token_above_200k_tokens",
|
|
"cache_read_input_token_cost_above_200k_tokens",
|
|
)
|
|
|
|
|
|
def _load(path: Path) -> dict[str, dict[str, object]]:
|
|
with open(path, encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
@pytest.fixture
|
|
def local_model_cost_map(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
|
|
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")
|
|
monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))
|
|
litellm.get_model_info.cache_clear()
|
|
yield
|
|
litellm.get_model_info.cache_clear()
|
|
|
|
|
|
@pytest.mark.parametrize("model", ALL_KEYS)
|
|
def test_backup_matches_main(model: str):
|
|
assert _load(BACKUP_PATH)[model] == _load(MAIN_PATH)[model]
|