From 6de604a326ded8945cd080645720780619de155a Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 8 Jun 2021 14:28:36 +0200 Subject: [PATCH] Fix mysensors tests typing (#51621) --- .../components/mysensors/test_config_flow.py | 26 +++++++++++-------- tests/components/mysensors/test_gateway.py | 4 ++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/components/mysensors/test_config_flow.py b/tests/components/mysensors/test_config_flow.py index 161d00e44b3..ddefd55457f 100644 --- a/tests/components/mysensors/test_config_flow.py +++ b/tests/components/mysensors/test_config_flow.py @@ -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 diff --git a/tests/components/mysensors/test_gateway.py b/tests/components/mysensors/test_gateway.py index f2e7aa77c8c..0c9652bdfc1 100644 --- a/tests/components/mysensors/test_gateway.py +++ b/tests/components/mysensors/test_gateway.py @@ -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"):