Fix mysensors tests typing (#51621)

This commit is contained in:
Martin Hjelmare 2021-06-08 14:28:36 +02:00 committed by GitHub
parent 3fa6c97801
commit 6de604a326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View file

@ -25,13 +25,14 @@ from homeassistant.components.mysensors.const import (
ConfGatewayType,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from tests.common import MockConfigEntry
async def get_form(
hass: HomeAssistant, gatway_type: ConfGatewayType, expected_step_id: str
):
) -> FlowResult:
"""Get a form for the given gateway type."""
await setup.async_setup_component(hass, "persistent_notification", {})
stepuser = await hass.config_entries.flow.async_init(
@ -107,7 +108,7 @@ async def test_missing_mqtt(hass: HomeAssistant) -> None:
assert result["errors"] == {"base": "mqtt_required"}
async def test_config_serial(hass: HomeAssistant):
async def test_config_serial(hass: HomeAssistant) -> None:
"""Test configuring a gateway via serial."""
step = await get_form(hass, CONF_GATEWAY_TYPE_SERIAL, "gw_serial")
flow_id = step["flow_id"]
@ -147,7 +148,7 @@ async def test_config_serial(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_config_tcp(hass: HomeAssistant):
async def test_config_tcp(hass: HomeAssistant) -> None:
"""Test configuring a gateway via tcp."""
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
flow_id = step["flow_id"]
@ -184,7 +185,7 @@ async def test_config_tcp(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_fail_to_connect(hass: HomeAssistant):
async def test_fail_to_connect(hass: HomeAssistant) -> None:
"""Test configuring a gateway via tcp."""
step = await get_form(hass, CONF_GATEWAY_TYPE_TCP, "gw_tcp")
flow_id = step["flow_id"]
@ -209,8 +210,9 @@ async def test_fail_to_connect(hass: HomeAssistant):
assert result2["type"] == "form"
assert "errors" in result2
assert "base" in result2["errors"]
assert result2["errors"]["base"] == "cannot_connect"
errors = result2["errors"]
assert errors
assert errors.get("base") == "cannot_connect"
assert len(mock_setup.mock_calls) == 0
assert len(mock_setup_entry.mock_calls) == 0
@ -367,12 +369,12 @@ async def test_fail_to_connect(hass: HomeAssistant):
)
async def test_config_invalid(
hass: HomeAssistant,
mqtt: config_entries.ConfigEntry,
mqtt: None,
gateway_type: ConfGatewayType,
expected_step_id: str,
user_input: dict[str, Any],
err_field,
err_string,
err_field: str,
err_string: str,
) -> None:
"""Perform a test that is expected to generate an error."""
step = await get_form(hass, gateway_type, expected_step_id)
@ -397,8 +399,10 @@ async def test_config_invalid(
assert result2["type"] == "form"
assert "errors" in result2
assert err_field in result2["errors"]
assert result2["errors"][err_field] == err_string
errors = result2["errors"]
assert errors
assert err_field in errors
assert errors[err_field] == err_string
assert len(mock_setup.mock_calls) == 0
assert len(mock_setup_entry.mock_calls) == 0

View file

@ -18,7 +18,9 @@ from homeassistant.core import HomeAssistant
("/dev/ttyACM0", False),
],
)
def test_is_serial_port_windows(hass: HomeAssistant, port: str, expect_valid: bool):
def test_is_serial_port_windows(
hass: HomeAssistant, port: str, expect_valid: bool
) -> None:
"""Test windows serial port."""
with patch("sys.platform", "win32"):