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:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user