1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Enable Ruff PT012 (#113957)

This commit is contained in:
Sid
2024-06-08 17:59:08 +02:00
committed by GitHub
parent 915658daa1
commit 721b2c2ca8
90 changed files with 341 additions and 429 deletions

View File

@@ -94,22 +94,20 @@ async def test_generate_content_service_error(
mock_config_entry: MockConfigEntry,
) -> None:
"""Test generate content service handles errors."""
with (
patch("google.generativeai.GenerativeModel") as mock_model,
pytest.raises(
HomeAssistantError, match="Error generating content: None reason"
),
):
with patch("google.generativeai.GenerativeModel") as mock_model:
mock_model.return_value.generate_content_async = AsyncMock(
side_effect=ClientError("reason")
)
await hass.services.async_call(
"google_generative_ai_conversation",
"generate_content",
{"prompt": "write a story about an epic fail"},
blocking=True,
return_response=True,
)
with pytest.raises(
HomeAssistantError, match="Error generating content: None reason"
):
await hass.services.async_call(
"google_generative_ai_conversation",
"generate_content",
{"prompt": "write a story about an epic fail"},
blocking=True,
return_response=True,
)
@pytest.mark.usefixtures("mock_init_component")
@@ -120,20 +118,20 @@ async def test_generate_content_response_has_empty_parts(
"""Test generate content service handles response with empty parts."""
with (
patch("google.generativeai.GenerativeModel") as mock_model,
pytest.raises(HomeAssistantError, match="Error generating content"),
):
mock_response = MagicMock()
mock_response.parts = []
mock_model.return_value.generate_content_async = AsyncMock(
return_value=mock_response
)
await hass.services.async_call(
"google_generative_ai_conversation",
"generate_content",
{"prompt": "write a story about an epic fail"},
blocking=True,
return_response=True,
)
with pytest.raises(HomeAssistantError, match="Error generating content"):
await hass.services.async_call(
"google_generative_ai_conversation",
"generate_content",
{"prompt": "write a story about an epic fail"},
blocking=True,
return_response=True,
)
async def test_generate_content_service_with_image_not_allowed_path(