Skip to content

Commit c84be82

Browse files
committed
add coverage-n
1 parent 306514e commit c84be82

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

pydantic_ai_slim/pydantic_ai/builtin_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class AbstractBuiltinTool(ABC):
1818
The builtin tools are passed to the model as part of the `ModelRequestParameters`.
1919
"""
2020

21+
# TODO(Marcelo): We need to handle custom tool definitions per model base.
2122
def handle_custom_tool_definition(self, model: str) -> Any: ...
2223

2324

pydantic_ai_slim/pydantic_ai/models/anthropic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def _get_builtin_tools(self, model_request_parameters: ModelRequestParameters) -
361361
user_location=user_location,
362362
)
363363
)
364-
elif isinstance(tool, CodeExecutionTool):
364+
elif isinstance(tool, CodeExecutionTool): # pragma: no branch
365365
tools.append(BetaCodeExecutionTool20250522Param(name='code_execution', type='code_execution_20250522'))
366366
return tools
367367

@@ -627,7 +627,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
627627
elif isinstance(event, BetaRawMessageDeltaEvent):
628628
pass
629629

630-
elif isinstance(event, (BetaRawContentBlockStopEvent, BetaRawMessageStopEvent)):
630+
elif isinstance(event, (BetaRawContentBlockStopEvent, BetaRawMessageStopEvent)): # pragma: no branch
631631
current_block = None
632632

633633
@property

pydantic_ai_slim/pydantic_ai/models/cohere.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ def _map_messages(self, messages: list[ModelMessage]) -> list[ChatMessageV2]:
225225
pass
226226
elif isinstance(item, ToolCallPart):
227227
tool_calls.append(self._map_tool_call(item))
228-
elif isinstance(item, ServerToolCallPart):
228+
elif isinstance(item, ServerToolCallPart): # pragma: no cover
229229
# ServerToolCallPart represents a tool call from a remote server
230230
# Never returned from cohere
231231
pass
232-
elif isinstance(item, ServerToolReturnPart):
232+
elif isinstance(item, ServerToolReturnPart): # pragma: no cover
233233
# ServerToolReturnPart represents a tool return from a remote server
234234
# Never returned from cohere
235235
pass

pydantic_ai_slim/pydantic_ai/models/function.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ def _estimate_usage(messages: Iterable[ModelMessage]) -> usage.Usage:
307307
elif isinstance(part, ToolCallPart):
308308
call = part
309309
response_tokens += 1 + _estimate_string_tokens(call.args_as_json_str())
310-
elif isinstance(part, ServerToolCallPart):
310+
# TODO(Marcelo): We need to add coverage here.
311+
elif isinstance(part, ServerToolCallPart): # pragma: no cover
311312
call = part
312313
response_tokens += 1 + _estimate_string_tokens(call.args_as_json_str())
313-
elif isinstance(part, ServerToolReturnPart):
314+
# TODO(Marcelo): We need to add coverage here.
315+
elif isinstance(part, ServerToolReturnPart): # pragma: no cover
314316
response_tokens += _estimate_string_tokens(part.model_response_str())
315317
else:
316318
assert_never(part)

pydantic_ai_slim/pydantic_ai/models/gemini.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,11 @@ def _content_model_response(m: ModelResponse) -> _GeminiContent:
624624
elif isinstance(item, TextPart):
625625
if item.content:
626626
parts.append(_GeminiTextPart(text=item.content))
627-
elif isinstance(item, ServerToolCallPart):
627+
elif isinstance(item, ServerToolCallPart): # pragma: no cover
628628
# Handle ServerToolCallPart the same as ToolCallPart
629629
# Never returned from gemini
630630
pass
631-
elif isinstance(item, ServerToolReturnPart):
631+
elif isinstance(item, ServerToolReturnPart): # pragma: no cover
632632
# Convert ServerToolReturnPart to a function response part
633633
# Never returned from gemini
634634
pass

pydantic_ai_slim/pydantic_ai/models/groq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCompletio
317317
elif isinstance(item, ThinkingPart):
318318
# Skip thinking parts when mapping to Groq messages
319319
continue
320-
elif isinstance(item, ServerToolCallPart):
320+
elif isinstance(item, ServerToolCallPart): # pragma: no cover
321321
# ServerToolCallPart is handled separately in server-side tools
322322
# Never returned from groq
323323
pass
324-
elif isinstance(item, ServerToolReturnPart):
324+
elif isinstance(item, ServerToolReturnPart): # pragma: no cover
325325
# ServerToolReturnPart is handled separately in server-side tools
326326
# Never returned from groq
327327
pass

pydantic_ai_slim/pydantic_ai/models/mistral.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ def _map_messages(self, messages: list[ModelMessage]) -> list[MistralMessages]:
503503
pass
504504
elif isinstance(part, ToolCallPart):
505505
tool_calls.append(self._map_tool_call(part))
506-
elif isinstance(part, ServerToolCallPart):
506+
elif isinstance(part, ServerToolCallPart): # pragma: no cover
507507
# Handle ServerToolCallPart the same as ToolCallPart
508508
# Never returned from mistral
509509
pass
510-
elif isinstance(part, ServerToolReturnPart):
510+
elif isinstance(part, ServerToolReturnPart): # pragma: no cover
511511
# For now, we'll add ServerToolReturnPart as text content
512512
# Never returned from mistral
513513
pass

pydantic_ai_slim/pydantic_ai/models/openai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def _get_tools(self, model_request_parameters: ModelRequestParameters) -> list[c
418418

419419
def _get_web_search_options(self, model_request_parameters: ModelRequestParameters) -> WebSearchOptions | None:
420420
for tool in model_request_parameters.builtin_tools:
421-
if isinstance(tool, WebSearchTool):
421+
if isinstance(tool, WebSearchTool): # pragma: no branch
422422
if tool.user_location:
423423
return WebSearchOptions(
424424
search_context_size=tool.search_context_size,
@@ -450,7 +450,7 @@ async def _map_messages(self, messages: list[ModelMessage]) -> list[chat.ChatCom
450450
elif isinstance(item, ToolCallPart):
451451
tool_calls.append(self._map_tool_call(item))
452452
# OpenAI doesn't return server tools calls.
453-
elif isinstance(item, (ServerToolCallPart, ServerToolReturnPart)):
453+
elif isinstance(item, (ServerToolCallPart, ServerToolReturnPart)): # pragma: no cover
454454
continue
455455
else:
456456
assert_never(item)

tests/models/test_anthropic.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,11 +1517,8 @@ async def test_anthropic_code_execution_tool(allow_model_requests: None, anthrop
15171517
async def test_anthropic_server_tool_pass_history_to_another_provider(
15181518
allow_model_requests: None, anthropic_api_key: str, openai_api_key: str
15191519
):
1520-
try:
1521-
from pydantic_ai.models.openai import OpenAIResponsesModel
1522-
from pydantic_ai.providers.openai import OpenAIProvider
1523-
except ImportError:
1524-
pytest.skip('OpenAI is not installed')
1520+
from pydantic_ai.models.openai import OpenAIResponsesModel
1521+
from pydantic_ai.providers.openai import OpenAIProvider
15251522

15261523
openai_model = OpenAIResponsesModel('gpt-4.1', provider=OpenAIProvider(api_key=openai_api_key))
15271524
anthropic_model = AnthropicModel('claude-3-5-sonnet-latest', provider=AnthropicProvider(api_key=anthropic_api_key))

0 commit comments

Comments
 (0)