Avoid expensive inspect calls in config validators (#112085)
* Avoid expensive inspect calls in config validators inspect has a performance problem https://github.com/python/cpython/issues/92041 We now avoid calling inspect unless we are going to log * remove unused * reduce * get_integration_logger
This commit is contained in:
parent
9353ad0690
commit
6421a08ba8
5 changed files with 101 additions and 59 deletions
|
@ -22,6 +22,14 @@ async def test_extract_frame_integration(
|
|||
)
|
||||
|
||||
|
||||
async def test_get_integration_logger(
|
||||
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
) -> None:
|
||||
"""Test extracting the current frame to get the logger."""
|
||||
logger = frame.get_integration_logger(__name__)
|
||||
assert logger.name == "homeassistant.components.hue"
|
||||
|
||||
|
||||
async def test_extract_frame_resolve_module(
|
||||
hass: HomeAssistant, enable_custom_integrations
|
||||
) -> None:
|
||||
|
@ -39,6 +47,17 @@ async def test_extract_frame_resolve_module(
|
|||
)
|
||||
|
||||
|
||||
async def test_get_integration_logger_resolve_module(
|
||||
hass: HomeAssistant, enable_custom_integrations
|
||||
) -> None:
|
||||
"""Test getting the logger from integration context."""
|
||||
from custom_components.test_integration_frame import call_get_integration_logger
|
||||
|
||||
logger = call_get_integration_logger(__name__)
|
||||
|
||||
assert logger.name == "custom_components.test_integration_frame"
|
||||
|
||||
|
||||
async def test_extract_frame_integration_with_excluded_integration(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
|
@ -102,6 +121,30 @@ async def test_extract_frame_no_integration(caplog: pytest.LogCaptureFixture) ->
|
|||
frame.get_integration_frame()
|
||||
|
||||
|
||||
async def test_get_integration_logger_no_integration(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test getting fallback logger without integration context."""
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
Mock(
|
||||
filename="/home/paulus/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
Mock(
|
||||
filename="/home/paulus/aiohue/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
],
|
||||
):
|
||||
logger = frame.get_integration_logger(__name__)
|
||||
|
||||
assert logger.name == __name__
|
||||
|
||||
|
||||
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
|
||||
async def test_prevent_flooding(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue