mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
mock shutdown
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from contextlib import contextmanager
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import bleak
|
import bleak
|
||||||
@@ -18,6 +19,7 @@ from homeassistant.components.bluetooth import (
|
|||||||
MONOTONIC_TIME,
|
MONOTONIC_TIME,
|
||||||
BluetoothServiceInfoBleak,
|
BluetoothServiceInfoBleak,
|
||||||
HaBluetoothConnector,
|
HaBluetoothConnector,
|
||||||
|
HomeAssistantBluetoothManager,
|
||||||
HomeAssistantRemoteScanner,
|
HomeAssistantRemoteScanner,
|
||||||
async_get_advertisement_callback,
|
async_get_advertisement_callback,
|
||||||
)
|
)
|
||||||
@@ -26,6 +28,14 @@ from homeassistant.core import HomeAssistant
|
|||||||
from . import _get_manager, generate_advertisement_data, generate_ble_device
|
from . import _get_manager, generate_advertisement_data, generate_ble_device
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def mock_shutdown(manager: HomeAssistantBluetoothManager) -> None:
|
||||||
|
"""Mock shutdown of the HomeAssistantBluetoothManager."""
|
||||||
|
manager.shutdown = True
|
||||||
|
yield
|
||||||
|
manager.shutdown = False
|
||||||
|
|
||||||
|
|
||||||
class FakeScanner(HomeAssistantRemoteScanner):
|
class FakeScanner(HomeAssistantRemoteScanner):
|
||||||
"""Fake scanner."""
|
"""Fake scanner."""
|
||||||
|
|
||||||
@@ -382,7 +392,7 @@ async def test_raise_after_shutdown(
|
|||||||
hass
|
hass
|
||||||
)
|
)
|
||||||
# hci0 has 2 slots, hci1 has 1 slot
|
# hci0 has 2 slots, hci1 has 1 slot
|
||||||
with patch.object(manager, "shutdown", True):
|
with mock_shutdown(manager):
|
||||||
ble_device = hci0_device_advs["00:00:00:00:00:01"][0]
|
ble_device = hci0_device_advs["00:00:00:00:00:01"][0]
|
||||||
client = bleak.BleakClient(ble_device)
|
client = bleak.BleakClient(ble_device)
|
||||||
with pytest.raises(BleakError, match="shutdown"):
|
with pytest.raises(BleakError, match="shutdown"):
|
||||||
|
Reference in New Issue
Block a user