Patch aiohttp client session close (#34769)
* Patch aiohttp client session close * Add test * Restore close regardless of auto_cleanup * Close session instead of detaching and do not restore * Delint test * Add frame helper * Use frame helper * Test warning log when closing session * Clean up * Correct docstring * Do not change shutdown * Fix tests
This commit is contained in:
parent
2f6da20065
commit
2a120d9045
4 changed files with 205 additions and 2 deletions
56
tests/helpers/test_frame.py
Normal file
56
tests/helpers/test_frame.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
"""Test the frame helper."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.helpers import frame
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
|
||||
async def test_extract_frame_integration(caplog):
|
||||
"""Test extracting the current frame from integration context."""
|
||||
correct_frame = Mock(
|
||||
filename="/home/paulus/homeassistant/components/hue/light.py",
|
||||
lineno="23",
|
||||
line="self.light.is_on",
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.helpers.frame.extract_stack",
|
||||
return_value=[
|
||||
Mock(
|
||||
filename="/home/paulus/homeassistant/core.py",
|
||||
lineno="23",
|
||||
line="do_something()",
|
||||
),
|
||||
correct_frame,
|
||||
Mock(
|
||||
filename="/home/paulus/aiohue/lights.py",
|
||||
lineno="2",
|
||||
line="something()",
|
||||
),
|
||||
],
|
||||
):
|
||||
found_frame, integration, path = frame.get_integration_frame()
|
||||
|
||||
assert integration == "hue"
|
||||
assert path == "homeassistant/components/"
|
||||
assert found_frame == correct_frame
|
||||
|
||||
|
||||
async def test_extract_frame_no_integration(caplog):
|
||||
"""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()",
|
||||
),
|
||||
],
|
||||
), pytest.raises(frame.MissingIntegrationFrame):
|
||||
frame.get_integration_frame()
|
Loading…
Add table
Add a link
Reference in a new issue