mock shutdown

This commit is contained in:
J. Nick Koston
2023-12-05 15:16:04 -10:00
parent f9e6236ff1
commit 2b24252b4e

View File

@@ -2,6 +2,7 @@
from __future__ import annotations
from collections.abc import Callable
from contextlib import contextmanager
from unittest.mock import patch
import bleak
@@ -18,6 +19,7 @@ from homeassistant.components.bluetooth import (
MONOTONIC_TIME,
BluetoothServiceInfoBleak,
HaBluetoothConnector,
HomeAssistantBluetoothManager,
HomeAssistantRemoteScanner,
async_get_advertisement_callback,
)
@@ -26,6 +28,14 @@ from homeassistant.core import HomeAssistant
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):
"""Fake scanner."""
@@ -382,7 +392,7 @@ async def test_raise_after_shutdown(
hass
)
# 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]
client = bleak.BleakClient(ble_device)
with pytest.raises(BleakError, match="shutdown"):