mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve formatting in component test files (#135267)
Improve formatting in test files
This commit is contained in:
parent
9d1989125f
commit
02956f9a83
@ -99,9 +99,9 @@ async def test_services_remote(hass: HomeAssistant, config) -> None:
|
|||||||
"adb_shell",
|
"adb_shell",
|
||||||
{ATTR_COMMAND: ["BACK", "test"], ATTR_NUM_REPEATS: 2},
|
{ATTR_COMMAND: ["BACK", "test"], ATTR_NUM_REPEATS: 2},
|
||||||
[
|
[
|
||||||
f"input keyevent {KEYS["BACK"]}",
|
f"input keyevent {KEYS['BACK']}",
|
||||||
"test",
|
"test",
|
||||||
f"input keyevent {KEYS["BACK"]}",
|
f"input keyevent {KEYS['BACK']}",
|
||||||
"test",
|
"test",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -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.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
|
||||||
assert (
|
assert (
|
||||||
camera_entity.mjpeg_source == "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi"
|
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 (
|
assert (
|
||||||
await camera_entity.stream_source()
|
await camera_entity.stream_source()
|
||||||
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264"
|
== "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}'}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ async def test_async_initiate_backup(
|
|||||||
|
|
||||||
tar_file_path = str(mocked_tarfile.call_args_list[0][0][0])
|
tar_file_path = str(mocked_tarfile.call_args_list[0][0][0])
|
||||||
backup_directory = hass.config.path(backup_directory)
|
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")
|
@pytest.mark.usefixtures("mock_backup_generation")
|
||||||
|
@ -766,10 +766,7 @@ async def test_if_fires_on_position(
|
|||||||
]
|
]
|
||||||
) == sorted(
|
) == 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_lt_90 - device - {entry.entity_id} - closed - open - None",
|
||||||
f"is_pos_gt_45 - device - {entry.entity_id} - open - closed - 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(
|
) == 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_lt_90 - device - {entry.entity_id} - closed - open - None",
|
||||||
f"is_pos_gt_45 - device - {entry.entity_id} - open - closed - None",
|
f"is_pos_gt_45 - device - {entry.entity_id} - open - closed - None",
|
||||||
]
|
]
|
||||||
|
@ -1770,8 +1770,7 @@ async def test_if_fires_on_entities_change_overlap_for_template(
|
|||||||
"entity_id": ["test.entity_1", "test.entity_2"],
|
"entity_id": ["test.entity_1", "test.entity_2"],
|
||||||
"above": above,
|
"above": above,
|
||||||
"below": below,
|
"below": below,
|
||||||
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
|
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
|
||||||
" else 10 }}",
|
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"service": "test.automation",
|
"service": "test.automation",
|
||||||
@ -1938,8 +1937,7 @@ async def test_variables_priority(
|
|||||||
"entity_id": ["test.entity_1", "test.entity_2"],
|
"entity_id": ["test.entity_1", "test.entity_2"],
|
||||||
"above": above,
|
"above": above,
|
||||||
"below": below,
|
"below": below,
|
||||||
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
|
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
|
||||||
" else 10 }}",
|
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"service": "test.automation",
|
"service": "test.automation",
|
||||||
|
@ -1423,8 +1423,7 @@ async def test_if_fires_on_entities_change_overlap_for_template(
|
|||||||
"platform": "state",
|
"platform": "state",
|
||||||
"entity_id": ["test.entity_1", "test.entity_2"],
|
"entity_id": ["test.entity_1", "test.entity_2"],
|
||||||
"to": "world",
|
"to": "world",
|
||||||
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
|
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
|
||||||
" else 10 }}",
|
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"service": "test.automation",
|
"service": "test.automation",
|
||||||
@ -1727,8 +1726,7 @@ async def test_variables_priority(
|
|||||||
"platform": "state",
|
"platform": "state",
|
||||||
"entity_id": ["test.entity_1", "test.entity_2"],
|
"entity_id": ["test.entity_1", "test.entity_2"],
|
||||||
"to": "world",
|
"to": "world",
|
||||||
"for": '{{ 5 if trigger.entity_id == "test.entity_1"'
|
"for": '{{ 5 if trigger.entity_id == "test.entity_1" else 10 }}',
|
||||||
" else 10 }}",
|
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"service": "test.automation",
|
"service": "test.automation",
|
||||||
|
@ -41,7 +41,7 @@ async def test_statistics_import(
|
|||||||
|
|
||||||
# Test that consumption statistics for 2 months have been added
|
# Test that consumption statistics for 2 months have been added
|
||||||
for entity in entities:
|
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(
|
stats = await hass.async_add_executor_job(
|
||||||
statistics_during_period,
|
statistics_during_period,
|
||||||
hass,
|
hass,
|
||||||
@ -70,7 +70,7 @@ async def test_statistics_import(
|
|||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
for entity in entities:
|
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(
|
stats = await hass.async_add_executor_job(
|
||||||
statistics_during_period,
|
statistics_during_period,
|
||||||
hass,
|
hass,
|
||||||
|
@ -281,7 +281,7 @@ async def test_import_from_yaml_fails(
|
|||||||
assert not hass.states.get("camera.config_test")
|
assert not hass.states.get("camera.config_test")
|
||||||
|
|
||||||
issue = issue_registry.async_get_issue(
|
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
|
||||||
assert issue.translation_key == "no_access_path"
|
assert issue.translation_key == "no_access_path"
|
||||||
|
@ -152,8 +152,7 @@ async def test_get_image_http(
|
|||||||
client = await hass_client_no_auth()
|
client = await hass_client_no_auth()
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.media_player.MediaPlayerEntity."
|
"homeassistant.components.media_player.MediaPlayerEntity.async_get_media_image",
|
||||||
"async_get_media_image",
|
|
||||||
return_value=(b"image", "image/jpeg"),
|
return_value=(b"image", "image/jpeg"),
|
||||||
):
|
):
|
||||||
resp = await client.get(state.attributes["entity_picture"])
|
resp = await client.get(state.attributes["entity_picture"])
|
||||||
|
@ -356,7 +356,7 @@ async def test_invalid_device_discovery_config(
|
|||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass,
|
hass,
|
||||||
"homeassistant/device/bla/config",
|
"homeassistant/device/bla/config",
|
||||||
'{ "o": {"name": "foobar"}, "dev": {"identifiers": ["ABDE03"]}, ' '"cmps": ""}',
|
'{ "o": {"name": "foobar"}, "dev": {"identifiers": ["ABDE03"]}, "cmps": ""}',
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert (
|
assert (
|
||||||
|
@ -179,4 +179,4 @@ class MyStromSwitchMock(MyStromDeviceMock):
|
|||||||
"""Return the URI."""
|
"""Return the URI."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return f"http://{self._state["ip"]}"
|
return f"http://{self._state['ip']}"
|
||||||
|
@ -830,7 +830,9 @@ async def test_hassio_discovery_flow_new_port_missing_unique_id(
|
|||||||
# Setup the config entry
|
# Setup the config entry
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
data={
|
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,
|
domain=otbr.DOMAIN,
|
||||||
options={},
|
options={},
|
||||||
@ -861,7 +863,9 @@ async def test_hassio_discovery_flow_new_port(hass: HomeAssistant) -> None:
|
|||||||
# Setup the config entry
|
# Setup the config entry
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
data={
|
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,
|
domain=otbr.DOMAIN,
|
||||||
options={},
|
options={},
|
||||||
@ -897,7 +901,9 @@ async def test_hassio_discovery_flow_new_port_other_addon(hass: HomeAssistant) -
|
|||||||
|
|
||||||
# Setup the config entry
|
# Setup the config entry
|
||||||
config_entry = MockConfigEntry(
|
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,
|
domain=otbr.DOMAIN,
|
||||||
options={},
|
options={},
|
||||||
source="hassio",
|
source="hassio",
|
||||||
|
@ -523,7 +523,7 @@ async def test_callback_view(
|
|||||||
assert result["type"] is FlowResultType.EXTERNAL_STEP
|
assert result["type"] is FlowResultType.EXTERNAL_STEP
|
||||||
|
|
||||||
client = await hass_client_no_auth()
|
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)
|
resp = await client.get(forward_url)
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
|
@ -541,8 +541,7 @@ async def test_view_empty_namespace(
|
|||||||
|
|
||||||
assert "# HELP python_info Python platform information" in body
|
assert "# HELP python_info Python platform information" in body
|
||||||
assert (
|
assert (
|
||||||
"# HELP python_gc_objects_collected_total "
|
"# HELP python_gc_objects_collected_total Objects collected during gc" in body
|
||||||
"Objects collected during gc" in body
|
|
||||||
)
|
)
|
||||||
|
|
||||||
EntityMetric(
|
EntityMetric(
|
||||||
@ -569,8 +568,7 @@ async def test_view_default_namespace(
|
|||||||
|
|
||||||
assert "# HELP python_info Python platform information" in body
|
assert "# HELP python_info Python platform information" in body
|
||||||
assert (
|
assert (
|
||||||
"# HELP python_gc_objects_collected_total "
|
"# HELP python_gc_objects_collected_total Objects collected during gc" in body
|
||||||
"Objects collected during gc" in body
|
|
||||||
)
|
)
|
||||||
|
|
||||||
EntityMetric(
|
EntityMetric(
|
||||||
|
@ -2655,9 +2655,9 @@ async def test_setup_fails_after_downgrade(
|
|||||||
await hass.async_stop()
|
await hass.async_stop()
|
||||||
assert instance.engine is None
|
assert instance.engine is None
|
||||||
assert (
|
assert (
|
||||||
f"The database schema version {SCHEMA_VERSION+1} is newer than {SCHEMA_VERSION}"
|
f"The database schema version {SCHEMA_VERSION + 1} is newer "
|
||||||
" which is the maximum database schema version supported by the installed "
|
f"than {SCHEMA_VERSION} which is the maximum database schema "
|
||||||
"version of Home Assistant Core"
|
"version supported by the installed version of Home Assistant Core"
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,4 +112,4 @@ async def test_errors(hass: HomeAssistant) -> None:
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
mock_set.assert_called_once()
|
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']}"
|
||||||
|
@ -501,7 +501,7 @@ async def test_unlink_devices(
|
|||||||
|
|
||||||
# Generate list of test identifiers
|
# Generate list of test identifiers
|
||||||
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 i in range(id_count)
|
||||||
for domain in domains
|
for domain in domains
|
||||||
]
|
]
|
||||||
|
@ -262,7 +262,7 @@ async def test_device_button_entities(
|
|||||||
WLAN_REGENERATE_PASSWORD,
|
WLAN_REGENERATE_PASSWORD,
|
||||||
"button.ssid_1_regenerate_password",
|
"button.ssid_1_regenerate_password",
|
||||||
"put",
|
"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"}},
|
"json": {"data": "password changed successfully", "meta": {"rc": "ok"}},
|
||||||
"headers": {"content-type": CONTENT_TYPE_JSON},
|
"headers": {"content-type": CONTENT_TYPE_JSON},
|
||||||
|
@ -589,14 +589,14 @@ async def test_restoring_client(
|
|||||||
entity_registry.async_get_or_create( # Make sure unique ID converts to site_id-mac
|
entity_registry.async_get_or_create( # Make sure unique ID converts to site_id-mac
|
||||||
TRACKER_DOMAIN,
|
TRACKER_DOMAIN,
|
||||||
UNIFI_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"],
|
suggested_object_id=clients_all_payload[0]["hostname"],
|
||||||
config_entry=config_entry,
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
entity_registry.async_get_or_create( # Unique ID already follow format site_id-mac
|
entity_registry.async_get_or_create( # Unique ID already follow format site_id-mac
|
||||||
TRACKER_DOMAIN,
|
TRACKER_DOMAIN,
|
||||||
UNIFI_DOMAIN,
|
UNIFI_DOMAIN,
|
||||||
f'site_id-{client_payload[0]["mac"]}',
|
f"site_id-{client_payload[0]['mac']}",
|
||||||
suggested_object_id=client_payload[0]["hostname"],
|
suggested_object_id=client_payload[0]["hostname"],
|
||||||
config_entry=config_entry,
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
|
@ -1577,14 +1577,14 @@ async def test_updating_unique_id(
|
|||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
UNIFI_DOMAIN,
|
UNIFI_DOMAIN,
|
||||||
f'{device_payload[0]["mac"]}-outlet-1',
|
f"{device_payload[0]['mac']}-outlet-1",
|
||||||
suggested_object_id="plug_outlet_1",
|
suggested_object_id="plug_outlet_1",
|
||||||
config_entry=config_entry,
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
UNIFI_DOMAIN,
|
UNIFI_DOMAIN,
|
||||||
f'{device_payload[1]["mac"]}-poe-1',
|
f"{device_payload[1]['mac']}-poe-1",
|
||||||
suggested_object_id="switch_port_1_poe",
|
suggested_object_id="switch_port_1_poe",
|
||||||
config_entry=config_entry,
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user