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,
) -> None:
"""Test it works."""
hass = await bootstrap.async_setup_hass(
runner.RuntimeConfig(
config_dir=get_test_config_dir(),
verbose=False,
log_rotate_days=10,
log_file="",
log_no_color=False,
skip_pip=True,
recovery_mode=False,
),
)
with patch("homeassistant.config.async_notify_setup_error") as mock_notify:
hass = await bootstrap.async_setup_hass(
runner.RuntimeConfig(
config_dir=get_test_config_dir(),
verbose=False,
log_rotate_days=10,
log_file="",
log_no_color=False,
skip_pip=True,
recovery_mode=False,
),
)
assert len(mock_notify.mock_calls) == 1
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),
)
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(
hass,
"switch",
@ -381,11 +383,14 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert mock_setup.call_count == 0
assert len(mock_notify.mock_calls) == 1
hass.data.pop(setup.DATA_SETUP)
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(
hass,
"switch",
@ -399,11 +404,14 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert mock_setup.call_count == 0
assert len(mock_notify.mock_calls) == 1
hass.data.pop(setup.DATA_SETUP)
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(
hass,
"switch",
@ -411,6 +419,7 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert mock_setup.call_count == 1
assert len(mock_notify.mock_calls) == 0
async def test_disable_component_if_invalid_return(hass: HomeAssistant) -> None: