litellm/tests/unit/test_version.py
joshua-berri f48d837cd2
feat(sdk): build core from an independent packaging manifest (#44340)
* feat(sdk): build core from an independent packaging manifest

* test(sdk): compare rebuilt core payload without generated SBOM identity

* fix(sdk): retain native build configuration in the core sdist

* test(sdk): collect coverage from the core build entry point

* fix(ci): isolate core packaging coverage configuration

* fix(test): identify installed core metadata on Python 3.10

* fix(packaging): preserve Git ignore rules in core staging

* fix(packaging): support source-only core builds

* fix(packaging): reject overlapping SDK distributions

* fix(packaging): align core requirements with current main

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-10-08 18:40:14 -07:00

40 lines
1.5 KiB
Python

import runpy
from pathlib import Path
from typing import Final
from unittest.mock import patch
import importlib_metadata
import pytest
@pytest.mark.parametrize(
("installed", "expected"),
[
({"litellm": "1.2.3"}, "1.2.3"),
({"litellm-core": "2.3.4"}, "2.3.4"),
({}, "unknown"),
],
)
def test_version_uses_installed_distribution(installed: dict[str, str], expected: str) -> None:
def lookup(name: str) -> str:
if name not in installed:
raise importlib_metadata.PackageNotFoundError(name)
return installed[name]
with patch("importlib_metadata.version", side_effect=lookup):
result: Final = runpy.run_path(str(Path(__file__).resolve().parents[2] / "litellm/_version.py"))
assert result["version"] == expected
@pytest.mark.parametrize("core_version", ["1.2.3", "2.3.4"])
def test_version_rejects_overlapping_distributions(core_version: str) -> None:
installed: Final = {"litellm": "1.2.3", "litellm-core": core_version}
with patch("importlib_metadata.version", side_effect=installed.__getitem__):
with pytest.raises(RuntimeError, match=r"litellm and litellm-core.*separate environments"):
runpy.run_path(str(Path(__file__).resolve().parents[2] / "litellm/_version.py"))
def test_version_handles_unreadable_metadata() -> None:
with patch("importlib_metadata.version", side_effect=ValueError("Invalid metadata")):
result: Final = runpy.run_path(str(Path(__file__).resolve().parents[2] / "litellm/_version.py"))
assert result["version"] == "unknown"