test(docker_model_runner): satisfy test-quality gate in provider tests

Drop copy-pasted sys.path inserts (TQ003), assert the dispatch return
value instead of only mock kwargs (TQ002), and mark the two shared
handler patches with their seam justification (TQ008)
This commit is contained in:
Kirill Losev 2026-08-30 15:07:31 +03:00
parent a4d2b49cb1
commit 57f898f205
6 changed files with 9 additions and 28 deletions

View file

@ -7,15 +7,11 @@ parameter mapping, and request/response transformation.
"""
import json
import os
import sys
from typing import List
from unittest.mock import MagicMock, patch
import pytest
sys.path.insert(0, os.path.abspath("../../../../.."))
from litellm.llms.docker_model_runner.chat.transformation import (
DockerModelRunnerChatConfig,
)

View file

@ -5,13 +5,8 @@ This test verifies that the DockerModelRunnerCompletionConfig correctly transfor
text completion requests and handles URL generation for the Docker Model Runner API.
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.abspath("../../../../..")) # Adds the parent directory to the system path
from litellm.llms.docker_model_runner.completion.transformation import (
DockerModelRunnerCompletionConfig,
)

View file

@ -1,11 +1,7 @@
"""Tests for the Docker Model Runner dispatch wiring in litellm/main.py."""
import os
import sys
from unittest.mock import MagicMock, patch
sys.path.insert(0, os.path.abspath("../../../.."))
import litellm
from litellm.main import _complete_docker_model_runner
from litellm.types.completion import _CompletionDispatchContext
@ -51,7 +47,9 @@ def test_complete_docker_model_runner_uses_shared_http_handler():
ctx = _make_ctx()
sentinel = MagicMock(name="response")
with patch("litellm.main.base_llm_http_handler.completion", return_value=sentinel) as mock_completion:
with patch( # test-quality-ok: the dispatch's only injection seam is the shared handler sink
"litellm.main.base_llm_http_handler.completion", return_value=sentinel
) as mock_completion:
result = _complete_docker_model_runner(ctx)
assert result is sentinel
@ -66,8 +64,12 @@ def test_complete_docker_model_runner_respects_env_api_base(monkeypatch):
"""DOCKER_MODEL_RUNNER_API_BASE is picked up when no explicit api_base is set."""
monkeypatch.setenv("DOCKER_MODEL_RUNNER_API_BASE", "http://model-runner.docker.internal:12434/engines/v1")
ctx = _make_ctx()
sentinel = MagicMock(name="response")
with patch("litellm.main.base_llm_http_handler.completion", return_value=MagicMock()) as mock_completion:
_complete_docker_model_runner(ctx)
with patch( # test-quality-ok: the dispatch's only injection seam is the shared handler sink
"litellm.main.base_llm_http_handler.completion", return_value=sentinel
) as mock_completion:
result = _complete_docker_model_runner(ctx)
assert result is sentinel
assert mock_completion.call_args.kwargs["api_base"] == "http://model-runner.docker.internal:12434/engines/v1"

View file

@ -6,14 +6,10 @@ embedding requests and handles URL generation for the Docker Model Runner API.
"""
import json
import os
import sys
from unittest.mock import MagicMock
import pytest
sys.path.insert(0, os.path.abspath("../../../../..")) # Adds the parent directory to the system path
from litellm.llms.docker_model_runner.embedding.transformation import (
DockerModelRunnerEmbeddingConfig,
)

View file

@ -7,14 +7,10 @@ Diffusers backend of Docker Model Runner.
"""
import json
import os
import sys
from unittest.mock import MagicMock
import pytest
sys.path.insert(0, os.path.abspath("../../../../..")) # Adds the parent directory to the system path
from litellm.llms.docker_model_runner.images.transformation import (
DockerModelRunnerImageGenerationConfig,
)

View file

@ -6,14 +6,10 @@ rerank requests and handles both llama.cpp and vLLM response formats.
"""
import json
import os
import sys
from unittest.mock import MagicMock
import pytest
sys.path.insert(0, os.path.abspath("../../../../..")) # Adds the parent directory to the system path
from litellm.llms.docker_model_runner.rerank.transformation import (
DockerModelRunnerRerankConfig,
)