mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix return type annotations in tests (#122184)
This commit is contained in:
parent
87ecf5d85e
commit
8bca9a3449
@ -77,11 +77,10 @@ async def scanner(
|
|||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return scanner
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("scanner")
|
||||||
async def test_lights_on_when_sun_sets(
|
async def test_lights_on_when_sun_sets(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test lights go on when there is someone home and the sun sets."""
|
"""Test lights go on when there is someone home and the sun sets."""
|
||||||
test_time = datetime(2017, 4, 5, 1, 2, 3, tzinfo=dt_util.UTC)
|
test_time = datetime(2017, 4, 5, 1, 2, 3, tzinfo=dt_util.UTC)
|
||||||
@ -136,8 +135,9 @@ async def test_lights_turn_off_when_everyone_leaves(hass: HomeAssistant) -> None
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("scanner")
|
||||||
async def test_lights_turn_on_when_coming_home_after_sun_set(
|
async def test_lights_turn_on_when_coming_home_after_sun_set(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test lights turn on when coming home after sun set."""
|
"""Test lights turn on when coming home after sun set."""
|
||||||
test_time = datetime(2017, 4, 5, 3, 2, 3, tzinfo=dt_util.UTC)
|
test_time = datetime(2017, 4, 5, 3, 2, 3, tzinfo=dt_util.UTC)
|
||||||
@ -172,8 +172,9 @@ async def test_lights_turn_on_when_coming_home_after_sun_set(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("scanner")
|
||||||
async def test_lights_turn_on_when_coming_home_after_sun_set_person(
|
async def test_lights_turn_on_when_coming_home_after_sun_set_person(
|
||||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, scanner
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test lights turn on when coming home after sun set."""
|
"""Test lights turn on when coming home after sun set."""
|
||||||
device_1 = f"{DOMAIN}.device_1"
|
device_1 = f"{DOMAIN}.device_1"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Test configuration for DoorBird tests."""
|
"""Test configuration for DoorBird tests."""
|
||||||
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Callable, Coroutine, Generator
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -16,6 +16,8 @@ from . import VALID_CONFIG, get_mock_doorbird_api
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry, load_json_value_fixture
|
from tests.common import MockConfigEntry, load_json_value_fixture
|
||||||
|
|
||||||
|
type DoorbirdMockerType = Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MockDoorbirdEntry:
|
class MockDoorbirdEntry:
|
||||||
@ -70,7 +72,7 @@ async def doorbird_mocker(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
doorbird_info: dict[str, Any],
|
doorbird_info: dict[str, Any],
|
||||||
doorbird_schedule: dict[str, Any],
|
doorbird_schedule: dict[str, Any],
|
||||||
) -> MockDoorbirdEntry:
|
) -> DoorbirdMockerType:
|
||||||
"""Create a MockDoorbirdEntry."""
|
"""Create a MockDoorbirdEntry."""
|
||||||
|
|
||||||
async def _async_mock(
|
async def _async_mock(
|
||||||
@ -79,7 +81,7 @@ async def doorbird_mocker(
|
|||||||
info: dict[str, Any] | None = None,
|
info: dict[str, Any] | None = None,
|
||||||
info_side_effect: Exception | None = None,
|
info_side_effect: Exception | None = None,
|
||||||
schedule: list[DoorBirdScheduleEntry] | None = None,
|
schedule: list[DoorBirdScheduleEntry] | None = None,
|
||||||
) -> None:
|
) -> MockDoorbirdEntry:
|
||||||
"""Create a MockDoorbirdEntry from defaults or specific values."""
|
"""Create a MockDoorbirdEntry from defaults or specific values."""
|
||||||
entry = entry or MockConfigEntry(
|
entry = entry or MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
"""Test DoorBird buttons."""
|
"""Test DoorBird buttons."""
|
||||||
|
|
||||||
from collections.abc import Callable, Coroutine
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from homeassistant.components.button import DOMAIN, SERVICE_PRESS
|
from homeassistant.components.button import DOMAIN, SERVICE_PRESS
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .conftest import MockDoorbirdEntry
|
from .conftest import DoorbirdMockerType
|
||||||
|
|
||||||
|
|
||||||
async def test_relay_button(
|
async def test_relay_button(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
doorbird_mocker: Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]],
|
doorbird_mocker: DoorbirdMockerType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test pressing a relay button."""
|
"""Test pressing a relay button."""
|
||||||
doorbird_entry = await doorbird_mocker()
|
doorbird_entry = await doorbird_mocker()
|
||||||
@ -27,7 +24,7 @@ async def test_relay_button(
|
|||||||
|
|
||||||
async def test_ir_button(
|
async def test_ir_button(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
doorbird_mocker: Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]],
|
doorbird_mocker: DoorbirdMockerType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test pressing the IR button."""
|
"""Test pressing the IR button."""
|
||||||
doorbird_entry = await doorbird_mocker()
|
doorbird_entry = await doorbird_mocker()
|
||||||
@ -42,7 +39,7 @@ async def test_ir_button(
|
|||||||
|
|
||||||
async def test_reset_favorites_button(
|
async def test_reset_favorites_button(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
doorbird_mocker: Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]],
|
doorbird_mocker: DoorbirdMockerType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test pressing the reset favorites button."""
|
"""Test pressing the reset favorites button."""
|
||||||
doorbird_entry = await doorbird_mocker()
|
doorbird_entry = await doorbird_mocker()
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
"""Test DoorBird init."""
|
"""Test DoorBird init."""
|
||||||
|
|
||||||
from collections.abc import Callable, Coroutine
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from homeassistant.components.doorbird.const import DOMAIN
|
from homeassistant.components.doorbird.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import mock_unauthorized_exception
|
from . import mock_unauthorized_exception
|
||||||
from .conftest import MockDoorbirdEntry
|
from .conftest import DoorbirdMockerType
|
||||||
|
|
||||||
|
|
||||||
async def test_basic_setup(
|
async def test_basic_setup(
|
||||||
doorbird_mocker: Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]],
|
doorbird_mocker: DoorbirdMockerType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test basic setup."""
|
"""Test basic setup."""
|
||||||
doorbird_entry = await doorbird_mocker()
|
doorbird_entry = await doorbird_mocker()
|
||||||
@ -22,7 +19,7 @@ async def test_basic_setup(
|
|||||||
|
|
||||||
async def test_auth_fails(
|
async def test_auth_fails(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
doorbird_mocker: Callable[[], Coroutine[Any, Any, MockDoorbirdEntry]],
|
doorbird_mocker: DoorbirdMockerType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test basic setup with an auth failure."""
|
"""Test basic setup with an auth failure."""
|
||||||
doorbird_entry = await doorbird_mocker(
|
doorbird_entry = await doorbird_mocker(
|
||||||
|
@ -11,7 +11,7 @@ import pytest
|
|||||||
def mock_zha_config_flow_setup() -> Generator[None]:
|
def mock_zha_config_flow_setup() -> Generator[None]:
|
||||||
"""Mock the radio connection and probing of the ZHA config flow."""
|
"""Mock the radio connection and probing of the ZHA config flow."""
|
||||||
|
|
||||||
def mock_probe(config: dict[str, Any]) -> None:
|
def mock_probe(config: dict[str, Any]) -> dict[str, Any]:
|
||||||
# The radio probing will return the correct baudrate
|
# The radio probing will return the correct baudrate
|
||||||
return {**config, "baudrate": 115200}
|
return {**config, "baudrate": 115200}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import pytest
|
|||||||
def mock_zha_config_flow_setup() -> Generator[None]:
|
def mock_zha_config_flow_setup() -> Generator[None]:
|
||||||
"""Mock the radio connection and probing of the ZHA config flow."""
|
"""Mock the radio connection and probing of the ZHA config flow."""
|
||||||
|
|
||||||
def mock_probe(config: dict[str, Any]) -> None:
|
def mock_probe(config: dict[str, Any]) -> dict[str, Any]:
|
||||||
# The radio probing will return the correct baudrate
|
# The radio probing will return the correct baudrate
|
||||||
return {**config, "baudrate": 115200}
|
return {**config, "baudrate": 115200}
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ async def test_authorize_fails(hass: HomeAssistant, exc, error) -> None:
|
|||||||
assert result["reason"] == error
|
assert result["reason"] == error
|
||||||
|
|
||||||
|
|
||||||
async def _test_provision_error(hass: HomeAssistant, exc) -> None:
|
async def _test_provision_error(hass: HomeAssistant, exc) -> str:
|
||||||
"""Test bluetooth flow with error."""
|
"""Test bluetooth flow with error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -20,7 +20,7 @@ GATEWAY_IMPORT_PATH = "homeassistant.components.screenlogic.ScreenLogicGateway"
|
|||||||
GATEWAY_DISCOVERY_IMPORT_PATH = "homeassistant.components.screenlogic.coordinator.async_discover_gateways_by_unique_id"
|
GATEWAY_DISCOVERY_IMPORT_PATH = "homeassistant.components.screenlogic.coordinator.async_discover_gateways_by_unique_id"
|
||||||
|
|
||||||
|
|
||||||
def num_key_string_to_int(data: dict) -> None:
|
def num_key_string_to_int(data: dict) -> dict:
|
||||||
"""Convert all string number dict keys to integer.
|
"""Convert all string number dict keys to integer.
|
||||||
|
|
||||||
This needed for screenlogicpy's data dict format.
|
This needed for screenlogicpy's data dict format.
|
||||||
|
@ -3231,7 +3231,7 @@ async def test_async_add_import_executor_job(hass: HomeAssistant) -> None:
|
|||||||
evt = threading.Event()
|
evt = threading.Event()
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
def executor_func() -> None:
|
def executor_func() -> threading.Event:
|
||||||
evt.set()
|
evt.set()
|
||||||
return evt
|
return evt
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user