Speed up the frame helper (#112562)
This commit is contained in:
parent
3ccbb2c87a
commit
1fb9cfe37e
12 changed files with 460 additions and 338 deletions
|
@ -7,6 +7,8 @@ import pytest
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import frame
|
||||
|
||||
from tests.common import extract_stack_to_frame
|
||||
|
||||
|
||||
async def test_extract_frame_integration(
|
||||
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
|
||||
|
@ -15,7 +17,7 @@ async def test_extract_frame_integration(
|
|||
integration_frame = frame.get_integration_frame()
|
||||
assert integration_frame == frame.IntegrationFrame(
|
||||
custom_integration=False,
|
||||
frame=mock_integration_frame,
|
||||
_frame=mock_integration_frame,
|
||||
integration="hue",
|
||||
module=None,
|
||||
relative_filename="homeassistant/components/hue/light.py",
|
||||
|
@ -40,7 +42,7 @@ async def test_extract_frame_resolve_module(
|
|||
|
||||
assert integration_frame == frame.IntegrationFrame(
|
||||
custom_integration=True,
|
||||
frame=ANY,
|
||||
_frame=ANY,
|
||||
integration="test_integration_frame",
|
||||
module="custom_components.test_integration_frame",
|
||||
relative_filename="custom_components/test_integration_frame/__init__.py",
|
||||
|
@ -68,25 +70,27 @@ async def test_extract_frame_integration_with_excluded_integration(
|
|||
line="self.light.is_on",
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
Mock(
|
||||
filename="/home/dev/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
correct_frame,
|
||||
Mock(
|
||||
filename="/home/dev/homeassistant/components/zeroconf/usage.py",
|
||||
lineno="23",
|
||||
line="self.light.is_on",
|
||||
),
|
||||
Mock(
|
||||
filename="/home/dev/mdns/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
],
|
||||
"homeassistant.helpers.frame.get_current_frame",
|
||||
return_value=extract_stack_to_frame(
|
||||
[
|
||||
Mock(
|
||||
filename="/home/dev/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
correct_frame,
|
||||
Mock(
|
||||
filename="/home/dev/homeassistant/components/zeroconf/usage.py",
|
||||
lineno="23",
|
||||
line="self.light.is_on",
|
||||
),
|
||||
Mock(
|
||||
filename="/home/dev/mdns/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
]
|
||||
),
|
||||
):
|
||||
integration_frame = frame.get_integration_frame(
|
||||
exclude_integrations={"zeroconf"}
|
||||
|
@ -94,7 +98,7 @@ async def test_extract_frame_integration_with_excluded_integration(
|
|||
|
||||
assert integration_frame == frame.IntegrationFrame(
|
||||
custom_integration=False,
|
||||
frame=correct_frame,
|
||||
_frame=correct_frame,
|
||||
integration="mdns",
|
||||
module=None,
|
||||
relative_filename="homeassistant/components/mdns/light.py",
|
||||
|
@ -104,19 +108,21 @@ async def test_extract_frame_integration_with_excluded_integration(
|
|||
async def test_extract_frame_no_integration(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test extracting the current frame 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()",
|
||||
),
|
||||
],
|
||||
"homeassistant.helpers.frame.get_current_frame",
|
||||
return_value=extract_stack_to_frame(
|
||||
[
|
||||
Mock(
|
||||
filename="/home/paulus/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
Mock(
|
||||
filename="/home/paulus/aiohue/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
]
|
||||
),
|
||||
), pytest.raises(frame.MissingIntegrationFrame):
|
||||
frame.get_integration_frame()
|
||||
|
||||
|
@ -126,19 +132,21 @@ async def test_get_integration_logger_no_integration(
|
|||
) -> 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()",
|
||||
),
|
||||
],
|
||||
"homeassistant.helpers.frame.get_current_frame",
|
||||
return_value=extract_stack_to_frame(
|
||||
[
|
||||
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__)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue