mirror of
https://github.com/home-assistant/core.git
synced 2026-09-11 10:06:07 -05:00
Use loader.async_suggest_report_issue in frame helper (#101461)
This commit is contained in:
@@ -21,7 +21,7 @@ from homeassistant.core import EVENT_HOMEASSISTANT_CLOSE, HomeAssistant
|
||||
import homeassistant.helpers.aiohttp_client as client
|
||||
from homeassistant.util.color import RGBColor
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@@ -155,9 +155,10 @@ async def test_warning_close_session_integration(
|
||||
session = client.async_get_clientsession(hass)
|
||||
await session.close()
|
||||
assert (
|
||||
"Detected integration that closes the Home Assistant aiohttp session. "
|
||||
"Please report issue for hue using this method at "
|
||||
"homeassistant/components/hue/light.py, line 23: await session.close()"
|
||||
"Detected that integration 'hue' closes the Home Assistant aiohttp session at "
|
||||
"homeassistant/components/hue/light.py, line 23: await session.close(), "
|
||||
"please create a bug report at https://github.com/home-assistant/core/issues?"
|
||||
"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@@ -166,6 +167,7 @@ async def test_warning_close_session_custom(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test log warning message when closing the session from custom context."""
|
||||
mock_integration(hass, MockModule("hue"), built_in=False)
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
@@ -189,10 +191,10 @@ async def test_warning_close_session_custom(
|
||||
session = client.async_get_clientsession(hass)
|
||||
await session.close()
|
||||
assert (
|
||||
"Detected integration that closes the Home Assistant aiohttp session. Please"
|
||||
" report issue to the custom integration author for hue using this method at"
|
||||
" custom_components/hue/light.py, line 23: await session.close()" in caplog.text
|
||||
)
|
||||
"Detected that custom integration 'hue' closes the Home Assistant aiohttp "
|
||||
"session at custom_components/hue/light.py, line 23: await session.close(), "
|
||||
"please report it to the author of the 'hue' custom integration"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
async def test_async_aiohttp_proxy_stream(
|
||||
|
||||
@@ -132,7 +132,7 @@ async def test_extract_frame_no_integration(caplog: pytest.LogCaptureFixture) ->
|
||||
|
||||
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
|
||||
async def test_prevent_flooding(
|
||||
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
) -> None:
|
||||
"""Test to ensure a report is only written once to the log."""
|
||||
|
||||
@@ -142,9 +142,10 @@ async def test_prevent_flooding(
|
||||
filename = "homeassistant/components/hue/light.py"
|
||||
|
||||
expected_message = (
|
||||
f"Detected integration that {what}. Please report issue for {integration} using"
|
||||
f" this method at {filename}, line "
|
||||
f"{mock_integration_frame.lineno}: {mock_integration_frame.line}"
|
||||
f"Detected that integration '{integration}' {what} at {filename}, line "
|
||||
f"{mock_integration_frame.lineno}: {mock_integration_frame.line}, "
|
||||
f"please create a bug report at https://github.com/home-assistant/core/issues?"
|
||||
f"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+{integration}%22"
|
||||
)
|
||||
|
||||
frame.report(what, error_if_core=False)
|
||||
|
||||
@@ -7,6 +7,8 @@ import pytest
|
||||
from homeassistant.core import EVENT_HOMEASSISTANT_CLOSE, HomeAssistant
|
||||
import homeassistant.helpers.httpx_client as client
|
||||
|
||||
from tests.common import MockModule, mock_integration
|
||||
|
||||
|
||||
async def test_get_async_client_with_ssl(hass: HomeAssistant) -> None:
|
||||
"""Test init async client with ssl."""
|
||||
@@ -125,9 +127,10 @@ async def test_warning_close_session_integration(
|
||||
await httpx_session.aclose()
|
||||
|
||||
assert (
|
||||
"Detected integration that closes the Home Assistant httpx client. "
|
||||
"Please report issue for hue using this method at "
|
||||
"homeassistant/components/hue/light.py, line 23: await session.aclose()"
|
||||
"Detected that integration 'hue' closes the Home Assistant httpx client at "
|
||||
"homeassistant/components/hue/light.py, line 23: await session.aclose(), "
|
||||
"please create a bug report at https://github.com/home-assistant/core/issues?"
|
||||
"q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+hue%22"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@@ -136,6 +139,7 @@ async def test_warning_close_session_custom(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test log warning message when closing the session from custom context."""
|
||||
mock_integration(hass, MockModule("hue"), built_in=False)
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
@@ -159,8 +163,7 @@ async def test_warning_close_session_custom(
|
||||
httpx_session = client.get_async_client(hass)
|
||||
await httpx_session.aclose()
|
||||
assert (
|
||||
"Detected integration that closes the Home Assistant httpx client. Please"
|
||||
" report issue to the custom integration author for hue using this method at"
|
||||
" custom_components/hue/light.py, line 23: await session.aclose()"
|
||||
in caplog.text
|
||||
)
|
||||
"Detected that custom integration 'hue' closes the Home Assistant httpx client "
|
||||
"at custom_components/hue/light.py, line 23: await session.aclose(), "
|
||||
"please report it to the author of the 'hue' custom integration"
|
||||
) in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user