Repository: pydantic/pydantic-ai
File: tests/models/test_outlines.py (Python)

Code before:
            assert isinstance(text, str)
            assert len(text) > 0


async def test_tool_definition_error_async_model(mock_async_model: OutlinesModel) -> None:
    """Test that function tools raise UserError with async model (covers outlines.py:303)."""
    agent = Agent(mock_async_model)

    @agent.tool_plain
    def dummy_tool() -> str:  # pragma: no cover
        return 'dummy'

    with pytest.raises(UserError, match='Outlines does not support function tools yet.'):
        await agent.run('Hello')


async def test_output_type_async_model(mock_async_model: OutlinesModel) -> None:
    """Test output_type with async model exercises JsonSchema path (covers outlines.py:306)."""

    class Box(BaseModel):
        width: int

    agent = Agent(mock_async_model, output_type=Box)
    # Mock returns 'test' which isn't valid JSON, so validation fails
    # But line 306 (output_type = JsonSchema(...)) is still exercised
    with pytest.raises(Exception):
        await agent.run('dimensions')


async def test_instructions_async_model(mock_async_model: OutlinesModel) -> None:
    """Test that instructions are passed to the model (covers outlines.py:430)."""
    agent = Agent(mock_async_model, instructions='Be brief.')
    result = await agent.run('Hello')
    assert result.output == 'test'


async def test_multi_turn_async_model(mock_async_model: OutlinesModel) -> None:
    """Test multi-turn conversation with message_history (covers outlines.py:490)."""
    agent = Agent(mock_async_model)
    result1 = await agent.run('First message')
    # The message_history includes a ModelResponse with TextPart, which triggers line 490
    result2 = await agent.run('Second message', message_history=result1.all_messages())
    assert result2.output == 'test'


@skip_if_transformers_imports_unsuccessful
def test_request_image_binary(transformers_multimodal_model: OutlinesModel, binary_image: BinaryImage) -> None:
    agent = Agent(transformers_multimodal_model)
    result = agent.run_sync(
        ["What's on the image?", binary_image], model_settings=ModelSettings(extra_body={'max_new_tokens': 100})
    )

Review comment (suggestion):
- No references to line numbers as they'll get outdated -- Claude really likes to do this 😄 
- Please catch a more precise error, this could be hiding other/real issues

Code after:
            assert isinstance(text, str)
            assert len(text) > 0


async def test_tool_definition_error_async_model(mock_async_model: OutlinesModel) -> None:
    """Test that function tools raise UserError with async model."""
    agent = Agent(mock_async_model)

    @agent.tool_plain
    def dummy_tool() -> str:  # pragma: no cover
        return 'dummy'

    with pytest.raises(UserError, match='Outlines does not support function tools yet.'):
        await agent.run('Hello')


async def test_output_type_async_model(mock_async_model: OutlinesModel) -> None:
    """Test output_type with async model exercises JsonSchema path."""

    class Box(BaseModel):
        width: int

    agent = Agent(mock_async_model, output_type=Box)
    # Mock returns 'test' which isn't valid JSON, so validation fails
    with pytest.raises(UnexpectedModelBehavior, match='Exceeded maximum retries .* for output validation'):
        await agent.run('dimensions')


async def test_instructions_async_model(mock_async_model: OutlinesModel) -> None:
    """Test that instructions are passed to the model."""
    agent = Agent(mock_async_model, instructions='Be brief.')
    result = await agent.run('Hello')
    assert result.output == 'test'
    assert result.all_messages() == snapshot(
        [
            ModelRequest(
                parts=[UserPromptPart(content='Hello', timestamp=IsDatetime())],
                instructions='Be brief.',
                timestamp=IsDatetime(),
                run_id=IsStr(),
            ),
            ModelResponse(parts=[TextPart(content='test')], timestamp=IsDatetime(), run_id=IsStr()),
        ]
    )


async def test_multi_turn_async_model(mock_async_model: OutlinesModel) -> None:
    """Test multi-turn conversation with message_history."""
    agent = Agent(mock_async_model)
    result1 = await agent.run('First message')
    result2 = await agent.run('Second message', message_history=result1.all_messages())