Add type hints to integration tests (part 8) (#87982)

This commit is contained in:
epenet 2023-02-13 11:13:48 +01:00 committed by GitHub
parent 575f7c4205
commit 89e4ee5320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 696 additions and 339 deletions

View file

@ -8,6 +8,7 @@ import pytest
from homeassistant.components import graphite
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
@ -32,14 +33,14 @@ def fixture_mock_time():
yield mock_time
async def test_setup(hass, mock_socket):
async def test_setup(hass: HomeAssistant, mock_socket) -> None:
"""Test setup."""
assert await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})
assert mock_socket.call_count == 1
assert mock_socket.call_args == mock.call(socket.AF_INET, socket.SOCK_STREAM)
async def test_setup_failure(hass, mock_socket):
async def test_setup_failure(hass: HomeAssistant, mock_socket) -> None:
"""Test setup fails due to socket error."""
mock_socket.return_value.connect.side_effect = OSError
assert not await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})
@ -49,7 +50,7 @@ async def test_setup_failure(hass, mock_socket):
assert mock_socket.return_value.connect.call_count == 1
async def test_full_config(hass, mock_gf, mock_socket):
async def test_full_config(hass: HomeAssistant, mock_gf, mock_socket) -> None:
"""Test setup with full configuration."""
config = {"graphite": {"host": "foo", "port": 123, "prefix": "me"}}
@ -60,7 +61,7 @@ async def test_full_config(hass, mock_gf, mock_socket):
assert mock_socket.call_args == mock.call(socket.AF_INET, socket.SOCK_STREAM)
async def test_full_udp_config(hass, mock_gf, mock_socket):
async def test_full_udp_config(hass: HomeAssistant, mock_gf, mock_socket) -> None:
"""Test setup with full configuration and UDP protocol."""
config = {
"graphite": {"host": "foo", "port": 123, "protocol": "udp", "prefix": "me"}
@ -72,7 +73,7 @@ async def test_full_udp_config(hass, mock_gf, mock_socket):
assert mock_socket.call_count == 0
async def test_config_port(hass, mock_gf, mock_socket):
async def test_config_port(hass: HomeAssistant, mock_gf, mock_socket) -> None:
"""Test setup with invalid port."""
config = {"graphite": {"host": "foo", "port": 2003}}
@ -82,7 +83,7 @@ async def test_config_port(hass, mock_gf, mock_socket):
assert mock_socket.call_args == mock.call(socket.AF_INET, socket.SOCK_STREAM)
async def test_start(hass, mock_socket, mock_time):
async def test_start(hass: HomeAssistant, mock_socket, mock_time) -> None:
"""Test the start."""
mock_time.return_value = 12345
assert await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})
@ -105,7 +106,7 @@ async def test_start(hass, mock_socket, mock_time):
assert mock_socket.return_value.close.call_count == 1
async def test_shutdown(hass, mock_socket, mock_time):
async def test_shutdown(hass: HomeAssistant, mock_socket, mock_time) -> None:
"""Test the shutdown."""
mock_time.return_value = 12345
assert await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})
@ -139,7 +140,7 @@ async def test_shutdown(hass, mock_socket, mock_time):
assert mock_socket.return_value.sendall.call_count == 0
async def test_report_attributes(hass, mock_socket, mock_time):
async def test_report_attributes(hass: HomeAssistant, mock_socket, mock_time) -> None:
"""Test the reporting with attributes."""
attrs = {"foo": 1, "bar": 2.0, "baz": True, "bat": "NaN"}
expected = [
@ -170,7 +171,9 @@ async def test_report_attributes(hass, mock_socket, mock_time):
assert mock_socket.return_value.close.call_count == 1
async def test_report_with_string_state(hass, mock_socket, mock_time):
async def test_report_with_string_state(
hass: HomeAssistant, mock_socket, mock_time
) -> None:
"""Test the reporting with strings."""
expected = [
"ha.test.entity.foo 1.000000 12345",
@ -208,7 +211,9 @@ async def test_report_with_string_state(hass, mock_socket, mock_time):
assert mock_socket.return_value.close.call_count == 0
async def test_report_with_binary_state(hass, mock_socket, mock_time):
async def test_report_with_binary_state(
hass: HomeAssistant, mock_socket, mock_time
) -> None:
"""Test the reporting with binary state."""
mock_time.return_value = 12345
assert await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})
@ -263,8 +268,13 @@ async def test_report_with_binary_state(hass, mock_socket, mock_time):
],
)
async def test_send_to_graphite_errors(
hass, mock_socket, mock_time, caplog, error, log_text
):
hass: HomeAssistant,
mock_socket,
mock_time,
caplog: pytest.LogCaptureFixture,
error,
log_text,
) -> None:
"""Test the sending with errors."""
mock_time.return_value = 12345
assert await async_setup_component(hass, graphite.DOMAIN, {"graphite": {}})