Add type hints to integration tests (part 15) (#88006)

This commit is contained in:
epenet
2023-02-15 10:00:49 +01:00
committed by GitHub
parent 6c23d6abfe
commit 50cbabb2d8
51 changed files with 896 additions and 427 deletions

View File

@@ -2,10 +2,11 @@
from unittest.mock import ANY, call
import homeassistant.components.mqtt_statestream as statestream
from homeassistant.core import State
from homeassistant.core import HomeAssistant, State
from homeassistant.setup import async_setup_component
from tests.common import mock_state_change_event
from tests.typing import MqttMockHAClient
async def add_statestream(
@@ -33,22 +34,30 @@ async def add_statestream(
)
async def test_fails_with_no_base(hass, mqtt_mock):
async def test_fails_with_no_base(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Setup should fail if no base_topic is set."""
assert await add_statestream(hass) is False
async def test_setup_succeeds_without_attributes(hass, mqtt_mock):
async def test_setup_succeeds_without_attributes(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the success of the setup with a valid base_topic."""
assert await add_statestream(hass, base_topic="pub")
async def test_setup_succeeds_with_attributes(hass, mqtt_mock):
async def test_setup_succeeds_with_attributes(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test setup with a valid base_topic and publish_attributes."""
assert await add_statestream(hass, base_topic="pub", publish_attributes=True)
async def test_state_changed_event_sends_message(hass, mqtt_mock):
async def test_state_changed_event_sends_message(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the sending of a new message if event changed."""
e_id = "fake.entity"
base_topic = "pub"
@@ -71,7 +80,9 @@ async def test_state_changed_event_sends_message(hass, mqtt_mock):
assert mqtt_mock.async_publish.called
async def test_state_changed_event_sends_message_and_timestamp(hass, mqtt_mock):
async def test_state_changed_event_sends_message_and_timestamp(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the sending of a message and timestamps if event changed."""
e_id = "another.entity"
base_topic = "pub"
@@ -102,7 +113,9 @@ async def test_state_changed_event_sends_message_and_timestamp(hass, mqtt_mock):
assert mqtt_mock.async_publish.called
async def test_state_changed_attr_sends_message(hass, mqtt_mock):
async def test_state_changed_attr_sends_message(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the sending of a new message if attribute changed."""
e_id = "fake.entity"
base_topic = "pub"
@@ -134,7 +147,9 @@ async def test_state_changed_attr_sends_message(hass, mqtt_mock):
assert mqtt_mock.async_publish.called
async def test_state_changed_event_include_domain(hass, mqtt_mock):
async def test_state_changed_event_include_domain(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on included domain works as expected."""
base_topic = "pub"
@@ -170,7 +185,9 @@ async def test_state_changed_event_include_domain(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_include_entity(hass, mqtt_mock):
async def test_state_changed_event_include_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on included entity works as expected."""
base_topic = "pub"
@@ -206,7 +223,9 @@ async def test_state_changed_event_include_entity(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_exclude_domain(hass, mqtt_mock):
async def test_state_changed_event_exclude_domain(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on excluded domain works as expected."""
base_topic = "pub"
@@ -242,7 +261,9 @@ async def test_state_changed_event_exclude_domain(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_exclude_entity(hass, mqtt_mock):
async def test_state_changed_event_exclude_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on excluded entity works as expected."""
base_topic = "pub"
@@ -278,7 +299,9 @@ async def test_state_changed_event_exclude_entity(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_exclude_domain_include_entity(hass, mqtt_mock):
async def test_state_changed_event_exclude_domain_include_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test filtering with excluded domain and included entity."""
base_topic = "pub"
@@ -314,7 +337,9 @@ async def test_state_changed_event_exclude_domain_include_entity(hass, mqtt_mock
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_include_domain_exclude_entity(hass, mqtt_mock):
async def test_state_changed_event_include_domain_exclude_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test filtering with included domain and excluded entity."""
base_topic = "pub"
@@ -350,7 +375,9 @@ async def test_state_changed_event_include_domain_exclude_entity(hass, mqtt_mock
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_include_globs(hass, mqtt_mock):
async def test_state_changed_event_include_globs(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on included glob works as expected."""
base_topic = "pub"
@@ -388,7 +415,9 @@ async def test_state_changed_event_include_globs(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_exclude_globs(hass, mqtt_mock):
async def test_state_changed_event_exclude_globs(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test that filtering on excluded globs works as expected."""
base_topic = "pub"
@@ -424,7 +453,9 @@ async def test_state_changed_event_exclude_globs(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_exclude_domain_globs_include_entity(hass, mqtt_mock):
async def test_state_changed_event_exclude_domain_globs_include_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test filtering with excluded domain and glob and included entity."""
base_topic = "pub"
@@ -480,7 +511,9 @@ async def test_state_changed_event_exclude_domain_globs_include_entity(hass, mqt
assert not mqtt_mock.async_publish.called
async def test_state_changed_event_include_domain_globs_exclude_entity(hass, mqtt_mock):
async def test_state_changed_event_include_domain_globs_exclude_entity(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test filtering with included domain and glob and excluded entity."""
base_topic = "pub"