Fix Rpi_power test race condition (#114662)
This commit is contained in:
parent
850dac0655
commit
f85511255c
1 changed files with 14 additions and 20 deletions
|
@ -6,6 +6,7 @@ from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.rpi_power import binary_sensor
|
||||||
from homeassistant.components.rpi_power.binary_sensor import (
|
from homeassistant.components.rpi_power.binary_sensor import (
|
||||||
DESCRIPTION_NORMALIZED,
|
DESCRIPTION_NORMALIZED,
|
||||||
DESCRIPTION_UNDER_VOLTAGE,
|
DESCRIPTION_UNDER_VOLTAGE,
|
||||||
|
@ -48,32 +49,25 @@ async def test_new_detected(
|
||||||
"""Test new entry with under voltage detected."""
|
"""Test new entry with under voltage detected."""
|
||||||
mocked_under_voltage = await _async_setup_component(hass, True)
|
mocked_under_voltage = await _async_setup_component(hass, True)
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(ENTITY_ID)
|
||||||
|
assert state
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert (
|
assert (
|
||||||
len(
|
binary_sensor.__name__,
|
||||||
[
|
logging.WARNING,
|
||||||
x
|
DESCRIPTION_UNDER_VOLTAGE,
|
||||||
for x in caplog.records
|
) in caplog.record_tuples
|
||||||
if x.levelno == logging.WARNING
|
|
||||||
and x.message == DESCRIPTION_UNDER_VOLTAGE
|
|
||||||
]
|
|
||||||
)
|
|
||||||
== 1
|
|
||||||
)
|
|
||||||
|
|
||||||
# back to normal
|
# back to normal
|
||||||
type(mocked_under_voltage).get = MagicMock(return_value=False)
|
type(mocked_under_voltage).get = MagicMock(return_value=False)
|
||||||
future = dt_util.utcnow() + timedelta(minutes=1)
|
future = dt_util.utcnow() + timedelta(minutes=1)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(ENTITY_ID)
|
||||||
|
assert state
|
||||||
|
assert state.state == STATE_OFF
|
||||||
assert (
|
assert (
|
||||||
len(
|
binary_sensor.__name__,
|
||||||
[
|
logging.INFO,
|
||||||
x
|
DESCRIPTION_NORMALIZED,
|
||||||
for x in caplog.records
|
) in caplog.record_tuples
|
||||||
if x.levelno == logging.INFO and x.message == DESCRIPTION_NORMALIZED
|
|
||||||
]
|
|
||||||
)
|
|
||||||
== 1
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue