Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting in component test files #135267

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/components/androidtv/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/axis/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/axis-media/media.amp?videocodec=h264"
f"{"" if not stream_profile else f"&{stream_profile}"}"
f"{'' if not stream_profile else f'&{stream_profile}'}"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/components/backup/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/broadlink/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions tests/components/cover/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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",
]
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_assistant/test_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions tests/components/homeassistant/triggers/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/ista_ecotrend/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/components/local_file/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 1 addition & 2 deletions tests/components/media_player/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions tests/components/modbus/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/components/motioneye/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/mqtt/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/components/mystrom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ def uri(self) -> str | None:
"""Return the URI."""
if not self._requested_state:
return None
return f"http://{self._state["ip"]}"
return f"http://{self._state['ip']}"
6 changes: 3 additions & 3 deletions tests/components/ollama/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def response(*args, **kwargs) -> dict:
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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions tests/components/otbr/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
Expand Down Expand Up @@ -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={},
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/plex/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/components/prometheus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/components/recorder/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions tests/components/tasmota/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/tessie/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"
2 changes: 1 addition & 1 deletion tests/components/tplink/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
2 changes: 1 addition & 1 deletion tests/components/unifi/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions tests/components/unifi/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/unifi/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down