Use builtin TimeoutError [core + helpers] (#109684)

This commit is contained in:
Marc Mueller
2024-02-05 12:09:54 +01:00
committed by GitHub
parent a9147cf3dd
commit cd0ee98dba
19 changed files with 70 additions and 74 deletions

View File

@@ -654,7 +654,7 @@ async def test_delay_basic(hass: HomeAssistant) -> None:
assert script_obj.is_running
assert script_obj.last_action == delay_alias
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -695,7 +695,7 @@ async def test_multiple_runs_delay(hass: HomeAssistant) -> None:
assert script_obj.is_running
assert len(events) == 1
assert events[-1].data["value"] == 1
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -725,7 +725,7 @@ async def test_delay_template_ok(hass: HomeAssistant) -> None:
await asyncio.wait_for(delay_started_flag.wait(), 1)
assert script_obj.is_running
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -792,7 +792,7 @@ async def test_delay_template_complex_ok(hass: HomeAssistant) -> None:
hass.async_create_task(script_obj.async_run(context=Context()))
await asyncio.wait_for(delay_started_flag.wait(), 1)
assert script_obj.is_running
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -859,7 +859,7 @@ async def test_cancel_delay(hass: HomeAssistant) -> None:
assert script_obj.is_running
assert len(events) == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -908,7 +908,7 @@ async def test_wait_basic(hass: HomeAssistant, action_type) -> None:
assert script_obj.is_running
assert script_obj.last_action == wait_alias
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -991,7 +991,7 @@ async def test_wait_for_trigger_variables(hass: HomeAssistant) -> None:
assert script_obj.last_action == wait_alias
hass.states.async_set("switch.test", "off")
await hass.async_block_till_done()
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1028,7 +1028,7 @@ async def test_wait_basic_times_out(hass: HomeAssistant, action_type) -> None:
async with asyncio.timeout(0.1):
await hass.async_block_till_done()
except asyncio.TimeoutError:
except TimeoutError:
timed_out = True
await script_obj.async_stop()
@@ -1101,7 +1101,7 @@ async def test_multiple_runs_wait(hass: HomeAssistant, action_type) -> None:
hass.async_create_task(script_obj.async_run())
await asyncio.wait_for(wait_started_flag.wait(), 1)
await asyncio.sleep(0)
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1142,7 +1142,7 @@ async def test_cancel_wait(hass: HomeAssistant, action_type) -> None:
assert script_obj.is_running
assert len(events) == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1252,7 +1252,7 @@ async def test_wait_timeout(
assert script_obj.is_running
assert len(events) == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1320,7 +1320,7 @@ async def test_wait_continue_on_timeout(
assert script_obj.is_running
assert len(events) == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1363,7 +1363,7 @@ async def test_wait_template_variables_in(hass: HomeAssistant) -> None:
await asyncio.wait_for(wait_started_flag.wait(), 1)
assert script_obj.is_running
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1404,7 +1404,7 @@ async def test_wait_template_with_utcnow(hass: HomeAssistant) -> None:
match_time = start_time.replace(hour=12)
with freeze_time(match_time):
async_fire_time_changed(hass, match_time)
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -1444,7 +1444,7 @@ async def test_wait_template_with_utcnow_no_match(hass: HomeAssistant) -> None:
async with asyncio.timeout(0.1):
await hass.async_block_till_done()
except asyncio.TimeoutError:
except TimeoutError:
timed_out = True
await script_obj.async_stop()
@@ -1505,7 +1505,7 @@ async def test_wait_variables_out(hass: HomeAssistant, mode, action_type) -> Non
assert script_obj.is_running
assert len(events) == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -2450,7 +2450,7 @@ async def test_repeat_conditional(
wait_started.clear()
hass.states.async_set("sensor.test", "done")
await asyncio.wait_for(hass.async_block_till_done(), 1)
except asyncio.TimeoutError:
except TimeoutError:
await script_obj.async_stop()
raise
@@ -4069,7 +4069,7 @@ async def test_script_mode_single(
assert "Already running" in caplog.text
assert script_obj.is_running
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -4204,7 +4204,7 @@ async def test_script_mode_2(
)
for message in messages
)
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -4299,7 +4299,7 @@ async def test_script_mode_queued(hass: HomeAssistant) -> None:
assert script_obj.runs == 1
assert len(events) == 3
assert events[2].data["value"] == 1
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -4351,7 +4351,7 @@ async def test_script_mode_queued_cancel(hass: HomeAssistant) -> None:
assert not script_obj.is_running
assert script_obj.runs == 0
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
@@ -4412,7 +4412,7 @@ async def test_shutdown_at(
assert script_obj.is_running
assert script_obj.last_action == delay_alias
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else:
@@ -4448,7 +4448,7 @@ async def test_shutdown_after(
assert script_obj.is_running
assert script_obj.last_action == delay_alias
except (AssertionError, asyncio.TimeoutError):
except (AssertionError, TimeoutError):
await script_obj.async_stop()
raise
else: