Avoid CI fail in command_line tests (#96324)

* Avoid CI fail in command_line tests

* Speedup tests manual update
This commit is contained in:
Jan Bouwhuis 2023-07-11 15:27:31 +02:00 committed by GitHub
parent d9f27400b7
commit f12f8bca03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 38 deletions

View file

@ -240,16 +240,18 @@ async def test_updating_to_often(
)
await hass.async_block_till_done()
assert len(called) == 1
assert called
assert (
"Updating Command Line Binary Sensor Test took longer than the scheduled update interval"
not in caplog.text
)
called.clear()
caplog.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1))
await hass.async_block_till_done()
assert len(called) == 2
assert called
assert (
"Updating Command Line Binary Sensor Test took longer than the scheduled update interval"
in caplog.text
@ -266,13 +268,11 @@ async def test_updating_manually(
called = []
class MockCommandBinarySensor(CommandBinarySensor):
"""Mock entity that updates slow."""
"""Mock entity that updates."""
async def _async_update(self) -> None:
"""Update slow."""
"""Update."""
called.append(1)
# Add waiting time
await asyncio.sleep(1)
with patch(
"homeassistant.components.command_line.binary_sensor.CommandBinarySensor",
@ -297,7 +297,8 @@ async def test_updating_manually(
)
await hass.async_block_till_done()
assert len(called) == 1
assert called
called.clear
await hass.services.async_call(
HA_DOMAIN,
@ -306,6 +307,4 @@ async def test_updating_manually(
blocking=True,
)
await hass.async_block_till_done()
assert len(called) == 2
await asyncio.sleep(0.2)
assert called

View file

@ -326,16 +326,18 @@ async def test_updating_to_often(
)
await hass.async_block_till_done()
assert len(called) == 0
assert not called
assert (
"Updating Command Line Cover Test took longer than the scheduled update interval"
not in caplog.text
)
called.clear()
caplog.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1))
await hass.async_block_till_done()
assert len(called) == 1
assert called
assert (
"Updating Command Line Cover Test took longer than the scheduled update interval"
in caplog.text
@ -352,13 +354,11 @@ async def test_updating_manually(
called = []
class MockCommandCover(CommandCover):
"""Mock entity that updates slow."""
"""Mock entity that updates."""
async def _async_update(self) -> None:
"""Update slow."""
"""Update."""
called.append(1)
# Add waiting time
await asyncio.sleep(1)
with patch(
"homeassistant.components.command_line.cover.CommandCover",
@ -384,7 +384,8 @@ async def test_updating_manually(
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(called) == 1
assert called
called.clear()
await hass.services.async_call(
HA_DOMAIN,
@ -393,6 +394,4 @@ async def test_updating_manually(
blocking=True,
)
await hass.async_block_till_done()
assert len(called) == 2
await asyncio.sleep(0.2)
assert called

View file

@ -575,16 +575,18 @@ async def test_updating_to_often(
)
await hass.async_block_till_done()
assert len(called) == 1
assert called
assert (
"Updating Command Line Sensor Test took longer than the scheduled update interval"
not in caplog.text
)
called.clear()
caplog.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1))
await hass.async_block_till_done()
assert len(called) == 2
assert called
assert (
"Updating Command Line Sensor Test took longer than the scheduled update interval"
in caplog.text
@ -601,13 +603,11 @@ async def test_updating_manually(
called = []
class MockCommandSensor(CommandSensor):
"""Mock entity that updates slow."""
"""Mock entity that updates."""
async def _async_update(self) -> None:
"""Update slow."""
called.append(1)
# Add waiting time
await asyncio.sleep(1)
with patch(
"homeassistant.components.command_line.sensor.CommandSensor",
@ -630,7 +630,8 @@ async def test_updating_manually(
)
await hass.async_block_till_done()
assert len(called) == 1
assert called
called.clear()
await hass.services.async_call(
HA_DOMAIN,
@ -639,6 +640,4 @@ async def test_updating_manually(
blocking=True,
)
await hass.async_block_till_done()
assert len(called) == 2
await asyncio.sleep(0.2)
assert called

View file

@ -684,16 +684,18 @@ async def test_updating_to_often(
)
await hass.async_block_till_done()
assert len(called) == 0
assert not called
assert (
"Updating Command Line Switch Test took longer than the scheduled update interval"
not in caplog.text
)
called.clear()
caplog.clear()
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1))
await hass.async_block_till_done()
assert len(called) == 1
assert called
assert (
"Updating Command Line Switch Test took longer than the scheduled update interval"
in caplog.text
@ -710,13 +712,11 @@ async def test_updating_manually(
called = []
class MockCommandSwitch(CommandSwitch):
"""Mock entity that updates slow."""
"""Mock entity that updates."""
async def _async_update(self) -> None:
"""Update slow."""
called.append(1)
# Add waiting time
await asyncio.sleep(1)
with patch(
"homeassistant.components.command_line.switch.CommandSwitch",
@ -743,7 +743,8 @@ async def test_updating_manually(
async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(called) == 1
assert called
called.clear()
await hass.services.async_call(
HA_DOMAIN,
@ -752,6 +753,4 @@ async def test_updating_manually(
blocking=True,
)
await hass.async_block_till_done()
assert len(called) == 2
await asyncio.sleep(0.2)
assert called