Improve formatting in component test files (#135267)

Improve formatting in test files
This commit is contained in:
epenet 2025-01-10 10:53:45 +01:00 committed by GitHub
parent 9d1989125f
commit 02956f9a83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 52 additions and 59 deletions

View File

@ -99,9 +99,9 @@ async def test_services_remote(hass: HomeAssistant, config) -> None:
"adb_shell",
{ATTR_COMMAND: ["BACK", "test"], ATTR_NUM_REPEATS: 2},
[
f"input keyevent {KEYS["BACK"]}",
f"input keyevent {KEYS['BACK']}",
"test",
f"input keyevent {KEYS["BACK"]}",
f"input keyevent {KEYS['BACK']}",
"test",
],
)

View File

@ -63,12 +63,12 @@ async def test_camera(
assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
assert (
camera_entity.mjpeg_source == "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi"
f"{"" if not stream_profile else f"?{stream_profile}"}"
f"{'' if not stream_profile else f'?{stream_profile}'}"
)
assert (
await camera_entity.stream_source()
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264"
f"{"" if not stream_profile else f"&{stream_profile}"}"
f"{'' if not stream_profile else f'&{stream_profile}'}"
)

View File

@ -383,7 +383,7 @@ async def test_async_initiate_backup(
tar_file_path = str(mocked_tarfile.call_args_list[0][0][0])
backup_directory = hass.config.path(backup_directory)
assert tar_file_path == f"{backup_directory}/{backup_data["backup_id"]}.tar"
assert tar_file_path == f"{backup_directory}/{backup_data['backup_id']}.tar"
@pytest.mark.usefixtures("mock_backup_generation")

View File

@ -92,7 +92,7 @@ async def test_slots_switch_setup_works(
for slot, switch in enumerate(switches):
assert (
hass.states.get(switch.entity_id).attributes[ATTR_FRIENDLY_NAME]
== f"{device.name} S{slot+1}"
== f"{device.name} S{slot + 1}"
)
assert hass.states.get(switch.entity_id).state == STATE_OFF
assert mock_setup.api.auth.call_count == 1

View File

@ -766,10 +766,7 @@ async def test_if_fires_on_position(
]
) == sorted(
[
(
f"is_pos_gt_45_lt_90 - device - {entry.entity_id} - closed - open"
" - None"
),
f"is_pos_gt_45_lt_90 - device - {entry.entity_id} - closed - open - None",
f"is_pos_lt_90 - device - {entry.entity_id} - closed - open - None",
f"is_pos_gt_45 - device - {entry.entity_id} - open - closed - None",
]
@ -925,10 +922,7 @@ async def test_if_fires_on_tilt_position(
]
) == sorted(
[
(
f"is_pos_gt_45_lt_90 - device - {entry.entity_id} - closed - open"
" - None"
),
f"is_pos_gt_45_lt_90 - device - {entry.entity_id} - closed - open - None",
f"is_pos_lt_90 - device - {entry.entity_id} - closed - open - None",
f"is_pos_gt_45 - device - {entry.entity_id} - open - closed - None",
]

View File

@ -2208,7 +2208,7 @@ async def test_fan_speed_ordered(
"ordered": True,
"speeds": [
{
"speed_name": f"{idx+1}/{len(speeds)}",
"speed_name": f"{idx + 1}/{len(speeds)}",
"speed_values": [{"lang": "en", "speed_synonym": x}],
}
for idx, x in enumerate(speeds)

View File

@ -1770,8 +1770,7 @@ async def test_if_fires_on_entities_change_overlap_for_template(
"entity_id": ["test.entity_1", "test.entity_2"],
"above": above,
"below": below,
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
" else 10 }}",
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
},
"action": {
"service": "test.automation",
@ -1938,8 +1937,7 @@ async def test_variables_priority(
"entity_id": ["test.entity_1", "test.entity_2"],
"above": above,
"below": below,
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
" else 10 }}",
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
},
"action": {
"service": "test.automation",

View File

@ -1423,8 +1423,7 @@ async def test_if_fires_on_entities_change_overlap_for_template(
"platform": "state",
"entity_id": ["test.entity_1", "test.entity_2"],
"to": "world",
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
" else 10 }}",
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
},
"action": {
"service": "test.automation",
@ -1727,8 +1726,7 @@ async def test_variables_priority(
"platform": "state",
"entity_id": ["test.entity_1", "test.entity_2"],
"to": "world",
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
" else 10 }}",
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
},
"action": {
"service": "test.automation",

View File

@ -41,7 +41,7 @@ async def test_statistics_import(
# Test that consumption statistics for 2 months have been added
for entity in entities:
statistic_id = f"ista_ecotrend:{entity.entity_id.removeprefix("sensor.")}"
statistic_id = f"ista_ecotrend:{entity.entity_id.removeprefix('sensor.')}"
stats = await hass.async_add_executor_job(
statistics_during_period,
hass,
@ -70,7 +70,7 @@ async def test_statistics_import(
await async_wait_recording_done(hass)
for entity in entities:
statistic_id = f"ista_ecotrend:{entity.entity_id.removeprefix("sensor.")}"
statistic_id = f"ista_ecotrend:{entity.entity_id.removeprefix('sensor.')}"
stats = await hass.async_add_executor_job(
statistics_during_period,
hass,

View File

@ -281,7 +281,7 @@ async def test_import_from_yaml_fails(
assert not hass.states.get("camera.config_test")
issue = issue_registry.async_get_issue(
DOMAIN, f"no_access_path_{slugify("mock.file")}"
DOMAIN, f"no_access_path_{slugify('mock.file')}"
)
assert issue
assert issue.translation_key == "no_access_path"

View File

@ -152,8 +152,7 @@ async def test_get_image_http(
client = await hass_client_no_auth()
with patch(
"homeassistant.components.media_player.MediaPlayerEntity."
"async_get_media_image",
"homeassistant.components.media_player.MediaPlayerEntity.async_get_media_image",
return_value=(b"image", "image/jpeg"),
):
resp = await client.get(state.attributes["entity_picture"])

View File

@ -422,9 +422,9 @@ async def test_virtual_binary_sensor(
assert hass.states.get(ENTITY_ID).state == expected
for i, slave in enumerate(slaves):
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_")
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i + 1}".replace(" ", "_")
assert hass.states.get(entity_id).state == slave
unique_id = f"{SLAVE_UNIQUE_ID}_{i+1}"
unique_id = f"{SLAVE_UNIQUE_ID}_{i + 1}"
entry = entity_registry.async_get(entity_id)
assert entry.unique_id == unique_id

View File

@ -18,7 +18,7 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry
TEST_CONFIG_ENTRY_ID = "74565ad414754616000674c87bdc876c"
TEST_URL = f"http://test:{DEFAULT_PORT+1}"
TEST_URL = f"http://test:{DEFAULT_PORT + 1}"
TEST_CAMERA_ID = 100
TEST_CAMERA_NAME = "Test Camera"
TEST_CAMERA_ENTITY_ID = "camera.test_camera"

View File

@ -356,7 +356,7 @@ async def test_invalid_device_discovery_config(
async_fire_mqtt_message(
hass,
"homeassistant/device/bla/config",
'{ "o": {"name": "foobar"}, "dev": {"identifiers": ["ABDE03"]}, ' '"cmps": ""}',
'{ "o": {"name": "foobar"}, "dev": {"identifiers": ["ABDE03"]}, "cmps": ""}',
)
await hass.async_block_till_done()
assert (

View File

@ -179,4 +179,4 @@ class MyStromSwitchMock(MyStromDeviceMock):
"""Return the URI."""
if not self._requested_state:
return None
return f"http://{self._state["ip"]}"
return f"http://{self._state['ip']}"

View File

@ -341,7 +341,7 @@ async def test_message_history_trimming(
for i in range(5):
result = await conversation.async_converse(
hass,
f"message {i+1}",
f"message {i + 1}",
conversation_id="1234",
context=Context(),
agent_id=mock_config_entry.entry_id,
@ -432,7 +432,7 @@ async def test_message_history_pruning(
for i in range(3):
result = await conversation.async_converse(
hass,
f"message {i+1}",
f"message {i + 1}",
conversation_id=None,
context=Context(),
agent_id=mock_config_entry.entry_id,
@ -490,7 +490,7 @@ async def test_message_history_unlimited(
for i in range(100):
result = await conversation.async_converse(
hass,
f"message {i+1}",
f"message {i + 1}",
conversation_id=conversation_id,
context=Context(),
agent_id=mock_config_entry.entry_id,

View File

@ -830,7 +830,9 @@ async def test_hassio_discovery_flow_new_port_missing_unique_id(
# Setup the config entry
config_entry = MockConfigEntry(
data={
"url": f"http://{HASSIO_DATA.config['host']}:{HASSIO_DATA.config['port']+1}"
"url": (
f"http://{HASSIO_DATA.config['host']}:{HASSIO_DATA.config['port'] + 1}"
)
},
domain=otbr.DOMAIN,
options={},
@ -861,7 +863,9 @@ async def test_hassio_discovery_flow_new_port(hass: HomeAssistant) -> None:
# Setup the config entry
config_entry = MockConfigEntry(
data={
"url": f"http://{HASSIO_DATA.config['host']}:{HASSIO_DATA.config['port']+1}"
"url": (
f"http://{HASSIO_DATA.config['host']}:{HASSIO_DATA.config['port'] + 1}"
)
},
domain=otbr.DOMAIN,
options={},
@ -897,7 +901,9 @@ async def test_hassio_discovery_flow_new_port_other_addon(hass: HomeAssistant) -
# Setup the config entry
config_entry = MockConfigEntry(
data={"url": f"http://openthread_border_router:{HASSIO_DATA.config['port']+1}"},
data={
"url": f"http://openthread_border_router:{HASSIO_DATA.config['port'] + 1}"
},
domain=otbr.DOMAIN,
options={},
source="hassio",
@ -914,7 +920,7 @@ async def test_hassio_discovery_flow_new_port_other_addon(hass: HomeAssistant) -
# Make sure the data of the existing entry was not updated
expected_data = {
"url": f"http://openthread_border_router:{HASSIO_DATA.config['port']+1}",
"url": f"http://openthread_border_router:{HASSIO_DATA.config['port'] + 1}",
}
config_entry = hass.config_entries.async_get_entry(config_entry.entry_id)
assert config_entry.data == expected_data

View File

@ -523,7 +523,7 @@ async def test_callback_view(
assert result["type"] is FlowResultType.EXTERNAL_STEP
client = await hass_client_no_auth()
forward_url = f'{config_flow.AUTH_CALLBACK_PATH}?flow_id={result["flow_id"]}'
forward_url = f"{config_flow.AUTH_CALLBACK_PATH}?flow_id={result['flow_id']}"
resp = await client.get(forward_url)
assert resp.status == HTTPStatus.OK

View File

@ -541,8 +541,7 @@ async def test_view_empty_namespace(
assert "# HELP python_info Python platform information" in body
assert (
"# HELP python_gc_objects_collected_total "
"Objects collected during gc" in body
"# HELP python_gc_objects_collected_total Objects collected during gc" in body
)
EntityMetric(
@ -569,8 +568,7 @@ async def test_view_default_namespace(
assert "# HELP python_info Python platform information" in body
assert (
"# HELP python_gc_objects_collected_total "
"Objects collected during gc" in body
"# HELP python_gc_objects_collected_total Objects collected during gc" in body
)
EntityMetric(

View File

@ -2655,9 +2655,9 @@ async def test_setup_fails_after_downgrade(
await hass.async_stop()
assert instance.engine is None
assert (
f"The database schema version {SCHEMA_VERSION+1} is newer than {SCHEMA_VERSION}"
" which is the maximum database schema version supported by the installed "
"version of Home Assistant Core"
f"The database schema version {SCHEMA_VERSION + 1} is newer "
f"than {SCHEMA_VERSION} which is the maximum database schema "
"version supported by the installed version of Home Assistant Core"
) in caplog.text

View File

@ -1514,7 +1514,7 @@ async def _test_split_light(
await common.async_turn_on(hass, entity)
mqtt_mock.async_publish.assert_called_once_with(
"tasmota_49A3BC/cmnd/Backlog",
f"NoDelay;Power{idx+num_switches+1} ON",
f"NoDelay;Power{idx + num_switches + 1} ON",
0,
False,
)
@ -1524,7 +1524,7 @@ async def _test_split_light(
await common.async_turn_on(hass, entity, brightness=(idx + 1) * 25.5)
mqtt_mock.async_publish.assert_called_once_with(
"tasmota_49A3BC/cmnd/Backlog",
f"NoDelay;Channel{idx+num_switches+1} {(idx+1)*10}",
f"NoDelay;Channel{idx + num_switches + 1} {(idx + 1) * 10}",
0,
False,
)
@ -1595,7 +1595,7 @@ async def _test_unlinked_light(
await common.async_turn_on(hass, entity)
mqtt_mock.async_publish.assert_called_once_with(
"tasmota_49A3BC/cmnd/Backlog",
f"NoDelay;Power{idx+num_switches+1} ON",
f"NoDelay;Power{idx + num_switches + 1} ON",
0,
False,
)
@ -1605,7 +1605,7 @@ async def _test_unlinked_light(
await common.async_turn_on(hass, entity, brightness=(idx + 1) * 25.5)
mqtt_mock.async_publish.assert_called_once_with(
"tasmota_49A3BC/cmnd/Backlog",
f"NoDelay;Dimmer{idx+1} {(idx+1)*10}",
f"NoDelay;Dimmer{idx + 1} {(idx + 1) * 10}",
0,
False,
)

View File

@ -112,4 +112,4 @@ async def test_errors(hass: HomeAssistant) -> None:
blocking=True,
)
mock_set.assert_called_once()
assert str(error.value) == f"Command failed, {TEST_RESPONSE_ERROR["reason"]}"
assert str(error.value) == f"Command failed, {TEST_RESPONSE_ERROR['reason']}"

View File

@ -501,7 +501,7 @@ async def test_unlink_devices(
# Generate list of test identifiers
test_identifiers = [
(domain, f"{device_id}{"" if i == 0 else f"_000{i}"}")
(domain, f"{device_id}{'' if i == 0 else f'_000{i}'}")
for i in range(id_count)
for domain in domains
]

View File

@ -262,7 +262,7 @@ async def test_device_button_entities(
WLAN_REGENERATE_PASSWORD,
"button.ssid_1_regenerate_password",
"put",
f"/rest/wlanconf/{WLAN_REGENERATE_PASSWORD[0]["_id"]}",
f"/rest/wlanconf/{WLAN_REGENERATE_PASSWORD[0]['_id']}",
{
"json": {"data": "password changed successfully", "meta": {"rc": "ok"}},
"headers": {"content-type": CONTENT_TYPE_JSON},

View File

@ -589,14 +589,14 @@ async def test_restoring_client(
entity_registry.async_get_or_create( # Make sure unique ID converts to site_id-mac
TRACKER_DOMAIN,
UNIFI_DOMAIN,
f'{clients_all_payload[0]["mac"]}-site_id',
f"{clients_all_payload[0]['mac']}-site_id",
suggested_object_id=clients_all_payload[0]["hostname"],
config_entry=config_entry,
)
entity_registry.async_get_or_create( # Unique ID already follow format site_id-mac
TRACKER_DOMAIN,
UNIFI_DOMAIN,
f'site_id-{client_payload[0]["mac"]}',
f"site_id-{client_payload[0]['mac']}",
suggested_object_id=client_payload[0]["hostname"],
config_entry=config_entry,
)

View File

@ -1577,14 +1577,14 @@ async def test_updating_unique_id(
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
UNIFI_DOMAIN,
f'{device_payload[0]["mac"]}-outlet-1',
f"{device_payload[0]['mac']}-outlet-1",
suggested_object_id="plug_outlet_1",
config_entry=config_entry,
)
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
UNIFI_DOMAIN,
f'{device_payload[1]["mac"]}-poe-1',
f"{device_payload[1]['mac']}-poe-1",
suggested_object_id="switch_port_1_poe",
config_entry=config_entry,
)