Use mock_platform
for button entity component tests instead of hass.components
(#113627)
This commit is contained in:
parent
11c570ea7b
commit
73f11064d7
4 changed files with 58 additions and 61 deletions
|
@ -1,5 +1,4 @@
|
|||
"""The tests for the Button component."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock
|
||||
|
@ -26,6 +25,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import TEST_DOMAIN
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
MockModule,
|
||||
|
@ -36,8 +37,6 @@ from tests.common import (
|
|||
mock_restore_cache,
|
||||
)
|
||||
|
||||
TEST_DOMAIN = "test"
|
||||
|
||||
|
||||
async def test_button(hass: HomeAssistant) -> None:
|
||||
"""Test getting data from the mocked button entity."""
|
||||
|
@ -60,11 +59,9 @@ async def test_custom_integration(
|
|||
caplog: pytest.LogCaptureFixture,
|
||||
enable_custom_integrations: None,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
setup_platform: None,
|
||||
) -> None:
|
||||
"""Test we integration."""
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -98,14 +95,11 @@ async def test_custom_integration(
|
|||
|
||||
|
||||
async def test_restore_state(
|
||||
hass: HomeAssistant, enable_custom_integrations: None
|
||||
hass: HomeAssistant, enable_custom_integrations: None, setup_platform: None
|
||||
) -> None:
|
||||
"""Test we restore state integration."""
|
||||
mock_restore_cache(hass, (State("button.button_1", "2021-01-01T23:59:59+00:00"),))
|
||||
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -113,14 +107,11 @@ async def test_restore_state(
|
|||
|
||||
|
||||
async def test_restore_state_does_not_restore_unavailable(
|
||||
hass: HomeAssistant, enable_custom_integrations: None
|
||||
hass: HomeAssistant, enable_custom_integrations: None, setup_platform: None
|
||||
) -> None:
|
||||
"""Test we restore state integration except for unavailable."""
|
||||
mock_restore_cache(hass, (State("button.button_1", STATE_UNAVAILABLE),))
|
||||
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue