Improve type hints in motionblinds_ble tests (#119049)

pull/119053/head
epenet 2024-06-07 10:43:56 +02:00 committed by GitHub
parent d5a68ad311
commit c107d980fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View File

@ -3,6 +3,7 @@
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
import pytest import pytest
from typing_extensions import Generator
TEST_MAC = "abcd" TEST_MAC = "abcd"
TEST_NAME = f"MOTION_{TEST_MAC.upper()}" TEST_NAME = f"MOTION_{TEST_MAC.upper()}"
@ -10,7 +11,9 @@ TEST_ADDRESS = "test_adress"
@pytest.fixture(name="motionblinds_ble_connect", autouse=True) @pytest.fixture(name="motionblinds_ble_connect", autouse=True)
def motion_blinds_connect_fixture(enable_bluetooth): def motion_blinds_connect_fixture(
enable_bluetooth: None,
) -> Generator[tuple[AsyncMock, Mock]]:
"""Mock motion blinds ble connection and entry setup.""" """Mock motion blinds ble connection and entry setup."""
device = Mock() device = Mock()
device.name = TEST_NAME device.name = TEST_NAME

View File

@ -1,8 +1,9 @@
"""Test the Motionblinds Bluetooth config flow.""" """Test the Motionblinds Bluetooth config flow."""
from unittest.mock import patch from unittest.mock import AsyncMock, Mock, patch
from motionblindsble.const import MotionBlindType from motionblindsble.const import MotionBlindType
import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
@ -43,9 +44,8 @@ BLIND_SERVICE_INFO = BluetoothServiceInfoBleak(
) )
async def test_config_flow_manual_success( @pytest.mark.usefixtures("motionblinds_ble_connect")
hass: HomeAssistant, motionblinds_ble_connect async def test_config_flow_manual_success(hass: HomeAssistant) -> None:
) -> None:
"""Successful flow manually initialized by the user.""" """Successful flow manually initialized by the user."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
const.DOMAIN, context={"source": config_entries.SOURCE_USER} const.DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -76,9 +76,8 @@ async def test_config_flow_manual_success(
assert result["options"] == {} assert result["options"] == {}
async def test_config_flow_manual_error_invalid_mac( @pytest.mark.usefixtures("motionblinds_ble_connect")
hass: HomeAssistant, motionblinds_ble_connect async def test_config_flow_manual_error_invalid_mac(hass: HomeAssistant) -> None:
) -> None:
"""Invalid MAC code error flow manually initialized by the user.""" """Invalid MAC code error flow manually initialized by the user."""
# Initialize # Initialize
@ -122,8 +121,9 @@ async def test_config_flow_manual_error_invalid_mac(
assert result["options"] == {} assert result["options"] == {}
@pytest.mark.usefixtures("motionblinds_ble_connect")
async def test_config_flow_manual_error_no_bluetooth_adapter( async def test_config_flow_manual_error_no_bluetooth_adapter(
hass: HomeAssistant, motionblinds_ble_connect hass: HomeAssistant,
) -> None: ) -> None:
"""No Bluetooth adapter error flow manually initialized by the user.""" """No Bluetooth adapter error flow manually initialized by the user."""
@ -159,7 +159,7 @@ async def test_config_flow_manual_error_no_bluetooth_adapter(
async def test_config_flow_manual_error_could_not_find_motor( async def test_config_flow_manual_error_could_not_find_motor(
hass: HomeAssistant, motionblinds_ble_connect hass: HomeAssistant, motionblinds_ble_connect: tuple[AsyncMock, Mock]
) -> None: ) -> None:
"""Could not find motor error flow manually initialized by the user.""" """Could not find motor error flow manually initialized by the user."""
@ -207,7 +207,7 @@ async def test_config_flow_manual_error_could_not_find_motor(
async def test_config_flow_manual_error_no_devices_found( async def test_config_flow_manual_error_no_devices_found(
hass: HomeAssistant, motionblinds_ble_connect hass: HomeAssistant, motionblinds_ble_connect: tuple[AsyncMock, Mock]
) -> None: ) -> None:
"""No devices found error flow manually initialized by the user.""" """No devices found error flow manually initialized by the user."""
@ -229,9 +229,8 @@ async def test_config_flow_manual_error_no_devices_found(
assert result["reason"] == const.ERROR_NO_DEVICES_FOUND assert result["reason"] == const.ERROR_NO_DEVICES_FOUND
async def test_config_flow_bluetooth_success( @pytest.mark.usefixtures("motionblinds_ble_connect")
hass: HomeAssistant, motionblinds_ble_connect async def test_config_flow_bluetooth_success(hass: HomeAssistant) -> None:
) -> None:
"""Successful bluetooth discovery flow.""" """Successful bluetooth discovery flow."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
const.DOMAIN, const.DOMAIN,