1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add type hints to core tests (part 2) (#88492)

This commit is contained in:
epenet
2023-02-21 09:27:13 +01:00
committed by GitHub
parent a102883eff
commit a51cc75f03
17 changed files with 383 additions and 216 deletions

View File

@@ -46,7 +46,7 @@ def manager():
return mgr
async def test_configure_reuses_handler_instance(manager):
async def test_configure_reuses_handler_instance(manager) -> None:
"""Test that we reuse instances."""
@manager.mock_reg_handler("test")
@@ -109,7 +109,7 @@ async def test_configure_two_steps(manager: data_entry_flow.FlowManager) -> None
assert result["data"] == ["INIT-DATA", "SECOND-DATA"]
async def test_show_form(manager):
async def test_show_form(manager) -> None:
"""Test that we can show a form."""
schema = vol.Schema({vol.Required("username"): str, vol.Required("password"): str})
@@ -128,7 +128,7 @@ async def test_show_form(manager):
assert form["errors"] == {"username": "Should be unique."}
async def test_abort_removes_instance(manager):
async def test_abort_removes_instance(manager) -> None:
"""Test that abort removes the flow from progress."""
@manager.mock_reg_handler("test")
@@ -150,7 +150,7 @@ async def test_abort_removes_instance(manager):
assert len(manager.mock_created_entries) == 0
async def test_abort_calls_async_remove(manager):
async def test_abort_calls_async_remove(manager) -> None:
"""Test abort calling the async_remove FlowHandler method."""
@manager.mock_reg_handler("test")
@@ -168,7 +168,9 @@ async def test_abort_calls_async_remove(manager):
assert len(manager.mock_created_entries) == 0
async def test_abort_calls_async_remove_with_exception(manager, caplog):
async def test_abort_calls_async_remove_with_exception(
manager, caplog: pytest.LogCaptureFixture
) -> None:
"""Test abort calling the async_remove FlowHandler method, with an exception."""
@manager.mock_reg_handler("test")
@@ -189,7 +191,7 @@ async def test_abort_calls_async_remove_with_exception(manager, caplog):
assert len(manager.mock_created_entries) == 0
async def test_create_saves_data(manager):
async def test_create_saves_data(manager) -> None:
"""Test creating a config entry."""
@manager.mock_reg_handler("test")
@@ -211,7 +213,7 @@ async def test_create_saves_data(manager):
assert entry["source"] is None
async def test_discovery_init_flow(manager):
async def test_discovery_init_flow(manager) -> None:
"""Test a flow initialized by discovery."""
@manager.mock_reg_handler("test")
@@ -283,7 +285,7 @@ async def test_finish_callback_change_result_type(hass: HomeAssistant) -> None:
assert result["result"] == 2
async def test_external_step(hass, manager):
async def test_external_step(hass: HomeAssistant, manager) -> None:
"""Test external step logic."""
manager.hass = hass
@@ -333,7 +335,7 @@ async def test_external_step(hass, manager):
assert result["title"] == "Hello"
async def test_show_progress(hass, manager):
async def test_show_progress(hass: HomeAssistant, manager) -> None:
"""Test show progress logic."""
manager.hass = hass
@@ -405,7 +407,7 @@ async def test_show_progress(hass, manager):
assert result["title"] == "Hello"
async def test_abort_flow_exception(manager):
async def test_abort_flow_exception(manager) -> None:
"""Test that the AbortFlow exception works."""
@manager.mock_reg_handler("test")
@@ -419,7 +421,7 @@ async def test_abort_flow_exception(manager):
assert form["description_placeholders"] == {"placeholder": "yo"}
async def test_init_unknown_flow(manager):
async def test_init_unknown_flow(manager) -> None:
"""Test that UnknownFlow is raised when async_create_flow returns None."""
with pytest.raises(data_entry_flow.UnknownFlow), patch.object(
@@ -428,7 +430,7 @@ async def test_init_unknown_flow(manager):
await manager.async_init("test")
async def test_async_get_unknown_flow(manager):
async def test_async_get_unknown_flow(manager) -> None:
"""Test that UnknownFlow is raised when async_get is called with a flow_id that does not exist."""
with pytest.raises(data_entry_flow.UnknownFlow):
@@ -437,7 +439,7 @@ async def test_async_get_unknown_flow(manager):
async def test_async_has_matching_flow(
hass: HomeAssistant, manager: data_entry_flow.FlowManager
):
) -> None:
"""Test we can check for matching flows."""
manager.hass = hass
@@ -488,7 +490,9 @@ async def test_async_has_matching_flow(
)
async def test_move_to_unknown_step_raises_and_removes_from_in_progress(manager):
async def test_move_to_unknown_step_raises_and_removes_from_in_progress(
manager,
) -> None:
"""Test that moving to an unknown step raises and removes the flow from in progress."""
@manager.mock_reg_handler("test")
@@ -501,13 +505,13 @@ async def test_move_to_unknown_step_raises_and_removes_from_in_progress(manager)
assert manager.async_progress() == []
async def test_configure_raises_unknown_flow_if_not_in_progress(manager):
async def test_configure_raises_unknown_flow_if_not_in_progress(manager) -> None:
"""Test configure raises UnknownFlow if the flow is not in progress."""
with pytest.raises(data_entry_flow.UnknownFlow):
await manager.async_configure("wrong_flow_id")
async def test_abort_raises_unknown_flow_if_not_in_progress(manager):
async def test_abort_raises_unknown_flow_if_not_in_progress(manager) -> None:
"""Test abort raises UnknownFlow if the flow is not in progress."""
with pytest.raises(data_entry_flow.UnknownFlow):
await manager.async_abort("wrong_flow_id")
@@ -517,7 +521,7 @@ async def test_abort_raises_unknown_flow_if_not_in_progress(manager):
"menu_options",
(["target1", "target2"], {"target1": "Target 1", "target2": "Target 2"}),
)
async def test_show_menu(hass, manager, menu_options):
async def test_show_menu(hass: HomeAssistant, manager, menu_options) -> None:
"""Test show menu."""
manager.hass = hass