Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -259,7 +259,7 @@ async def _generator(prompt_idx: int, text: str) -> AsyncGenerator[RequestOutput
@pytest.mark.asyncio
@pytest.mark.skip_global_cleanup
async def test_batched_echo_does_not_prepend_user_prompt() -> None:
"""echo must only echo the assistant turn, never the user's prompt.
"""Echo must only echo the assistant turn, never the user's prompt.
With `add_generation_prompt` (the default) the response role is `assistant`
while the last conversation message is the user's, so there is nothing to
@@ -121,7 +121,7 @@ def _build_serving_chat(engine: AsyncLLM) -> OpenAIServingChat:
@pytest.mark.asyncio
async def test_chat_error_non_stream():
"""test finish_reason='error' returns 500 InternalServerError (non-streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (non-streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -246,7 +246,7 @@ async def test_renderer_only_chat_request_skips_mm_cache():
@pytest.mark.asyncio
async def test_chat_error_stream():
"""test finish_reason='error' returns 500 InternalServerError (streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -465,7 +465,8 @@ def test_system_message_warns_on_video(video_content):
def test_json_schema_response_format_missing_schema():
"""When response_format type is 'json_schema' but the json_schema field
is not provided, request construction should raise a validation error
so the API returns 400 instead of 500."""
so the API returns 400 instead of 500.
"""
with pytest.raises(Exception, match="json_schema.*must be provided"):
ChatCompletionRequest(
model=MODEL_NAME,
@@ -519,7 +520,8 @@ def test_structured_outputs_structural_tag_invalid(structural_tag):
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "top_logprobs"])
def test_non_numeric_logprobs_rejected(field_name):
"""A non-numeric logprobs value must be a clean 400 validation error, not a
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
"""
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
ChatCompletionRequest(
model=MODEL_NAME,
@@ -81,7 +81,8 @@ async def test_chat_logit_bias_invalid(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_non_integer_key(client):
"""Test that a non-integer logit_bias key is rejected with a clean,
informative error instead of a raw 'invalid literal for int()' message."""
informative error instead of a raw 'invalid literal for int()' message.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -101,7 +102,8 @@ async def test_chat_logit_bias_non_integer_key(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_non_numeric_value(client):
"""Test that a non-numeric logit_bias value is rejected with a message
that names the specific offending token, not just a generic TypeError."""
that names the specific offending token, not just a generic TypeError.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -120,7 +122,8 @@ async def test_chat_logit_bias_non_numeric_value(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_multiple_non_integer_keys(client):
"""Test that ALL invalid logit_bias keys are reported together,
not just the first one encountered."""
not just the first one encountered.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -451,7 +451,7 @@ async def test_inconsistent_tool_choice_and_tools(
async def test_max_tokens_with_tool_choice_required(
client: openai.AsyncOpenAI, tool_choice
):
""" """
"""Requesting a single token with a required tool choice must not crash."""
models = await client.models.list()
model_name: str = models.data[0].id
@@ -52,9 +52,10 @@ def stop_sign_image_url():
@pytest.mark.asyncio
async def test_translategemma_extra_lang_code_fields(client: openai.AsyncOpenAI):
"""en -> es translation through TranslateGemma's bundled chat template's
"""En -> es translation through TranslateGemma's bundled chat template's
``text`` content branch, which depends on ``source_lang_code`` /
``target_lang_code`` extra fields being preserved on the content part."""
``target_lang_code`` extra fields being preserved on the content part.
"""
completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=[
@@ -92,13 +93,14 @@ async def test_translategemma_image_extra_lang_code_fields(
client: openai.AsyncOpenAI,
stop_sign_image_url: str,
):
"""en -> es OCR-translation through TranslateGemma's bundled chat
"""En -> es OCR-translation through TranslateGemma's bundled chat
template's ``image`` content branch. Exercises the multimodal branch of
``_collect_extra_fields`` in ``_parse_chat_message_content_part``: the
``source_lang_code`` / ``target_lang_code`` extras must survive parsing
and end up alongside the ``{"type": "image"}`` placeholder so the
template's image branch (``content["type"] == 'image'``) renders the
right OCR-translation prompt."""
right OCR-translation prompt.
"""
completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=[
@@ -191,7 +191,8 @@ async def test_logprob_token_ids_stream_with_no_top_k(server):
async def test_logprob_token_ids_default_behavior_unchanged(server):
"""Without `logprob_token_ids`, the response carries the natural top-k
most-likely tokens. This guards against the new field accidentally
changing the default-path output."""
changing the default-path output.
"""
async with server.get_async_client() as client:
resp = await client.chat.completions.create(
model=MODEL_NAME,
@@ -1232,7 +1232,6 @@ async def test_serving_chat_mistral_token_ids_prompt_is_validated():
"""Regression test: when the Mistral tokenizer path returns token IDs
directly, we must still apply input length + max_tokens validation.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig(skip_tokenizer_init=True)
@@ -1271,7 +1270,6 @@ async def test_serving_chat_mistral_token_ids_prompt_too_long_is_rejected():
"""Regression test: MistralTokenizer token-id prompts must still enforce
the max context length for the input itself (token_num >= max_model_len).
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig(skip_tokenizer_init=True)
@@ -1408,7 +1406,8 @@ async def test_serving_chat_did_set_correct_cache_salt(model_type):
@pytest.mark.asyncio
async def test_serving_chat_data_parallel_rank_extraction():
"""Test that data_parallel_rank is properly extracted from header and
passed to engine."""
passed to engine.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -1512,8 +1511,7 @@ async def _render_chat_prompt_token_ids(
class TestServingChatWithHarmony:
"""
These tests ensure Chat Completion requests are being properly converted into
"""These tests ensure Chat Completion requests are being properly converted into
Harmony messages and Harmony response messages back into Chat Completion responses.
These tests are not exhaustive, but each one was created to cover a specific case
that we got wrong but is now fixed.
@@ -1731,7 +1729,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_system_message_without_tools(self, serving_chat, stream):
"""Leading system message produces a developer message with
DeveloperContent (# Instructions header)."""
DeveloperContent (# Instructions header).
"""
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello"},
@@ -1753,7 +1752,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_system_message_with_tools(self, serving_chat, stream, weather_tools):
"""Leading system message is folded into the developer message
alongside tool definitions."""
alongside tool definitions.
"""
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What's the weather?"},
@@ -2168,7 +2168,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_tool_choice_validation_without_parser():
"""Test that tool_choice='required' or named tool without tool_parser
returns an appropriate error message."""
returns an appropriate error message.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -33,7 +33,6 @@ def _count_reasoning_decode_token_ids_between_markers(
reasoning_end_ids: list[int],
) -> int | None:
"""Count decode tokens in the thinking span (after last start, before first end)."""
if not reasoning_start_ids or not reasoning_end_ids:
raise ValueError("reasoning marker token id lists must be non-empty")
@@ -152,8 +151,8 @@ async def client(request, server, server_with_auto_reasoning_config):
@pytest.mark.parametrize("client", ["default", "auto_config"], indirect=True)
async def test_thinking_token_budget_mixed_requests(client: openai.AsyncOpenAI):
"""Test that mixed requests (some with thinking_token_budget, some without)
complete successfully without errors."""
complete successfully without errors.
"""
response_with_budget = await client.chat.completions.create(
model=MODEL_NAME,
messages=MESSAGES,
@@ -182,7 +181,6 @@ async def test_thinking_token_budget_limits_reasoning(client: openai.AsyncOpenAI
grouped into streamed chunks (a single chunk can carry several tokens under
async scheduling / stream_interval > 1). Counting chunks under-counts.
"""
tokenizer = get_tokenizer(tokenizer_name=MODEL_NAME)
start_ids = list(tokenizer.encode(REASONING_START_STR, add_special_tokens=False))
end_ids = list(tokenizer.encode(REASONING_END_STR, add_special_tokens=False))
@@ -227,7 +225,6 @@ async def test_thinking_token_budget_qwen35_fp8_mtp_concurrent_mixed_budget_and_
Qwen3.5 FP8 + MTP (TP=2) server. Budgeted calls are checked with
``_count_reasoning_decode_token_ids_between_markers`` on full token ids.
"""
_batch_spec: list[tuple[Literal["budget"], int] | tuple[Literal["plain"], None]] = [
("budget", 1),
("budget", 12),
@@ -350,7 +350,6 @@ async def test_parallel_no_streaming(client: openai.AsyncOpenAI, model_name: str
"""Parallel sampling without streaming.
A single request output contains a list of completions.
"""
prompt = "What is an LLM?"
n = 3
max_tokens = 50
@@ -396,7 +395,6 @@ async def test_parallel_streaming(client: openai.AsyncOpenAI, model_name: str):
The tokens from multiple samples, are flattened into a single stream,
with an index to indicate which sample the token belongs to.
"""
prompt = "What is an LLM?"
n = 3
max_tokens = 50
@@ -303,7 +303,7 @@ def test_completion_metrics_carries_both_timing_and_spec_decode():
@pytest.mark.asyncio
async def test_completion_error_non_stream():
"""test finish_reason='error' returns 500 InternalServerError (non-streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (non-streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -439,7 +439,7 @@ async def test_renderer_only_completion_request_skips_mm_cache():
@pytest.mark.asyncio
async def test_completion_error_stream():
"""test finish_reason='error' returns 500 InternalServerError (streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -521,7 +521,8 @@ async def test_completion_error_stream():
def test_json_schema_response_format_missing_schema():
"""When response_format type is 'json_schema' but the json_schema field
is not provided, request construction should raise a validation error
so the API returns 400 instead of 500."""
so the API returns 400 instead of 500.
"""
with pytest.raises(Exception, match="json_schema.*must be provided"):
CompletionRequest(
model=MODEL_NAME,
@@ -584,7 +585,8 @@ def test_negative_prompt_token_ids_flat():
def test_logprobs_minus_one_allowed():
"""logprobs=-1 means "return all logprobs". The sampling layer and the chat
top_logprobs / prompt_logprobs validators all accept -1, so the completion
logprobs validator must accept it too instead of rejecting it as negative."""
logprobs validator must accept it too instead of rejecting it as negative.
"""
request = CompletionRequest(
model=MODEL_NAME,
prompt="Test prompt",
@@ -744,7 +746,8 @@ class TestCompletionPromptListLimit:
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "logprobs"])
def test_non_numeric_logprobs_rejected(field_name):
"""A non-numeric logprobs value must be a clean 400 validation error, not a
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
"""
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
CompletionRequest(
model=MODEL_NAME,
@@ -39,8 +39,7 @@ def server():
@pytest.mark.asyncio
async def test_token_in_token_out_and_logprobs(server):
"""
Test token-in-token-out and token_ids align with prompt_logprobs
"""Test token-in-token-out and token_ids align with prompt_logprobs
& logprobs when return_tokens_as_token_ids is enabled.
"""
tokenizer = get_tokenizer(tokenizer_name=MODEL_NAME)
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
This file test accuracy of the vLLM server via LMEval.
"""This file test accuracy of the vLLM server via LMEval.
It uses local-completions, which interacts with vLLM
through the OAI API with N concurrent connections.
This simulates real work usage of the API and makes
@@ -37,7 +36,6 @@ if current_platform.is_tpu():
def run_test(more_args):
"""Run the end to end accuracy test."""
args = list(DEFAULT_ARGS)
args.extend(more_args)
print(f"Running with: {args}")
@@ -68,7 +66,6 @@ def run_test(more_args):
def test_lm_eval_accuracy_v1_engine():
"""Run with the V1 Engine."""
more_args = []
# Limit compilation time for V1 on TPU
@@ -43,7 +43,8 @@ def _system():
class TestResponseInputToHarmonyRenderParity:
"""Each test drives the same conversation through both APIs and asserts
identical Harmony messages and rendered token sequences."""
identical Harmony messages and rendered token sequences.
"""
# -----------------------------------------------------------------------
# Single-message cases
@@ -51,7 +52,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_developer_message(self):
"""Both APIs must render developer messages identically using
DeveloperContent (with the '# Instructions' header)."""
DeveloperContent (with the '# Instructions' header).
"""
chat_msgs = parse_chat_input_to_harmony_message(
{"role": "developer", "content": "Be concise."}
)
@@ -246,7 +248,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_reasoning_combined_with_function_call(self):
"""Chat API packs reasoning + tool_calls into one dict; responses API
represents them as two separate items. Both must produce the same two
Harmony messages in the same order: analysis then commentary."""
Harmony messages in the same order: analysis then commentary.
"""
chat_msgs = parse_chat_input_to_harmony_message(
{
"role": "assistant",
@@ -529,7 +532,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_completed_turns_drop_reasoning(self):
"""Validates that reasoning from completed turns is dropped, while
reasoning from the current in-progress tool-call turn is preserved
in both chat completions and responses previous_input_messages."""
in both chat completions and responses previous_input_messages.
"""
first_turn_reasoning = "FIRST_TURN_REASONING"
second_turn_reasoning = "SECOND_TURN_REASONING"
@@ -170,7 +170,7 @@ class TestIsFunctionRecipientWithAllowedNames:
"""Tests for is_function_recipient with allowed_function_tool_names."""
def test_prefixed_always_accepted(self):
"""functions. prefix is always accepted regardless of allowed names."""
"""Functions. prefix is always accepted regardless of allowed names."""
fn_names = frozenset({"other_tool"})
assert is_function_recipient("functions.get_weather", fn_names) is True
@@ -252,8 +252,7 @@ class TestExtractFunctionFromRecipient:
class TestCommonParseInputToHarmonyMessage:
"""
Tests for scenarios that are common to both Chat Completion
"""Tests for scenarios that are common to both Chat Completion
parse_chat_input_to_harmony_message and Responses API
response_previous_input_to_harmony functions.
"""
@@ -324,7 +323,8 @@ class TestCommonParseInputToHarmonyMessage:
def test_system_message(self, parse_function):
"""Test parsing system messages, which are parsed into developer messages
with DeveloperContent."""
with DeveloperContent.
"""
chat_msg = {
"role": "system",
"content": "You are a helpful assistant",
@@ -448,8 +448,7 @@ class TestCommonParseInputToHarmonyMessage:
class TestParseChatInputToHarmonyMessage:
"""
Tests for scenarios that are specific to the Chat Completion API
"""Tests for scenarios that are specific to the Chat Completion API
parse_chat_input_to_harmony_message function.
"""
@@ -14,7 +14,7 @@ from vllm.exceptions import GenerationError
@pytest.mark.asyncio
async def test_raise_if_error_raises_generation_error():
"""test _raise_if_error raises GenerationError"""
"""Test _raise_if_error raises GenerationError."""
# create a minimal GenerateBaseServing instance
mock_engine = MagicMock()
mock_engine.model_config = MagicMock()
@@ -42,7 +42,7 @@ async def test_raise_if_error_raises_generation_error():
@pytest.mark.asyncio
async def test_convert_generation_error_to_streaming_response():
"""test _convert_generation_error_to_streaming_response output"""
"""Test _convert_generation_error_to_streaming_response output."""
mock_engine = MagicMock()
mock_engine.model_config = MagicMock()
mock_engine.model_config.max_model_len = 100
@@ -168,8 +168,7 @@ async def test_max_tokens_with_tool_choice_required(
@pytest.mark.asyncio
async def test_named_tool_use(client: openai.AsyncOpenAI):
def get_weather(latitude: float, longitude: float) -> str:
"""
Mock function to simulate getting weather data.
"""Mock function to simulate getting weather data.
In a real application, this would call an external weather API.
"""
return f"Current temperature at ({latitude}, {longitude}) is 20°C."
@@ -12,7 +12,8 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
def test_function_call_dict_converted_to_object():
"""Test that function_call dictionaries are correctly parsed into
ResponseFunctionToolCall objects."""
ResponseFunctionToolCall objects.
"""
# Create a request with function_call as dict
request_data = {
"model": "gpt-oss",
@@ -57,7 +58,6 @@ def test_direct_function_call_object_preservation():
def test_mixed_input_types_with_function_calls():
"""Test parsing with mixed input types including function calls."""
request_data = {
"model": "gpt-oss",
"input": [
@@ -177,7 +177,6 @@ def test_empty_list_input():
def test_function_call_output_not_affected():
"""Test that FunctionCallOutput is not affected by the function_call parsing."""
# Test with FunctionCallOutput as dict (should not be parsed)
request_data = {
"model": "gpt-oss",
@@ -265,7 +264,6 @@ def test_function_call_validation_failure_logs_debug(caplog):
def test_validator_handles_iterator_input():
"""Test that validator can handle ValidatorIterator input (Pydantic internal)."""
# This test simulates when Pydantic passes a ValidatorIterator instead of a list
# This happened with complex nested structures containing reasoning + function_call
@@ -332,7 +330,8 @@ def test_validator_handles_empty_iterator():
def test_assistant_string_content_stays_easyinput():
"""EasyInput assistant message with plain string content is not
coerced into a ResponseOutputMessage."""
coerced into a ResponseOutputMessage.
"""
request_data = {
"model": "test-model",
"input": [
@@ -354,7 +353,8 @@ def test_assistant_string_content_stays_easyinput():
def test_assistant_output_style_content_coerced():
"""Assistant message whose content is output-message-shaped (list of
output_text items) should be coerced to ResponseOutputMessage."""
output_text items) should be coerced to ResponseOutputMessage.
"""
request_data = {
"model": "test-model",
"input": [
@@ -20,8 +20,7 @@ from vllm.exceptions import VLLMValidationError
class TestResponsePreviousInputToHarmony:
"""
Tests for scenarios that are specific to the Responses API
"""Tests for scenarios that are specific to the Responses API
response_previous_input_to_harmony function.
"""
@@ -67,7 +67,8 @@ class TestResponseInputToHarmonyMessage:
def test_system_message(self):
"""System messages carry developer instructions and must be rendered
as developer messages with DeveloperContent."""
as developer messages with DeveloperContent.
"""
msg = response_input_to_harmony(
{"type": "message", "role": "system", "content": "Be helpful."},
prev_responses=[],
@@ -89,7 +90,8 @@ class TestResponseInputToHarmonyMessage:
def test_developer_message_gets_instructions_prefix(self):
"""Developer messages must use DeveloperContent which adds the
'# Instructions' header the model was trained on."""
'# Instructions' header the model was trained on.
"""
msg = response_input_to_harmony(
{"type": "message", "role": "developer", "content": "Be concise."},
prev_responses=[],
@@ -119,7 +121,8 @@ class TestResponseInputToHarmonyMessage:
def test_developer_message_array_content_concatenated(self):
"""Array content in developer messages is flattened and rendered
via DeveloperContent with the '# Instructions' header."""
via DeveloperContent with the '# Instructions' header.
"""
msg = response_input_to_harmony(
{
"type": "message",
@@ -210,7 +213,8 @@ class TestResponseInputToHarmonyMessage:
def test_function_call_output_uses_most_recent_matching_call(self):
"""When multiple prev_responses share a call_id, the last one wins
because the search is reversed."""
because the search is reversed.
"""
earlier = ResponseFunctionToolCall(
id="fc_old",
call_id="call_test",
@@ -839,11 +839,13 @@ class TestConstructChatMessagesCombinePolicy:
class TestConstructInputMessagesInstructionsLeak:
"""Regression tests for #37697: instructions from a prior response
should NOT leak through previous_response_id."""
should NOT leak through previous_response_id.
"""
def test_old_instructions_stripped_from_prev_msg(self):
"""System message in prev_msg must be dropped so the new request's
instructions are the only system message in the conversation."""
instructions are the only system message in the conversation.
"""
prev = [
{"role": "system", "content": "old instructions"},
{"role": "user", "content": "What is 2+2?"},
@@ -860,7 +862,8 @@ class TestConstructInputMessagesInstructionsLeak:
def test_no_instructions_in_new_request(self):
"""If the new request has no instructions, old ones should still
be stripped -- they must not carry over."""
be stripped -- they must not carry over.
"""
prev = [
{"role": "system", "content": "old instructions"},
{"role": "user", "content": "Hi"},
@@ -81,7 +81,7 @@ def _new_online_renderer() -> OnlineRenderer:
class MockConversationContext(ConversationContext):
"""Mock conversation context for testing"""
"""Mock conversation context for testing."""
def __init__(self):
self.init_tool_sessions_called = False
@@ -123,7 +123,7 @@ def test_serialize_message_pydantic_model_returns_dict() -> None:
@pytest.fixture
def mock_serving_responses():
"""Create a mock OpenAIServingResponses instance"""
"""Create a mock OpenAIServingResponses instance."""
serving_responses = MagicMock(spec=OpenAIServingResponses)
serving_responses.tool_server = MagicMock(spec=ToolServer)
return serving_responses
@@ -131,13 +131,13 @@ def mock_serving_responses():
@pytest.fixture
def mock_context():
"""Create a mock conversation context"""
"""Create a mock conversation context."""
return MockConversationContext()
@pytest.fixture
def mock_exit_stack():
"""Create a mock async exit stack"""
"""Create a mock async exit stack."""
return MagicMock(spec=AsyncExitStack)
@@ -550,7 +550,7 @@ def test_responses_render_result_rejects_non_single_prompt(engine_inputs):
class TestInitializeToolSessions:
"""Test class for _initialize_tool_sessions method"""
"""Test class for _initialize_tool_sessions method."""
@pytest.fixture(params=[ParsableContext, HarmonyContext])
def tool_context(self, request):
@@ -635,7 +635,7 @@ class TestInitializeToolSessions:
@pytest_asyncio.fixture
async def serving_responses_instance(self):
"""Create a real OpenAIServingResponses instance for testing"""
"""Create a real OpenAIServingResponses instance for testing."""
# Create minimal mocks for required dependencies
engine_client = MagicMock()
@@ -802,8 +802,7 @@ class TestInitializeToolSessions:
async def test_initialize_tool_sessions(
self, serving_responses_instance, mock_context, mock_exit_stack
):
"""Test that method works correctly with only MCP tools"""
"""Test that method works correctly with only MCP tools."""
request = ResponsesRequest(input="test input", tools=[])
# Call the method
@@ -852,11 +851,11 @@ class TestInitializeToolSessions:
class TestValidateGeneratorInput:
"""Test class for _validate_generator_input method"""
"""Test class for _validate_generator_input method."""
@pytest_asyncio.fixture
async def serving_responses_instance(self):
"""Create a real OpenAIServingResponses instance for testing"""
"""Create a real OpenAIServingResponses instance for testing."""
# Create minimal mocks for required dependencies
engine_client = MagicMock()
@@ -884,7 +883,7 @@ class TestValidateGeneratorInput:
return instance
def test_validate_generator_input(self, serving_responses_instance):
"""Test _validate_generator_input with valid prompt length"""
"""Test _validate_generator_input with valid prompt length."""
# Create an engine prompt with valid length (less than max_model_len)
valid_prompt_token_ids = list(range(5)) # 5 tokens < 100 max_model_len
engine_input = tokens_input(valid_prompt_token_ids)
@@ -999,7 +998,7 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
class TestExtractAllowedToolsFromMcpRequests:
"""Test class for _extract_allowed_tools_from_mcp_requests function"""
"""Test class for _extract_allowed_tools_from_mcp_requests function."""
def test_extract_allowed_tools_basic_formats(self):
"""Test extraction with list format, object format, and None."""
@@ -1113,7 +1112,7 @@ class TestHarmonyPreambleStreaming:
return item
def test_preamble_delta_emits_text_events(self) -> None:
"""commentary + recipient=None should emit output_text.delta events."""
"""Commentary + recipient=None should emit output_text.delta events."""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_content_delta_events,
)
@@ -1146,7 +1145,7 @@ class TestHarmonyPreambleStreaming:
assert "response.output_item.added" not in type_names
def test_commentary_with_function_recipient_not_preamble(self) -> None:
"""commentary + recipient='functions.X' must NOT use preamble path."""
"""Commentary + recipient='functions.X' must NOT use preamble path."""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_content_delta_events,
)
@@ -1164,7 +1163,8 @@ class TestHarmonyPreambleStreaming:
def test_preamble_done_emits_text_done_events(self) -> None:
"""Completed preamble should emit text done + content_part done +
output_item done, same shape as final channel."""
output_item done, same shape as final channel.
"""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_previous_item_done_events,
)
@@ -1184,8 +1184,9 @@ class TestHarmonyPreambleStreaming:
assert "response.output_item.done" in type_names
def test_commentary_with_recipient_no_preamble_done(self) -> None:
"""commentary + recipient='functions.X' should route to function call
done, not preamble done."""
"""Commentary + recipient='functions.X' should route to function call
done, not preamble done.
"""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_previous_item_done_events,
)
@@ -1331,7 +1332,8 @@ def _mock_parser_with_reasoning(serving, delta_sequence: list[DeltaMessage]):
class TestStreamingReasoningToContentTransition:
"""Tests for _process_simple_streaming_events reasoning-to-content
transition, specifically the fix for mixed deltas that carry both
reasoning and content simultaneously."""
reasoning and content simultaneously.
"""
@pytest.mark.asyncio
async def test_mixed_delta_reasoning_and_content_emits_reasoning_delta(
@@ -1341,8 +1343,8 @@ class TestStreamingReasoningToContentTransition:
and content set (e.g. reasoning end and content start in the same
chunk), the trailing reasoning text must be emitted as a
ResponseReasoningTextDeltaEvent and included in the
ResponseReasoningTextDoneEvent text."""
ResponseReasoningTextDoneEvent text.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -1411,8 +1413,8 @@ class TestStreamingReasoningToContentTransition:
self, monkeypatch
):
"""When the transition from reasoning to content is clean (no mixed
delta), no extra reasoning delta event should be emitted."""
delta), no extra reasoning delta event should be emitted.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -1473,8 +1475,8 @@ class TestStreamingReasoningToContentTransition:
async def test_reasoning_only_stream_no_content(self, monkeypatch):
"""When the stream has only reasoning deltas and no content, the
reasoning done event should be emitted at finalization with the
full accumulated text, and no text delta events should appear."""
full accumulated text, and no text delta events should appear.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -143,7 +143,8 @@ async def test_streaming_output_consistency(client: OpenAI, model_name: str):
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_streaming_logprobs(client: OpenAI, model_name: str):
"""Test that streaming with logprobs returns valid logprob data on
output_text.delta events and that top_logprobs has the requested count."""
output_text.delta events and that top_logprobs has the requested count.
"""
response = await client.responses.create(
model=model_name,
input="Say hello.",
@@ -124,7 +124,8 @@ class TestProcessorCompoundDeltas:
def test_split_name_and_args_same_index(self):
"""Regression: parsers like KimiK2 emit name and args as separate
DeltaToolCalls at the same index within one DeltaMessage."""
DeltaToolCalls at the same index within one DeltaMessage.
"""
tc_name = _make_tool_call(0, name="get_weather")
tc_args = _make_tool_call(0, arguments='{"city":"SF"}')
delta = DeltaMessage(tool_calls=[tc_name, tc_args])
@@ -140,7 +141,8 @@ class TestProcessorCompoundDeltas:
def test_reasoning_to_content_transition(self):
"""Regression: the old special case in emit_delta handled this;
now split_delta handles it generically."""
now split_delta handles it generically.
"""
processor = SimpleStreamingEventProcessor()
_run_through_processor(processor, DeltaMessage(reasoning="think"))
assert processor.state.current_state == _StateType.REASONING
@@ -83,8 +83,7 @@ def before_generate_case(context: schemathesis.HookContext, strategy):
assert op is not None
def no_invalid_types(case: schemathesis.Case):
"""
Skips tool_calls with `"type": "custom"` which schemathesis incorrectly
"""Skips tool_calls with `"type": "custom"` which schemathesis incorrectly
generates instead of the valid `"type": "function"`.
Example test case that is skipped:
@@ -25,7 +25,8 @@ def _model_config() -> Mock:
def test_completion_flag_forwarded_to_tok_params():
"""build_tok_params must forward return_token_offsets, defaulting to
False (zero behavioral change for existing callers) and coercing JSON
null to False via the bool() guard."""
null to False via the bool() guard.
"""
cfg = _model_config()
default = CompletionRequest(model="m", prompt="hi")
@@ -40,7 +41,8 @@ def test_completion_flag_forwarded_to_tok_params():
def test_chat_flag_forwarded_to_tok_params():
"""Chat build_tok_params has its own (max_completion_tokens) branch, so
its return_token_offsets forwarding is verified independently."""
its return_token_offsets forwarding is verified independently.
"""
cfg = _model_config()
messages = [{"role": "user", "content": "hi"}]
@@ -64,7 +66,8 @@ def test_generate_request_token_offsets_default_none():
def test_generate_request_token_offsets_survive_json_round_trip():
"""GenerateRequest crosses the disagg serialization boundary; the
tuple[int, int] offsets must survive model_dump and re-validate."""
tuple[int, int] offsets must survive model_dump and re-validate.
"""
req = GenerateRequest(
token_ids=[10, 20],
sampling_params=SamplingParams(),
@@ -189,8 +189,7 @@ async def test_chat_completion_with_tool_use(server):
@pytest.mark.asyncio
async def test_comparison_with_prompt_logprobs_and_logprobs(server):
"""
Test that token_ids align with prompt_logprobs and
"""Test that token_ids align with prompt_logprobs and
logprobs when return_tokens_as_token_ids is enabled.
"""
async with server.get_async_client() as client:
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for stop_token_ids propagation from default_sampling_params
"""Unit tests for stop_token_ids propagation from default_sampling_params
to SamplingParams in ChatCompletionRequest and CompletionRequest.
Regression test for https://github.com/vllm-project/vllm/issues/22519
+1 -2
View File
@@ -16,8 +16,7 @@ from vllm.entrypoints.serve.engine.protocol import UsageInfo
async def accumulate_streaming_response(
stream_generator: AsyncGenerator[str, None],
) -> ChatCompletionResponse:
"""
Accumulate streaming SSE chunks into a complete ChatCompletionResponse.
"""Accumulate streaming SSE chunks into a complete ChatCompletionResponse.
This helper parses the SSE format and builds up the complete response
by combining all the delta chunks.