Bump ruff to 0.3.4 (#112690)

Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Joost Lekkerkerker 2024-03-26 00:02:16 +01:00 committed by GitHub
parent 27219b6962
commit 6bb4e7d62c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
1044 changed files with 24245 additions and 16750 deletions

View file

@ -46,9 +46,11 @@ from tests.typing import RecorderInstanceGenerator
def test_session_scope_not_setup(hass_recorder: Callable[..., HomeAssistant]) -> None:
"""Try to create a session scope when not setup."""
hass = hass_recorder()
with patch.object(
util.get_instance(hass), "get_session", return_value=None
), pytest.raises(RuntimeError), util.session_scope(hass=hass):
with (
patch.object(util.get_instance(hass), "get_session", return_value=None),
pytest.raises(RuntimeError),
util.session_scope(hass=hass),
):
pass
@ -65,9 +67,10 @@ def test_recorder_bad_execute(hass_recorder: Callable[..., HomeAssistant]) -> No
mck1 = MagicMock()
mck1.to_native = to_native
with pytest.raises(SQLAlchemyError), patch(
"homeassistant.components.recorder.core.time.sleep"
) as e_mock:
with (
pytest.raises(SQLAlchemyError),
patch("homeassistant.components.recorder.core.time.sleep") as e_mock,
):
util.execute((mck1,), to_native=True)
assert e_mock.call_count == 2
@ -146,12 +149,15 @@ async def test_last_run_was_recently_clean(
thirty_min_future_time = dt_util.utcnow() + timedelta(minutes=30)
async with async_test_home_assistant() as hass:
with patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
wraps=_last_run_was_recently_clean,
) as last_run_was_recently_clean_mock, patch(
"homeassistant.components.recorder.core.dt_util.utcnow",
return_value=thirty_min_future_time,
with (
patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
wraps=_last_run_was_recently_clean,
) as last_run_was_recently_clean_mock,
patch(
"homeassistant.components.recorder.core.dt_util.utcnow",
return_value=thirty_min_future_time,
),
):
await async_setup_recorder_instance(hass, config)
last_run_was_recently_clean_mock.assert_called_once()
@ -752,17 +758,23 @@ def test_combined_checks(
assert "restarted cleanly and passed the basic sanity check" in caplog.text
caplog.clear()
with patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
side_effect=sqlite3.DatabaseError,
), pytest.raises(sqlite3.DatabaseError):
with (
patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
side_effect=sqlite3.DatabaseError,
),
pytest.raises(sqlite3.DatabaseError),
):
util.run_checks_on_open_db("fake_db_path", cursor)
caplog.clear()
with patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
side_effect=sqlite3.DatabaseError,
), pytest.raises(sqlite3.DatabaseError):
with (
patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
side_effect=sqlite3.DatabaseError,
),
pytest.raises(sqlite3.DatabaseError),
):
util.run_checks_on_open_db("fake_db_path", cursor)
cursor.execute("DROP TABLE events;")