Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate demo test to use freezegun #105644

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions tests/components/demo/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from unittest.mock import patch

from freezegun.api import FrozenDateTimeFactory
import pytest

from homeassistant.components.button import DOMAIN, SERVICE_PRESS
Expand Down Expand Up @@ -37,20 +38,20 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state.state == STATE_UNKNOWN


async def test_press(hass: HomeAssistant) -> None:
async def test_press(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
"""Test pressing the button."""
state = hass.states.get(ENTITY_PUSH)
assert state
assert state.state == STATE_UNKNOWN

now = dt_util.parse_datetime("2021-01-09 12:00:00+00:00")
with patch("homeassistant.util.dt.utcnow", return_value=now):
await hass.services.async_call(
DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: ENTITY_PUSH},
blocking=True,
)
freezer.move_to(now)
await hass.services.async_call(
DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: ENTITY_PUSH},
blocking=True,
)

state = hass.states.get(ENTITY_PUSH)
assert state
Expand Down
Loading