mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 19:25:12 +02:00
Fix wait for a dependency with config entries (#142318)
* Fix wait for dependency with config entries * test types * test coverage --------- Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -353,6 +353,76 @@ async def test_component_not_setup_missing_dependencies(hass: HomeAssistant) ->
|
||||
assert await setup.async_setup_component(hass, "comp2", {})
|
||||
|
||||
|
||||
async def test_component_not_setup_already_setup_dependencies(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test we do not set up component dependencies if they are already set up."""
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
"comp",
|
||||
dependencies=["dep1"],
|
||||
partial_manifest={"after_dependencies": ["dep2"]},
|
||||
),
|
||||
)
|
||||
mock_integration(hass, MockModule("dep1"))
|
||||
mock_integration(hass, MockModule("dep2"))
|
||||
|
||||
setup.async_set_domains_to_be_loaded(hass, {"comp", "dep2"})
|
||||
|
||||
hass.config.components.add("dep1")
|
||||
hass.config.components.add("dep2")
|
||||
|
||||
with patch(
|
||||
"homeassistant.setup.async_setup_component",
|
||||
side_effect=setup.async_setup_component,
|
||||
) as mock_setup:
|
||||
await mock_setup(hass, "comp", {})
|
||||
|
||||
assert mock_setup.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_handlers")
|
||||
async def test_component_setup_dependencies_with_config_entry(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test we wait for a dependency with config entry."""
|
||||
calls: list[str] = []
|
||||
|
||||
async def mock_async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
await asyncio.sleep(0)
|
||||
calls.append("entry")
|
||||
return True
|
||||
|
||||
mock_integration(hass, MockModule("comp", async_setup_entry=mock_async_setup_entry))
|
||||
mock_platform(hass, "comp.config_flow", None)
|
||||
MockConfigEntry(domain="comp").add_to_hass(hass)
|
||||
|
||||
async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
calls.append("comp")
|
||||
return True
|
||||
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule("comp2", dependencies=["comp"], async_setup=mock_async_setup),
|
||||
)
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule("comp3", dependencies=["comp"], async_setup=mock_async_setup),
|
||||
)
|
||||
|
||||
await asyncio.gather(
|
||||
setup.async_setup_component(hass, "comp2", {}),
|
||||
setup.async_setup_component(hass, "comp3", {}),
|
||||
)
|
||||
|
||||
assert "comp" in hass.config.components
|
||||
assert "comp2" in hass.config.components
|
||||
assert "comp3" in hass.config.components
|
||||
|
||||
assert calls == ["entry", "comp", "comp"]
|
||||
|
||||
|
||||
async def test_component_failing_setup(hass: HomeAssistant) -> None:
|
||||
"""Test component that fails setup."""
|
||||
mock_integration(hass, MockModule("comp", setup=lambda hass, config: False))
|
||||
|
Reference in New Issue
Block a user