[Misc] Cleanup: use consistent pytest-mock in unit tests (#2698)
Signed-off-by: yuanheng <jonathan.zhaoyh@gmail.com>
This commit is contained in:
1 parent
2c67c30550
commit
e0cdbe9a5d
26 files changed
+1598
-1369
No files matched your search
@@ -6,7 +6,7 @@ explicitly patch values that differ from vLLM.
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
from unittest.mock import Mock
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
@@ -102,7 +102,7 @@ def test_qwen3_tts_codec_frame_rate_patching():
|
||||
vllm_config = EngineArgs().create_model_config()
|
||||
|
||||
# Create a mock talking config with a dummy value for position_id_per_seconds
|
||||
mock_talker_config = Mock()
|
||||
mock_talker_config = SimpleNamespace()
|
||||
mock_talker_config.position_id_per_seconds = 12.3
|
||||
vllm_config.hf_config.talker_config = mock_talker_config
|
||||
|
||||
@@ -146,13 +146,12 @@ def test_stage_specific_text_config_override():
|
||||
# Switch the created hf text config with a mock whose
|
||||
# values we want to pull through the text config helper
|
||||
stage_text_config = vllm_config.hf_text_config
|
||||
vllm_config.hf_text_config = Mock()
|
||||
vllm_config.hf_text_config = SimpleNamespace()
|
||||
stage_text_config.sliding_window = 4096
|
||||
stage_text_config.attention_chunk_size = 2048
|
||||
|
||||
# Move the stage config's text config getter & thinker config
|
||||
mock_stage_config = Mock()
|
||||
mock_stage_config.get_text_config.return_value = stage_text_config
|
||||
mock_stage_config = SimpleNamespace(get_text_config=lambda: stage_text_config)
|
||||
vllm_config.hf_config.thinker_config = mock_stage_config
|
||||
|
||||
# Ensure that create from a vLLM config correctly pulls the
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
from vllm.sampling_params import SamplingParams
|
||||
from vllm.v1.engine import EngineCoreRequest
|
||||
|
||||
@@ -24,18 +23,18 @@ def _make_engine_core_request() -> EngineCoreRequest:
|
||||
)
|
||||
|
||||
|
||||
def test_build_add_request_message_preserves_additional_information():
|
||||
def test_build_add_request_message_preserves_additional_information(mocker: MockerFixture):
|
||||
engine = object.__new__(AsyncOmniEngine)
|
||||
params = SamplingParams(max_tokens=8)
|
||||
engine.default_sampling_params_list = [params]
|
||||
engine.stage_metadata = [{"stage_type": "llm"}]
|
||||
engine.supported_tasks = ("speech",)
|
||||
|
||||
input_processor = Mock()
|
||||
input_processor = mocker.Mock()
|
||||
input_processor.process_inputs.return_value = _make_engine_core_request()
|
||||
engine.input_processor = input_processor
|
||||
|
||||
output_processor = Mock()
|
||||
output_processor = mocker.Mock()
|
||||
engine.output_processors = [output_processor]
|
||||
|
||||
prompt = {
|
||||
@@ -63,18 +62,18 @@ def test_build_add_request_message_preserves_additional_information():
|
||||
output_processor.add_request.assert_called_once()
|
||||
|
||||
|
||||
def test_build_add_request_message_with_resumable_streaming():
|
||||
def test_build_add_request_message_with_resumable_streaming(mocker: MockerFixture):
|
||||
engine = object.__new__(AsyncOmniEngine)
|
||||
params = SamplingParams(max_tokens=8)
|
||||
engine.default_sampling_params_list = [params]
|
||||
engine.stage_metadata = [{"stage_type": "llm"}]
|
||||
engine.supported_tasks = ("generate",)
|
||||
|
||||
input_processor = Mock()
|
||||
input_processor = mocker.Mock()
|
||||
input_processor.process_inputs.return_value = _make_engine_core_request()
|
||||
engine.input_processor = input_processor
|
||||
|
||||
output_processor = Mock()
|
||||
output_processor = mocker.Mock()
|
||||
engine.output_processors = [output_processor]
|
||||
|
||||
msg = engine._build_add_request_message(
|
||||
|
||||
@@ -5,36 +5,36 @@ subsequent attempts to collect output raise RuntimeError.
|
||||
"""
|
||||
|
||||
import queue
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from vllm_omni.engine.async_omni_engine import AsyncOmniEngine
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _make_engine(output_queue, *, thread_alive: bool = True) -> AsyncOmniEngine:
|
||||
def _make_engine(output_queue, mocker: MockerFixture, *, thread_alive: bool = True) -> AsyncOmniEngine:
|
||||
"""Create an AsyncOmniEngine bypassing __init__."""
|
||||
engine = object.__new__(AsyncOmniEngine)
|
||||
engine.output_queue = output_queue
|
||||
engine.orchestrator_thread = MagicMock(
|
||||
is_alive=MagicMock(return_value=thread_alive),
|
||||
engine.orchestrator_thread = mocker.MagicMock(
|
||||
is_alive=mocker.MagicMock(return_value=thread_alive),
|
||||
)
|
||||
return engine
|
||||
|
||||
|
||||
def test_try_get_output_raises_after_orchestrator_dies():
|
||||
def test_try_get_output_raises_after_orchestrator_dies(mocker: MockerFixture):
|
||||
"""Draining remaining results then hitting an empty queue with a dead
|
||||
orchestrator must raise RuntimeError so callers know the pipeline is gone."""
|
||||
mock_queue = MagicMock()
|
||||
mock_queue = mocker.MagicMock()
|
||||
# First call succeeds; second call finds the queue empty.
|
||||
mock_queue.sync_q.get.side_effect = [
|
||||
{"type": "output", "request_id": "r1"},
|
||||
queue.Empty,
|
||||
]
|
||||
|
||||
engine = _make_engine(mock_queue, thread_alive=True)
|
||||
engine = _make_engine(mock_queue, mocker, thread_alive=True)
|
||||
|
||||
# Collect the one buffered result.
|
||||
assert engine.try_get_output()["request_id"] == "r1"
|
||||
@@ -47,15 +47,15 @@ def test_try_get_output_raises_after_orchestrator_dies():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_try_get_output_async_raises_after_orchestrator_dies():
|
||||
async def test_try_get_output_async_raises_after_orchestrator_dies(mocker: MockerFixture):
|
||||
"""Same scenario as above but for the async variant."""
|
||||
mock_queue = MagicMock()
|
||||
mock_queue = mocker.MagicMock()
|
||||
mock_queue.sync_q.get_nowait.side_effect = [
|
||||
{"type": "output", "request_id": "r1"},
|
||||
queue.Empty,
|
||||
]
|
||||
|
||||
engine = _make_engine(mock_queue, thread_alive=True)
|
||||
engine = _make_engine(mock_queue, mocker, thread_alive=True)
|
||||
|
||||
assert (await engine.try_get_output_async())["request_id"] == "r1"
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user