Enable Ruff SIM117 (#86783)
This commit is contained in:
parent
57cf11f067
commit
a79885ceaf
25 changed files with 441 additions and 453 deletions
|
@ -21,8 +21,9 @@ def get_cert(
|
||||||
"""Get the certificate for the host and port combination."""
|
"""Get the certificate for the host and port combination."""
|
||||||
ctx = ssl.create_default_context()
|
ctx = ssl.create_default_context()
|
||||||
address = (host, port)
|
address = (host, port)
|
||||||
with socket.create_connection(address, timeout=TIMEOUT) as sock:
|
with socket.create_connection(address, timeout=TIMEOUT) as sock, ctx.wrap_socket(
|
||||||
with ctx.wrap_socket(sock, server_hostname=address[0]) as ssock:
|
sock, server_hostname=address[0]
|
||||||
|
) as ssock:
|
||||||
cert = ssock.getpeercert()
|
cert = ssock.getpeercert()
|
||||||
return cert
|
return cert
|
||||||
|
|
||||||
|
|
|
@ -661,8 +661,9 @@ def _apply_update( # noqa: C901
|
||||||
),
|
),
|
||||||
table,
|
table,
|
||||||
)
|
)
|
||||||
with contextlib.suppress(SQLAlchemyError):
|
with contextlib.suppress(SQLAlchemyError), session_scope(
|
||||||
with session_scope(session=session_maker()) as session:
|
session=session_maker()
|
||||||
|
) as session:
|
||||||
connection = session.connection()
|
connection = session.connection()
|
||||||
connection.execute(
|
connection.execute(
|
||||||
# Using LOCK=EXCLUSIVE to prevent
|
# Using LOCK=EXCLUSIVE to prevent
|
||||||
|
@ -804,8 +805,9 @@ def _apply_update( # noqa: C901
|
||||||
if engine.dialect.name == SupportedDialect.MYSQL:
|
if engine.dialect.name == SupportedDialect.MYSQL:
|
||||||
# Ensure the row format is dynamic or the index
|
# Ensure the row format is dynamic or the index
|
||||||
# unique will be too large
|
# unique will be too large
|
||||||
with contextlib.suppress(SQLAlchemyError):
|
with contextlib.suppress(SQLAlchemyError), session_scope(
|
||||||
with session_scope(session=session_maker()) as session:
|
session=session_maker()
|
||||||
|
) as session:
|
||||||
connection = session.connection()
|
connection = session.connection()
|
||||||
# This is safe to run multiple times and fast
|
# This is safe to run multiple times and fast
|
||||||
# since the table is small.
|
# since the table is small.
|
||||||
|
|
|
@ -2422,8 +2422,9 @@ def correct_db_schema(
|
||||||
),
|
),
|
||||||
"statistics_meta",
|
"statistics_meta",
|
||||||
)
|
)
|
||||||
with contextlib.suppress(SQLAlchemyError):
|
with contextlib.suppress(SQLAlchemyError), session_scope(
|
||||||
with session_scope(session=session_maker()) as session:
|
session=session_maker()
|
||||||
|
) as session:
|
||||||
connection = session.connection()
|
connection = session.connection()
|
||||||
connection.execute(
|
connection.execute(
|
||||||
# Using LOCK=EXCLUSIVE to prevent the database from corrupting
|
# Using LOCK=EXCLUSIVE to prevent the database from corrupting
|
||||||
|
|
|
@ -248,6 +248,7 @@ select = [
|
||||||
"F", # pyflakes/autoflake
|
"F", # pyflakes/autoflake
|
||||||
"PGH004", # Use specific rule codes when using noqa
|
"PGH004", # Use specific rule codes when using noqa
|
||||||
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
|
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
|
||||||
|
"SIM117", # Merge with-statements that use the same scope
|
||||||
"T20", # flake8-print
|
"T20", # flake8-print
|
||||||
"UP", # pyupgrade
|
"UP", # pyupgrade
|
||||||
"W", # pycodestyle
|
"W", # pycodestyle
|
||||||
|
|
|
@ -24,8 +24,7 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
async def test_bluetooth_discovery(hass: HomeAssistant):
|
async def test_bluetooth_discovery(hass: HomeAssistant):
|
||||||
"""Test discovery via bluetooth with a valid device."""
|
"""Test discovery via bluetooth with a valid device."""
|
||||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO):
|
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||||
with patch_airthings_ble(
|
|
||||||
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -66,8 +65,9 @@ async def test_bluetooth_discovery_airthings_ble_update_failed(
|
||||||
"""Test discovery via bluetooth but there's an exception from airthings-ble."""
|
"""Test discovery via bluetooth but there's an exception from airthings-ble."""
|
||||||
for loop in [(Exception(), "unknown"), (BleakError(), "cannot_connect")]:
|
for loop in [(Exception(), "unknown"), (BleakError(), "cannot_connect")]:
|
||||||
exc, reason = loop
|
exc, reason = loop
|
||||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO):
|
with patch_async_ble_device_from_address(
|
||||||
with patch_airthings_ble(side_effect=exc):
|
WAVE_SERVICE_INFO
|
||||||
|
), patch_airthings_ble(side_effect=exc):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_BLUETOOTH},
|
context={"source": SOURCE_BLUETOOTH},
|
||||||
|
@ -99,9 +99,7 @@ async def test_user_setup(hass: HomeAssistant):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
||||||
return_value=[WAVE_SERVICE_INFO],
|
return_value=[WAVE_SERVICE_INFO],
|
||||||
):
|
), patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO):
|
|
||||||
with patch_airthings_ble(
|
|
||||||
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -167,9 +165,9 @@ async def test_user_setup_unknown_error(hass: HomeAssistant):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
||||||
return_value=[WAVE_SERVICE_INFO],
|
return_value=[WAVE_SERVICE_INFO],
|
||||||
|
), patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||||
|
None, Exception()
|
||||||
):
|
):
|
||||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO):
|
|
||||||
with patch_airthings_ble(None, Exception()):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
@ -183,9 +181,9 @@ async def test_user_setup_unable_to_connect(hass: HomeAssistant):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
||||||
return_value=[WAVE_SERVICE_INFO],
|
return_value=[WAVE_SERVICE_INFO],
|
||||||
|
), patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||||
|
side_effect=BleakError("An error")
|
||||||
):
|
):
|
||||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO):
|
|
||||||
with patch_airthings_ble(side_effect=BleakError("An error")):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
|
@ -85,6 +85,5 @@ async def test_device(hass, config_entry, aioclient_mock_fixture, aioclient_mock
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.flo.device.FloDeviceDataUpdateCoordinator.send_presence_ping",
|
"homeassistant.components.flo.device.FloDeviceDataUpdateCoordinator.send_presence_ping",
|
||||||
side_effect=RequestError,
|
side_effect=RequestError,
|
||||||
):
|
), pytest.raises(UpdateFailed):
|
||||||
with pytest.raises(UpdateFailed):
|
|
||||||
await valve._async_update_data()
|
await valve._async_update_data()
|
||||||
|
|
|
@ -629,9 +629,7 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_sin
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.recorder.history.state_changes_during_period",
|
"homeassistant.components.recorder.history.state_changes_during_period",
|
||||||
_fake_states,
|
_fake_states,
|
||||||
):
|
), freeze_time(start_time):
|
||||||
|
|
||||||
with freeze_time(start_time):
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"sensor",
|
"sensor",
|
||||||
|
@ -729,9 +727,7 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_sin
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.recorder.history.state_changes_during_period",
|
"homeassistant.components.recorder.history.state_changes_during_period",
|
||||||
_fake_states,
|
_fake_states,
|
||||||
):
|
), freeze_time(start_time):
|
||||||
|
|
||||||
with freeze_time(start_time):
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"sensor",
|
"sensor",
|
||||||
|
@ -828,9 +824,7 @@ async def test_async_start_from_history_and_switch_to_watching_state_changes_mul
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.recorder.history.state_changes_during_period",
|
"homeassistant.components.recorder.history.state_changes_during_period",
|
||||||
_fake_states,
|
_fake_states,
|
||||||
):
|
), freeze_time(start_time):
|
||||||
|
|
||||||
with freeze_time(start_time):
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"sensor",
|
"sensor",
|
||||||
|
|
|
@ -140,8 +140,7 @@ async def test_reauthentication_flow(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.lyric.api.ConfigEntryLyricClient"):
|
with patch("homeassistant.components.lyric.api.ConfigEntryLyricClient"), patch(
|
||||||
with patch(
|
|
||||||
"homeassistant.components.lyric.async_setup_entry", return_value=True
|
"homeassistant.components.lyric.async_setup_entry", return_value=True
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
|
@ -997,8 +997,9 @@ async def test_switch_failure(hass: HomeAssistant, exc: Exception) -> None:
|
||||||
"""Tests that the turn on/off service throws HomeAssistantError."""
|
"""Tests that the turn on/off service throws HomeAssistantError."""
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
with patch("homeassistant.components.nextdns.NextDns.set_setting", side_effect=exc):
|
with patch(
|
||||||
with pytest.raises(HomeAssistantError):
|
"homeassistant.components.nextdns.NextDns.set_setting", side_effect=exc
|
||||||
|
), pytest.raises(HomeAssistantError):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
|
|
|
@ -29,8 +29,7 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||||
outage_count=0,
|
outage_count=0,
|
||||||
customers_served=350394,
|
customers_served=350394,
|
||||||
),
|
),
|
||||||
):
|
), patch(
|
||||||
with patch(
|
|
||||||
"peco.PecoOutageApi.get_map_alerts",
|
"peco.PecoOutageApi.get_map_alerts",
|
||||||
return_value=AlertResults(
|
return_value=AlertResults(
|
||||||
alert_content="Testing 1234", alert_title="Testing 4321"
|
alert_content="Testing 1234", alert_title="Testing 4321"
|
||||||
|
|
|
@ -41,8 +41,7 @@ async def test_sensor_available(
|
||||||
outage_count=456,
|
outage_count=456,
|
||||||
customers_served=789,
|
customers_served=789,
|
||||||
),
|
),
|
||||||
):
|
), patch(
|
||||||
with patch(
|
|
||||||
"peco.PecoOutageApi.get_map_alerts",
|
"peco.PecoOutageApi.get_map_alerts",
|
||||||
return_value=AlertResults(
|
return_value=AlertResults(
|
||||||
alert_content="Testing 1234", alert_title="Testing 4321"
|
alert_content="Testing 1234", alert_title="Testing 4321"
|
||||||
|
@ -74,8 +73,7 @@ async def test_sensor_available(
|
||||||
outage_count=456,
|
outage_count=456,
|
||||||
customers_served=789,
|
customers_served=789,
|
||||||
),
|
),
|
||||||
):
|
), patch(
|
||||||
with patch(
|
|
||||||
"peco.PecoOutageApi.get_map_alerts",
|
"peco.PecoOutageApi.get_map_alerts",
|
||||||
return_value=AlertResults(
|
return_value=AlertResults(
|
||||||
alert_content="Testing 1234", alert_title="Testing 4321"
|
alert_content="Testing 1234", alert_title="Testing 4321"
|
||||||
|
|
|
@ -832,8 +832,7 @@ async def test_client_request_missing(hass):
|
||||||
|
|
||||||
with patch("plexauth.PlexAuth.initiate_auth"), patch(
|
with patch("plexauth.PlexAuth.initiate_auth"), patch(
|
||||||
"plexauth.PlexAuth.token", return_value=None
|
"plexauth.PlexAuth.token", return_value=None
|
||||||
):
|
), pytest.raises(RuntimeError):
|
||||||
with pytest.raises(RuntimeError):
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
@ -855,8 +854,9 @@ async def test_client_header_issues(hass, current_request_with_host):
|
||||||
"plexauth.PlexAuth.token", return_value=None
|
"plexauth.PlexAuth.token", return_value=None
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.http.current_request.get", return_value=MockRequest()
|
"homeassistant.components.http.current_request.get", return_value=MockRequest()
|
||||||
|
), pytest.raises(
|
||||||
|
RuntimeError
|
||||||
):
|
):
|
||||||
with pytest.raises(RuntimeError):
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,8 +33,9 @@ async def test_media_lookups(hass, mock_plex_server, requests_mock, playqueue_cr
|
||||||
},
|
},
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
with pytest.raises(MediaNotFound) as excinfo:
|
with pytest.raises(MediaNotFound) as excinfo, patch(
|
||||||
with patch("plexapi.server.PlexServer.fetchItem", side_effect=NotFound):
|
"plexapi.server.PlexServer.fetchItem", side_effect=NotFound
|
||||||
|
):
|
||||||
assert await hass.services.async_call(
|
assert await hass.services.async_call(
|
||||||
MEDIA_PLAYER_DOMAIN,
|
MEDIA_PLAYER_DOMAIN,
|
||||||
SERVICE_PLAY_MEDIA,
|
SERVICE_PLAY_MEDIA,
|
||||||
|
|
|
@ -62,8 +62,9 @@ async def test_media_player_playback(
|
||||||
|
|
||||||
# Test media lookup failure
|
# Test media lookup failure
|
||||||
payload = '{"library_name": "Movies", "title": "Movie 1" }'
|
payload = '{"library_name": "Movies", "title": "Movie 1" }'
|
||||||
with patch("plexapi.library.LibrarySection.search", return_value=None):
|
with patch(
|
||||||
with pytest.raises(HomeAssistantError) as excinfo:
|
"plexapi.library.LibrarySection.search", return_value=None
|
||||||
|
), pytest.raises(HomeAssistantError) as excinfo:
|
||||||
assert await hass.services.async_call(
|
assert await hass.services.async_call(
|
||||||
MP_DOMAIN,
|
MP_DOMAIN,
|
||||||
SERVICE_PLAY_MEDIA,
|
SERVICE_PLAY_MEDIA,
|
||||||
|
|
|
@ -37,8 +37,7 @@ def test_session_scope_not_setup(hass_recorder):
|
||||||
hass = hass_recorder()
|
hass = hass_recorder()
|
||||||
with patch.object(
|
with patch.object(
|
||||||
util.get_instance(hass), "get_session", return_value=None
|
util.get_instance(hass), "get_session", return_value=None
|
||||||
), pytest.raises(RuntimeError):
|
), pytest.raises(RuntimeError), util.session_scope(hass=hass):
|
||||||
with util.session_scope(hass=hass):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -689,9 +688,8 @@ async def test_write_lock_db(
|
||||||
with instance.engine.connect() as connection:
|
with instance.engine.connect() as connection:
|
||||||
connection.execute(text("DROP TABLE events;"))
|
connection.execute(text("DROP TABLE events;"))
|
||||||
|
|
||||||
with util.write_lock_db_sqlite(instance):
|
with util.write_lock_db_sqlite(instance), pytest.raises(OperationalError):
|
||||||
# Database should be locked now, try writing SQL command
|
# Database should be locked now, try writing SQL command
|
||||||
with pytest.raises(OperationalError):
|
|
||||||
# This needs to be called in another thread since
|
# This needs to be called in another thread since
|
||||||
# the lock method is BEGIN IMMEDIATE and since we have
|
# the lock method is BEGIN IMMEDIATE and since we have
|
||||||
# a connection per thread with sqlite now, we cannot do it
|
# a connection per thread with sqlite now, we cannot do it
|
||||||
|
|
|
@ -92,8 +92,7 @@ async def test_service_set_ac_cancel(
|
||||||
with patch(
|
with patch(
|
||||||
"renault_api.renault_vehicle.RenaultVehicle.set_ac_stop",
|
"renault_api.renault_vehicle.RenaultVehicle.set_ac_stop",
|
||||||
side_effect=RenaultException("Didn't work"),
|
side_effect=RenaultException("Didn't work"),
|
||||||
) as mock_action:
|
) as mock_action, pytest.raises(HomeAssistantError, match="Didn't work"):
|
||||||
with pytest.raises(HomeAssistantError, match="Didn't work"):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_AC_CANCEL, service_data=data, blocking=True
|
DOMAIN, SERVICE_AC_CANCEL, service_data=data, blocking=True
|
||||||
)
|
)
|
||||||
|
|
|
@ -97,8 +97,9 @@ async def test_button_failure(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_reset_filter",
|
"homeassistant.components.sensibo.util.SensiboClient.async_reset_filter",
|
||||||
return_value={"status": "failure"},
|
return_value={"status": "failure"},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
BUTTON_DOMAIN,
|
BUTTON_DOMAIN,
|
||||||
SERVICE_PRESS,
|
SERVICE_PRESS,
|
||||||
|
|
|
@ -168,8 +168,7 @@ async def test_climate_fan(
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
):
|
), pytest.raises(HomeAssistantError):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_FAN_MODE,
|
SERVICE_SET_FAN_MODE,
|
||||||
|
@ -235,8 +234,7 @@ async def test_climate_swing(
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
):
|
), pytest.raises(HomeAssistantError):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_SWING_MODE,
|
SERVICE_SET_SWING_MODE,
|
||||||
|
@ -353,8 +351,7 @@ async def test_climate_temperatures(
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
return_value={"result": {"status": "Success"}},
|
return_value={"result": {"status": "Success"}},
|
||||||
):
|
), pytest.raises(MultipleInvalid):
|
||||||
with pytest.raises(MultipleInvalid):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
@ -391,8 +388,7 @@ async def test_climate_temperatures(
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
return_value={"result": {"status": "Success"}},
|
return_value={"result": {"status": "Success"}},
|
||||||
):
|
), pytest.raises(HomeAssistantError):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
@ -447,8 +443,7 @@ async def test_climate_temperature_is_none(
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
):
|
), pytest.raises(ValueError):
|
||||||
with pytest.raises(ValueError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
@ -634,8 +629,7 @@ async def test_climate_service_failed(
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
return_value={"result": {"status": "Error", "failureReason": "Did not work"}},
|
return_value={"result": {"status": "Error", "failureReason": "Did not work"}},
|
||||||
):
|
), pytest.raises(HomeAssistantError):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
|
@ -752,8 +746,9 @@ async def test_climate_set_timer(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
||||||
return_value={"status": "failure"},
|
return_value={"status": "failure"},
|
||||||
|
), pytest.raises(
|
||||||
|
MultipleInvalid
|
||||||
):
|
):
|
||||||
with pytest.raises(MultipleInvalid):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_ENABLE_TIMER,
|
SERVICE_ENABLE_TIMER,
|
||||||
|
@ -770,8 +765,9 @@ async def test_climate_set_timer(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
||||||
return_value={"status": "failure"},
|
return_value={"status": "failure"},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_ENABLE_TIMER,
|
SERVICE_ENABLE_TIMER,
|
||||||
|
@ -853,8 +849,9 @@ async def test_climate_pure_boost(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_pureboost",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_pureboost",
|
||||||
|
), pytest.raises(
|
||||||
|
MultipleInvalid
|
||||||
):
|
):
|
||||||
with pytest.raises(MultipleInvalid):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_ENABLE_PURE_BOOST,
|
SERVICE_ENABLE_PURE_BOOST,
|
||||||
|
@ -954,8 +951,9 @@ async def test_climate_climate_react(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_climate_react",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_climate_react",
|
||||||
|
), pytest.raises(
|
||||||
|
MultipleInvalid
|
||||||
):
|
):
|
||||||
with pytest.raises(MultipleInvalid):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_ENABLE_PURE_BOOST,
|
SERVICE_ENABLE_PURE_BOOST,
|
||||||
|
@ -1260,8 +1258,9 @@ async def test_climate_full_ac_state(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_states",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_states",
|
||||||
|
), pytest.raises(
|
||||||
|
MultipleInvalid
|
||||||
):
|
):
|
||||||
with pytest.raises(MultipleInvalid):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_FULL_STATE,
|
SERVICE_FULL_STATE,
|
||||||
|
|
|
@ -75,8 +75,7 @@ async def test_entity_failed_service_calls(
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
side_effect=p_error,
|
side_effect=p_error,
|
||||||
):
|
), pytest.raises(HomeAssistantError):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_FAN_MODE,
|
SERVICE_SET_FAN_MODE,
|
||||||
|
|
|
@ -89,8 +89,9 @@ async def test_select_set_option(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
return_value={"result": {"status": "failed"}},
|
return_value={"result": {"status": "failed"}},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SELECT_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
|
@ -130,8 +131,9 @@ async def test_select_set_option(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
|
||||||
return_value={"result": {"status": "Failed", "failureReason": "No connection"}},
|
return_value={"result": {"status": "Failed", "failureReason": "No connection"}},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SELECT_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
|
|
|
@ -195,8 +195,9 @@ async def test_switch_command_failure(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
"homeassistant.components.sensibo.util.SensiboClient.async_set_timer",
|
||||||
return_value={"status": "failure"},
|
return_value={"status": "failure"},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
|
@ -212,8 +213,9 @@ async def test_switch_command_failure(
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.sensibo.util.SensiboClient.async_del_timer",
|
"homeassistant.components.sensibo.util.SensiboClient.async_del_timer",
|
||||||
return_value={"status": "failure"},
|
return_value={"status": "failure"},
|
||||||
|
), pytest.raises(
|
||||||
|
HomeAssistantError
|
||||||
):
|
):
|
||||||
with pytest.raises(HomeAssistantError):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
|
|
|
@ -72,8 +72,7 @@ def test_send_message_to_api_with_bad_data_throws_error(
|
||||||
signal_requests_mock = signal_requests_mock_factory(False)
|
signal_requests_mock = signal_requests_mock_factory(False)
|
||||||
with caplog.at_level(
|
with caplog.at_level(
|
||||||
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
||||||
):
|
), pytest.raises(SignalCliRestApiError) as exc:
|
||||||
with pytest.raises(SignalCliRestApiError) as exc:
|
|
||||||
signal_notification_service.send_message(MESSAGE)
|
signal_notification_service.send_message(MESSAGE)
|
||||||
|
|
||||||
assert "Sending signal message" in caplog.text
|
assert "Sending signal message" in caplog.text
|
||||||
|
@ -90,8 +89,7 @@ def test_send_message_with_bad_data_throws_vol_error(
|
||||||
"""Test sending a message with bad data throws an error."""
|
"""Test sending a message with bad data throws an error."""
|
||||||
with caplog.at_level(
|
with caplog.at_level(
|
||||||
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
||||||
):
|
), pytest.raises(vol.Invalid) as exc:
|
||||||
with pytest.raises(vol.Invalid) as exc:
|
|
||||||
data = {"test": "test"}
|
data = {"test": "test"}
|
||||||
signal_notification_service.send_message(MESSAGE, **{"data": data})
|
signal_notification_service.send_message(MESSAGE, **{"data": data})
|
||||||
|
|
||||||
|
@ -108,8 +106,7 @@ def test_send_message_with_attachment(
|
||||||
signal_requests_mock = signal_requests_mock_factory()
|
signal_requests_mock = signal_requests_mock_factory()
|
||||||
with caplog.at_level(
|
with caplog.at_level(
|
||||||
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
|
||||||
):
|
), tempfile.NamedTemporaryFile(
|
||||||
with tempfile.NamedTemporaryFile(
|
|
||||||
mode="w", suffix=".png", prefix=os.path.basename(__file__)
|
mode="w", suffix=".png", prefix=os.path.basename(__file__)
|
||||||
) as temp_file:
|
) as temp_file:
|
||||||
temp_file.write("attachment_data")
|
temp_file.write("attachment_data")
|
||||||
|
|
|
@ -125,8 +125,7 @@ async def test_discovery(hass, pywemo_registry):
|
||||||
# Setup the component and start discovery.
|
# Setup the component and start discovery.
|
||||||
with patch(
|
with patch(
|
||||||
"pywemo.discover_devices", return_value=pywemo_devices
|
"pywemo.discover_devices", return_value=pywemo_devices
|
||||||
) as mock_discovery:
|
) as mock_discovery, patch(
|
||||||
with patch(
|
|
||||||
"homeassistant.components.wemo.WemoDiscovery.discover_statics"
|
"homeassistant.components.wemo.WemoDiscovery.discover_statics"
|
||||||
) as mock_discover_statics:
|
) as mock_discover_statics:
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -192,8 +192,7 @@ async def test_reauthentication(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.yolink.api.ConfigEntryAuth"):
|
with patch("homeassistant.components.yolink.api.ConfigEntryAuth"), patch(
|
||||||
with patch(
|
|
||||||
"homeassistant.components.yolink.async_setup_entry", return_value=True
|
"homeassistant.components.yolink.async_setup_entry", return_value=True
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
|
@ -256,8 +256,7 @@ async def test_gateway_initialize_failure(hass, device_light_1, coordinator):
|
||||||
with patch(
|
with patch(
|
||||||
"bellows.zigbee.application.ControllerApplication.new",
|
"bellows.zigbee.application.ControllerApplication.new",
|
||||||
side_effect=[asyncio.TimeoutError(), FileNotFoundError(), RuntimeError()],
|
side_effect=[asyncio.TimeoutError(), FileNotFoundError(), RuntimeError()],
|
||||||
) as mock_new:
|
) as mock_new, pytest.raises(RuntimeError):
|
||||||
with pytest.raises(RuntimeError):
|
|
||||||
await zha_gateway.async_initialize()
|
await zha_gateway.async_initialize()
|
||||||
|
|
||||||
assert mock_new.call_count == 3
|
assert mock_new.call_count == 3
|
||||||
|
@ -272,8 +271,7 @@ async def test_gateway_initialize_failure_transient(hass, device_light_1, coordi
|
||||||
with patch(
|
with patch(
|
||||||
"bellows.zigbee.application.ControllerApplication.new",
|
"bellows.zigbee.application.ControllerApplication.new",
|
||||||
side_effect=[RuntimeError(), zigpy.exceptions.TransientConnectionError()],
|
side_effect=[RuntimeError(), zigpy.exceptions.TransientConnectionError()],
|
||||||
) as mock_new:
|
) as mock_new, pytest.raises(ConfigEntryNotReady):
|
||||||
with pytest.raises(ConfigEntryNotReady):
|
|
||||||
await zha_gateway.async_initialize()
|
await zha_gateway.async_initialize()
|
||||||
|
|
||||||
# Initialization immediately stops and is retried after TransientConnectionError
|
# Initialization immediately stops and is retried after TransientConnectionError
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue