mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
test(mcp): cover YAML spec parsing branches
This commit is contained in:
parent
8e819168bd
commit
4ed28ec9fa
1 changed files with 31 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ This test suite ensures that:
|
|||
5. Path parameters are properly URL encoded
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Final
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
|
@ -312,6 +313,11 @@ def test_parse_openapi_spec_rejects_non_object_document() -> None:
|
|||
gen._parse_openapi_spec("- not an OpenAPI object\n")
|
||||
|
||||
|
||||
def test_parse_openapi_spec_rejects_json_scalar() -> None:
|
||||
with pytest.raises(TypeError, match="OpenAPI spec must be a JSON or YAML object"):
|
||||
gen._parse_openapi_spec("42")
|
||||
|
||||
|
||||
def test_parse_openapi_spec_rejects_yaml_merge_aliases() -> None:
|
||||
import yaml
|
||||
|
||||
|
|
@ -330,6 +336,13 @@ merged:
|
|||
)
|
||||
|
||||
|
||||
def test_parse_openapi_spec_rejects_yaml_merge_keys() -> None:
|
||||
import yaml
|
||||
|
||||
with pytest.raises(yaml.YAMLError, match="YAML merge keys are not supported"):
|
||||
gen._parse_openapi_spec("<<: {openapi: 3.0.0}\n")
|
||||
|
||||
|
||||
def test_parse_openapi_spec_rejects_yaml_aliases() -> None:
|
||||
import yaml
|
||||
|
||||
|
|
@ -355,6 +368,24 @@ def test_parse_openapi_spec_rejects_oversized_yaml_integer() -> None:
|
|||
gen._parse_openapi_spec(f"openapi: 3.0.0\nx-expensive: {oversized_integer}\n")
|
||||
|
||||
|
||||
def test_parse_openapi_spec_accepts_yaml_integer() -> None:
|
||||
assert gen._parse_openapi_spec("openapi: 3.0.0\nrevision: 1\n") == {
|
||||
"openapi": "3.0.0",
|
||||
"revision": 1,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_openapi_spec_async_reads_local_yaml(tmp_path: Path) -> None:
|
||||
spec_path = tmp_path / "openapi.yaml"
|
||||
spec_path.write_text("openapi: 3.0.0\npaths: {}\n", encoding="utf-8")
|
||||
|
||||
assert await gen.load_openapi_spec_async(str(spec_path)) == {
|
||||
"openapi": "3.0.0",
|
||||
"paths": {},
|
||||
}
|
||||
|
||||
|
||||
def _create_mock_client(method: str, response_text: str, status_code: int = 200) -> AsyncMock:
|
||||
"""Utility to create a mocked async httpx client for the given method.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue