Test platform setup errors are notified (#104384)

Test setup errors are notified
This commit is contained in:
Jan Bouwhuis 2023-11-22 21:16:12 +01:00 committed by GitHub
parent 968563253f
commit 3a42bd35e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 14 deletions

View File

@ -719,17 +719,19 @@ async def test_setup_hass_invalid_core_config(
event_loop: asyncio.AbstractEventLoop, event_loop: asyncio.AbstractEventLoop,
) -> None: ) -> None:
"""Test it works.""" """Test it works."""
hass = await bootstrap.async_setup_hass( with patch("homeassistant.config.async_notify_setup_error") as mock_notify:
runner.RuntimeConfig( hass = await bootstrap.async_setup_hass(
config_dir=get_test_config_dir(), runner.RuntimeConfig(
verbose=False, config_dir=get_test_config_dir(),
log_rotate_days=10, verbose=False,
log_file="", log_rotate_days=10,
log_no_color=False, log_file="",
skip_pip=True, log_no_color=False,
recovery_mode=False, skip_pip=True,
), recovery_mode=False,
) ),
)
assert len(mock_notify.mock_calls) == 1
assert "recovery_mode" in hass.config.components assert "recovery_mode" in hass.config.components

View File

@ -373,7 +373,9 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
MockPlatform(platform_schema=platform_schema, setup_platform=mock_setup), MockPlatform(platform_schema=platform_schema, setup_platform=mock_setup),
) )
with assert_setup_component(0, "switch"): with assert_setup_component(0, "switch"), patch(
"homeassistant.config.async_notify_setup_error"
) as mock_notify:
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
"switch", "switch",
@ -381,11 +383,14 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert mock_setup.call_count == 0 assert mock_setup.call_count == 0
assert len(mock_notify.mock_calls) == 1
hass.data.pop(setup.DATA_SETUP) hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("switch") hass.config.components.remove("switch")
with assert_setup_component(0): with assert_setup_component(0), patch(
"homeassistant.config.async_notify_setup_error"
) as mock_notify:
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
"switch", "switch",
@ -399,11 +404,14 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert mock_setup.call_count == 0 assert mock_setup.call_count == 0
assert len(mock_notify.mock_calls) == 1
hass.data.pop(setup.DATA_SETUP) hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("switch") hass.config.components.remove("switch")
with assert_setup_component(1, "switch"): with assert_setup_component(1, "switch"), patch(
"homeassistant.config.async_notify_setup_error"
) as mock_notify:
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
"switch", "switch",
@ -411,6 +419,7 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert mock_setup.call_count == 1 assert mock_setup.call_count == 1
assert len(mock_notify.mock_calls) == 0
async def test_disable_component_if_invalid_return(hass: HomeAssistant) -> None: async def test_disable_component_if_invalid_return(hass: HomeAssistant) -> None: