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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 896 additions and 427 deletions

View file

@ -4,7 +4,7 @@ from unittest.mock import ANY, patch
import homeassistant.components.mqtt_eventstream as eventstream
from homeassistant.const import EVENT_STATE_CHANGED, MATCH_ALL
from homeassistant.core import State, callback
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers.json import JSONEncoder
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -14,6 +14,7 @@ from tests.common import (
async_fire_time_changed,
mock_state_change_event,
)
from tests.typing import MqttMockHAClient
async def add_eventstream(hass, sub_topic=None, pub_topic=None, ignore_event=None):
@ -30,12 +31,12 @@ async def add_eventstream(hass, sub_topic=None, pub_topic=None, ignore_event=Non
)
async def test_setup_succeeds(hass, mqtt_mock):
async def test_setup_succeeds(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
"""Test the success of the setup."""
assert await add_eventstream(hass)
async def test_setup_with_pub(hass, mqtt_mock):
async def test_setup_with_pub(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
"""Test the setup with subscription."""
# Should start off with no listeners for all events
assert hass.bus.async_listeners().get("*") is None
@ -47,7 +48,7 @@ async def test_setup_with_pub(hass, mqtt_mock):
assert hass.bus.async_listeners().get("*") == 1
async def test_subscribe(hass, mqtt_mock):
async def test_subscribe(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
"""Test the subscription."""
sub_topic = "foo"
assert await add_eventstream(hass, sub_topic=sub_topic)
@ -57,7 +58,9 @@ async def test_subscribe(hass, mqtt_mock):
mqtt_mock.async_subscribe.assert_called_with(sub_topic, ANY, 0, ANY)
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."""
now = dt_util.as_utc(dt_util.now())
e_id = "fake.entity"
@ -104,7 +107,9 @@ async def test_state_changed_event_sends_message(hass, mqtt_mock):
assert result == event
async def test_time_event_does_not_send_message(hass, mqtt_mock):
async def test_time_event_does_not_send_message(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the sending of a new message if time event."""
assert await add_eventstream(hass, pub_topic="bar")
await hass.async_block_till_done()
@ -118,7 +123,9 @@ async def test_time_event_does_not_send_message(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_receiving_remote_event_fires_hass_event(hass, mqtt_mock):
async def test_receiving_remote_event_fires_hass_event(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the receiving of the remotely fired event."""
sub_topic = "foo"
assert await add_eventstream(hass, sub_topic=sub_topic)
@ -144,7 +151,9 @@ async def test_receiving_remote_event_fires_hass_event(hass, mqtt_mock):
await hass.async_block_till_done()
async def test_receiving_blocked_event_fires_hass_event(hass, mqtt_mock):
async def test_receiving_blocked_event_fires_hass_event(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the receiving of blocked event does not fire."""
sub_topic = "foo"
assert await add_eventstream(hass, sub_topic=sub_topic)
@ -169,7 +178,9 @@ async def test_receiving_blocked_event_fires_hass_event(hass, mqtt_mock):
await hass.async_block_till_done()
async def test_ignored_event_doesnt_send_over_stream(hass, mqtt_mock):
async def test_ignored_event_doesnt_send_over_stream(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the ignoring of sending events if defined."""
assert await add_eventstream(hass, pub_topic="bar", ignore_event=["state_changed"])
await hass.async_block_till_done()
@ -192,7 +203,9 @@ async def test_ignored_event_doesnt_send_over_stream(hass, mqtt_mock):
assert not mqtt_mock.async_publish.called
async def test_wrong_ignored_event_sends_over_stream(hass, mqtt_mock):
async def test_wrong_ignored_event_sends_over_stream(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
) -> None:
"""Test the ignoring of sending events if defined."""
assert await add_eventstream(hass, pub_topic="bar", ignore_event=["statee_changed"])
await hass.async_block_till_done()