Update string formatting to use f-string on tests (#125986)

* Update string formatting to use f-string on tests

* Update test_package.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Update statement given feedback

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Alberto Montes 2024-09-19 10:32:38 +02:00 committed by GitHub
parent 31f9687ba1
commit 5d2f8319b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 87 additions and 148 deletions

View File

@ -791,9 +791,7 @@ async def test_get_progress_flow(hass: HomeAssistant, client: TestClient) -> Non
assert resp.status == HTTPStatus.OK
data = await resp.json()
resp2 = await client.get(
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
resp2 = await client.get(f"/api/config/config_entries/flow/{data['flow_id']}")
assert resp2.status == HTTPStatus.OK
data2 = await resp2.json()
@ -829,9 +827,7 @@ async def test_get_progress_flow_unauth(
hass_admin_user.groups = []
resp2 = await client.get(
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
resp2 = await client.get(f"/api/config/config_entries/flow/{data['flow_id']}")
assert resp2.status == HTTPStatus.UNAUTHORIZED

View File

@ -79,7 +79,7 @@ async def test_logbook_entry(hass: HomeAssistant) -> None:
assert mock_statsd.event.call_count == 1
assert mock_statsd.event.call_args == mock.call(
title="Home Assistant",
text="%%% \n **{}** {} \n %%%".format(event["name"], event["message"]),
text=f"%%% \n **{event['name']}** {event['message']} \n %%%",
tags=["entity:sensor.foo.bar", "domain:automation"],
)

View File

@ -215,7 +215,7 @@ async def test_check_attributes(
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
assert state.attributes.get(ATTR_MEDIA_TITLE) == "Snow Bride"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("HALLHD", "312")
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "HALLHD (312)"
assert state.attributes.get(ATTR_INPUT_SOURCE) == "312"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "TV-G"
@ -234,7 +234,7 @@ async def test_check_attributes(
assert state.attributes.get(ATTR_MEDIA_POSITION_UPDATED_AT)
assert state.attributes.get(ATTR_MEDIA_TITLE) == "Tyler's Ultimate"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) == "Spaghetti and Clam Sauce"
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("FOODHD", "231")
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "FOODHD (231)"
assert state.attributes.get(ATTR_INPUT_SOURCE) == "231"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "No Rating"
@ -255,7 +255,7 @@ async def test_check_attributes(
assert state.attributes.get(ATTR_MEDIA_ARTIST) == "Gerald Albright"
assert state.attributes.get(ATTR_MEDIA_ALBUM_NAME) == "Slam Dunk (2014)"
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "{} ({})".format("MCSJ", "851")
assert state.attributes.get(ATTR_MEDIA_CHANNEL) == "MCSJ (851)"
assert state.attributes.get(ATTR_INPUT_SOURCE) == "851"
assert not state.attributes.get(ATTR_MEDIA_CURRENTLY_RECORDING)
assert state.attributes.get(ATTR_MEDIA_RATING) == "TV-PG"

View File

@ -20,7 +20,7 @@ async def test_setup_correct_reading(hass: HomeAssistant) -> None:
"""Test DTE Energy bridge returns a correct value."""
with requests_mock.Mocker() as mock_req:
mock_req.get(
"http://{}/instantaneousdemand".format(DTE_ENERGY_BRIDGE_CONFIG["ip"]),
f"http://{DTE_ENERGY_BRIDGE_CONFIG['ip']}/instantaneousdemand",
text=".411 kW",
)
assert await async_setup_component(
@ -34,7 +34,7 @@ async def test_setup_incorrect_units_reading(hass: HomeAssistant) -> None:
"""Test DTE Energy bridge handles a value with incorrect units."""
with requests_mock.Mocker() as mock_req:
mock_req.get(
"http://{}/instantaneousdemand".format(DTE_ENERGY_BRIDGE_CONFIG["ip"]),
f"http://{DTE_ENERGY_BRIDGE_CONFIG['ip']}/instantaneousdemand",
text="411 kW",
)
assert await async_setup_component(
@ -48,7 +48,7 @@ async def test_setup_bad_format_reading(hass: HomeAssistant) -> None:
"""Test DTE Energy bridge handles an invalid value."""
with requests_mock.Mocker() as mock_req:
mock_req.get(
"http://{}/instantaneousdemand".format(DTE_ENERGY_BRIDGE_CONFIG["ip"]),
f"http://{DTE_ENERGY_BRIDGE_CONFIG['ip']}/instantaneousdemand",
text="411",
)
assert await async_setup_component(

View File

@ -1248,9 +1248,7 @@ async def test_proper_put_state_request(hue_client: TestClient) -> None:
"""Test the request to set the state."""
# Test proper on value parsing
result = await hue_client.put(
"/api/username/lights/{}/state".format(
ENTITY_NUMBERS_BY_ID["light.ceiling_lights"]
),
f"/api/username/lights/{ENTITY_NUMBERS_BY_ID['light.ceiling_lights']}/state",
data=json.dumps({HUE_API_STATE_ON: 1234}),
)
@ -1258,9 +1256,7 @@ async def test_proper_put_state_request(hue_client: TestClient) -> None:
# Test proper brightness value parsing
result = await hue_client.put(
"/api/username/lights/{}/state".format(
ENTITY_NUMBERS_BY_ID["light.ceiling_lights"]
),
f"/api/username/lights/{ENTITY_NUMBERS_BY_ID['light.ceiling_lights']}/state",
data=json.dumps({HUE_API_STATE_ON: True, HUE_API_STATE_BRI: "Hello world!"}),
)

View File

@ -495,7 +495,7 @@ async def test_callback_view_with_jwt(
assert push_payload["body"] == "Hello"
assert push_payload["icon"] == "beer.png"
bearer_token = "Bearer {}".format(push_payload["data"]["jwt"])
bearer_token = f"Bearer {push_payload['data']['jwt']}"
resp = await client.post(
PUBLISH_URL, json={"type": "push"}, headers={AUTHORIZATION: bearer_token}

View File

@ -312,7 +312,7 @@ async def test_auth_access_signed_path_with_refresh_token(
assert data["user_id"] == refresh_token.user.id
# Use signature on other path
req = await client.get("/another_path?{}".format(signed_path.split("?")[1]))
req = await client.get(f"/another_path?{signed_path.split('?')[1]}")
assert req.status == HTTPStatus.UNAUTHORIZED
# We only allow GET

View File

@ -34,11 +34,11 @@ async def test_http_handle_intent(
assert intent_obj.context.user_id == hass_admin_user.id
response = intent_obj.create_response()
response.async_set_speech(
"I've ordered a {}!".format(intent_obj.slots["type"]["value"])
f"I've ordered a {intent_obj.slots['type']['value']}!"
)
response.async_set_card(
"Beer ordered",
"You chose a {}.".format(intent_obj.slots["type"]["value"]),
f"You chose a {intent_obj.slots['type']['value']}.",
)
return response

View File

@ -134,9 +134,7 @@ async def test_enter_and_exit(
req = await locative_client.post(url, data=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
assert state_name == "home"
data["id"] = "HOME"
@ -146,9 +144,7 @@ async def test_enter_and_exit(
req = await locative_client.post(url, data=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
assert state_name == "not_home"
data["id"] = "hOmE"
@ -158,9 +154,7 @@ async def test_enter_and_exit(
req = await locative_client.post(url, data=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
assert state_name == "home"
data["trigger"] = "exit"
@ -169,9 +163,7 @@ async def test_enter_and_exit(
req = await locative_client.post(url, data=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
assert state_name == "not_home"
data["id"] = "work"
@ -181,9 +173,7 @@ async def test_enter_and_exit(
req = await locative_client.post(url, data=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}").state
assert state_name == "work"
@ -206,7 +196,7 @@ async def test_exit_after_enter(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
assert state.state == "home"
data["id"] = "Work"
@ -216,7 +206,7 @@ async def test_exit_after_enter(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
assert state.state == "work"
data["id"] = "Home"
@ -227,7 +217,7 @@ async def test_exit_after_enter(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
assert state.state == "work"
@ -250,7 +240,7 @@ async def test_exit_first(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
assert state.state == "not_home"
@ -273,9 +263,7 @@ async def test_two_devices(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["device"])
)
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_1['device']}")
assert state.state == "not_home"
# Enter Home
@ -286,13 +274,9 @@ async def test_two_devices(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_2["device"])
)
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_2['device']}")
assert state.state == "home"
state = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["device"])
)
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_1['device']}")
assert state.state == "not_home"
@ -318,7 +302,7 @@ async def test_load_unload_entry(
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["device"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['device']}")
assert state.state == "not_home"
assert len(hass.data[DATA_DISPATCHER][TRACKER_UPDATE]) == 1

View File

@ -72,6 +72,6 @@ async def test_system_health_info_yaml_not_found(hass: HomeAssistant) -> None:
assert info == {
"dashboards": 1,
"mode": "yaml",
"error": "{} not found".format(hass.config.path("ui-lovelace.yaml")),
"error": f"{hass.config.path('ui-lovelace.yaml')} not found",
"resources": 0,
}

View File

@ -142,12 +142,8 @@ async def test_data_will_be_saved(
req = await meraki_client.post(URL, data=json.dumps(data))
assert req.status == HTTPStatus.OK
await hass.async_block_till_done()
state_name = hass.states.get(
"{}.{}".format("device_tracker", "00_26_ab_b8_a9_a4")
).state
state_name = hass.states.get("device_tracker.00_26_ab_b8_a9_a4").state
assert state_name == "home"
state_name = hass.states.get(
"{}.{}".format("device_tracker", "00_26_ab_b8_a9_a5")
).state
state_name = hass.states.get("device_tracker.00_26_ab_b8_a9_a5").state
assert state_name == "home"

View File

@ -15,7 +15,7 @@ async def test_sending_location(
) -> None:
"""Test sending a location via a webhook."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {
@ -48,7 +48,7 @@ async def test_sending_location(
assert state.attributes["vertical_accuracy"] == 80
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {
@ -87,7 +87,7 @@ async def test_restoring_location(
) -> None:
"""Test sending a location via a webhook."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {

View File

@ -101,7 +101,7 @@ async def test_webhook_handle_render_template(
) -> None:
"""Test that we render templates properly."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "render_template",
"data": {
@ -133,7 +133,7 @@ async def test_webhook_handle_call_services(
calls = async_mock_service(hass, "test", "mobile_app")
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json=CALL_SERVICE,
)
@ -158,7 +158,7 @@ async def test_webhook_handle_fire_event(
hass.bus.async_listen("test_event", store_event)
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]), json=FIRE_EVENT
f"/api/webhook/{create_registrations[1]['webhook_id']}", json=FIRE_EVENT
)
assert resp.status == HTTPStatus.OK
@ -224,7 +224,7 @@ async def test_webhook_handle_get_zones(
await hass.services.async_call(ZONE_DOMAIN, "reload", blocking=True)
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={"type": "get_zones"},
)
@ -317,7 +317,7 @@ async def test_webhook_returns_error_incorrect_json(
) -> None:
"""Test that an error is returned when JSON is invalid."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]), data="not json"
f"/api/webhook/{create_registrations[1]['webhook_id']}", data="not json"
)
assert resp.status == HTTPStatus.BAD_REQUEST
@ -350,7 +350,7 @@ async def test_webhook_handle_decryption(
container = {"type": msg["type"], "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -374,7 +374,7 @@ async def test_webhook_handle_decryption_legacy(
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -399,7 +399,7 @@ async def test_webhook_handle_decryption_fail(
data = encrypt_payload(key, RENDER_TEMPLATE["data"])
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -412,7 +412,7 @@ async def test_webhook_handle_decryption_fail(
data = encrypt_payload(key, "{not_valid", encode_json=False)
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -424,7 +424,7 @@ async def test_webhook_handle_decryption_fail(
data = encrypt_payload(key[::-1], RENDER_TEMPLATE["data"])
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -444,7 +444,7 @@ async def test_webhook_handle_decryption_legacy_fail(
data = encrypt_payload_legacy(key, RENDER_TEMPLATE["data"])
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -457,7 +457,7 @@ async def test_webhook_handle_decryption_legacy_fail(
data = encrypt_payload_legacy(key, "{not_valid", encode_json=False)
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -469,7 +469,7 @@ async def test_webhook_handle_decryption_legacy_fail(
data = encrypt_payload_legacy(key[::-1], RENDER_TEMPLATE["data"])
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -490,7 +490,7 @@ async def test_webhook_handle_decryption_legacy_upgrade(
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -508,7 +508,7 @@ async def test_webhook_handle_decryption_legacy_upgrade(
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -526,7 +526,7 @@ async def test_webhook_handle_decryption_legacy_upgrade(
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
f"/api/webhook/{create_registrations[0]['webhook_id']}", json=container
)
assert resp.status == HTTPStatus.OK
@ -539,7 +539,7 @@ async def test_webhook_requires_encryption(
) -> None:
"""Test that encrypted registrations only accept encrypted data."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]),
f"/api/webhook/{create_registrations[0]['webhook_id']}",
json=RENDER_TEMPLATE,
)
@ -560,7 +560,7 @@ async def test_webhook_update_location_without_locations(
# start off with a location set by name
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"location_name": STATE_HOME},
@ -575,7 +575,7 @@ async def test_webhook_update_location_without_locations(
# set location to an 'unknown' state
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"altitude": 123},
@ -597,7 +597,7 @@ async def test_webhook_update_location_with_gps(
) -> None:
"""Test that location can be updated."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"gps": [1, 2], "gps_accuracy": 10, "altitude": -10},
@ -621,7 +621,7 @@ async def test_webhook_update_location_with_gps_without_accuracy(
) -> None:
"""Test that location can be updated."""
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"gps": [1, 2]},
@ -659,7 +659,7 @@ async def test_webhook_update_location_with_location_name(
await hass.services.async_call(ZONE_DOMAIN, "reload", blocking=True)
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"location_name": "zone_name"},
@ -672,7 +672,7 @@ async def test_webhook_update_location_with_location_name(
assert state.state == "zone_name"
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"location_name": STATE_HOME},
@ -685,7 +685,7 @@ async def test_webhook_update_location_with_location_name(
assert state.state == STATE_HOME
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "update_location",
"data": {"location_name": STATE_NOT_HOME},
@ -876,7 +876,7 @@ async def test_webhook_handle_scan_tag(
events = async_capture_events(hass, EVENT_TAG_SCANNED)
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={"type": "scan_tag", "data": {"tag_id": "mock-tag-id"}},
)
@ -1052,7 +1052,7 @@ async def test_webhook_handle_conversation_process(
return_value=mock_conversation_agent,
):
resp = await webhook_client.post(
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
f"/api/webhook/{create_registrations[1]['webhook_id']}",
json={
"type": "conversation_process",
"data": {

View File

@ -1540,7 +1540,7 @@ async def test_encrypted_payload_wrong_topic_key(
async def test_encrypted_payload_no_topic_key(hass: HomeAssistant, setup_comp) -> None:
"""Test encrypted payload with no topic key."""
await setup_owntracks(
hass, {CONF_SECRET: {"owntracks/{}/{}".format(USER, "otherdevice"): "foobar"}}
hass, {CONF_SECRET: {f"owntracks/{USER}/otherdevice": "foobar"}}
)
await send_message(hass, LOCATION_TOPIC, MOCK_ENCRYPTED_LOCATION_MESSAGE)
assert hass.states.get(DEVICE_TRACKER_STATE) is None

View File

@ -269,9 +269,7 @@ async def test_send_command(hass: HomeAssistant) -> None:
"""Test send_command service."""
await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4", ".media_player.PS4Device.async_send_command"
)
mock_func = "homeassistant.components.ps4.media_player.PS4Device.async_send_command"
mock_devices = hass.data[PS4_DATA].devices
assert len(mock_devices) == 1

View File

@ -194,10 +194,7 @@ async def test_state_standby_is_set(hass: HomeAssistant) -> None:
async def test_state_playing_is_set(hass: HomeAssistant) -> None:
"""Test that state is set to playing."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.",
"pyps4.Ps4Async.async_get_ps_store_data",
)
mock_func = "homeassistant.components.ps4.media_player.pyps4.Ps4Async.async_get_ps_store_data"
with patch(mock_func, return_value=None):
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
@ -224,10 +221,7 @@ async def test_state_none_is_set(hass: HomeAssistant) -> None:
async def test_media_attributes_are_fetched(hass: HomeAssistant) -> None:
"""Test that media attributes are fetched."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.",
"pyps4.Ps4Async.async_get_ps_store_data",
)
mock_func = "homeassistant.components.ps4.media_player.pyps4.Ps4Async.async_get_ps_store_data"
# Mock result from fetching data.
mock_result = MagicMock()
@ -276,8 +270,7 @@ async def test_media_attributes_are_loaded(
patch_load_json_object.return_value = {MOCK_TITLE_ID: MOCK_GAMES_DATA_LOCKED}
with patch(
"homeassistant.components.ps4.media_player."
"pyps4.Ps4Async.async_get_ps_store_data",
"homeassistant.components.ps4.media_player.pyps4.Ps4Async.async_get_ps_store_data",
return_value=None,
) as mock_fetch:
await mock_ddp_response(hass, MOCK_STATUS_PLAYING)
@ -381,9 +374,7 @@ async def test_device_info_assummed_works(
async def test_turn_on(hass: HomeAssistant) -> None:
"""Test that turn on service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.wakeup"
)
mock_func = "homeassistant.components.ps4.media_player.pyps4.Ps4Async.wakeup"
with patch(mock_func) as mock_call:
await hass.services.async_call(
@ -397,9 +388,7 @@ async def test_turn_on(hass: HomeAssistant) -> None:
async def test_turn_off(hass: HomeAssistant) -> None:
"""Test that turn off service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.standby"
)
mock_func = "homeassistant.components.ps4.media_player.pyps4.Ps4Async.standby"
with patch(mock_func) as mock_call:
await hass.services.async_call(
@ -413,9 +402,7 @@ async def test_turn_off(hass: HomeAssistant) -> None:
async def test_toggle(hass: HomeAssistant) -> None:
"""Test that toggle service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.toggle"
)
mock_func = "homeassistant.components.ps4.media_player.pyps4.Ps4Async.toggle"
with patch(mock_func) as mock_call:
await hass.services.async_call(
@ -429,8 +416,8 @@ async def test_toggle(hass: HomeAssistant) -> None:
async def test_media_pause(hass: HomeAssistant) -> None:
"""Test that media pause service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
mock_func = (
"homeassistant.components.ps4.media_player.pyps4.Ps4Async.remote_control"
)
with patch(mock_func) as mock_call:
@ -445,8 +432,8 @@ async def test_media_pause(hass: HomeAssistant) -> None:
async def test_media_stop(hass: HomeAssistant) -> None:
"""Test that media stop service calls function."""
mock_entity_id = await setup_mock_component(hass)
mock_func = "{}{}".format(
"homeassistant.components.ps4.media_player.", "pyps4.Ps4Async.remote_control"
mock_func = (
"homeassistant.components.ps4.media_player.pyps4.Ps4Async.remote_control"
)
with patch(mock_func) as mock_call:

View File

@ -121,18 +121,14 @@ async def test_enter_and_exit(
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}").state
assert state_name == STATE_HOME
# Enter Home again
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}").state
assert state_name == STATE_HOME
data["lon"] = 0
@ -142,9 +138,7 @@ async def test_enter_and_exit(
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}").state
assert state_name == STATE_NOT_HOME
assert len(device_registry.devices) == 1
@ -171,7 +165,7 @@ async def test_enter_with_attrs(hass: HomeAssistant, client, webhook_id) -> None
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}")
assert state.state == STATE_NOT_HOME
assert state.attributes["gps_accuracy"] == 10.5
assert state.attributes["battery_level"] == 10.0
@ -194,7 +188,7 @@ async def test_enter_with_attrs(hass: HomeAssistant, client, webhook_id) -> None
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}")
assert state.state == STATE_HOME
assert state.attributes["gps_accuracy"] == 123
assert state.attributes["battery_level"] == 23
@ -214,7 +208,7 @@ async def test_two_devices(hass: HomeAssistant, client, webhook_id) -> None:
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["id"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_1['id']}")
assert state.state == "not_home"
# Enter Home
@ -226,9 +220,9 @@ async def test_two_devices(hass: HomeAssistant, client, webhook_id) -> None:
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_2["id"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_2['id']}")
assert state.state == "home"
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["id"]))
state = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data_device_1['id']}")
assert state.state == "not_home"
@ -244,9 +238,7 @@ async def test_load_unload_entry(hass: HomeAssistant, client, webhook_id) -> Non
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTPStatus.OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
state_name = hass.states.get(f"{DEVICE_TRACKER_DOMAIN}.{data['id']}").state
assert state_name == STATE_HOME
assert len(hass.data[DATA_DISPATCHER][TRACKER_UPDATE]) == 1

View File

@ -62,9 +62,7 @@ async def test_form(hass: HomeAssistant) -> None:
"weekday": ["mon", "fri"],
}
assert len(mock_setup_entry.mock_calls) == 1
assert result2["result"].unique_id == "{}-{}-{}-{}".format(
"eker\u00f6", "slagsta", "10:00", "['mon', 'fri']"
)
assert result2["result"].unique_id == "eker\u00f6-slagsta-10:00-['mon', 'fri']"
@pytest.mark.parametrize(

View File

@ -73,9 +73,7 @@ async def test_form(hass: HomeAssistant) -> None:
}
assert result["options"] == {"filter_product": None}
assert len(mock_setup_entry.mock_calls) == 1
assert result["result"].unique_id == "{}-{}-{}-{}".format(
"stockholmc", "uppsalac", "10:00", "['mon', 'fri']"
)
assert result["result"].unique_id == "stockholmc-uppsalac-10:00-['mon', 'fri']"
async def test_form_entry_already_exist(hass: HomeAssistant) -> None:

View File

@ -73,7 +73,7 @@ async def test_signal_type_format(hass: HomeAssistant) -> None:
assert calls == [("Hello", 2)]
# Test compatibility with string keys
async_dispatcher_send(hass, "test-{}".format("unique-id"), "x", 4)
async_dispatcher_send(hass, "test-unique-id", "x", 4)
await hass.async_block_till_done()
assert calls == [("Hello", 2), ("x", 4)]

View File

@ -25,12 +25,8 @@ def test_battery_icon() -> None:
iconbase = "mdi:battery"
for level in range(0, 100, 5):
print( # noqa: T201
"Level: %d. icon: %s, charging: %s"
% (
level,
icon.icon_for_battery_level(level, False),
icon.icon_for_battery_level(level, True),
)
f"Level: {level}. icon: {icon.icon_for_battery_level(level, False)}, "
f"charging: {icon.icon_for_battery_level(level, True)}"
)
if level <= 10:
postfix_charging = "-outline"

View File

@ -19,9 +19,7 @@ RESOURCE_DIR = os.path.abspath(
TEST_NEW_REQ = "pyhelloworld3==1.0.0"
TEST_ZIP_REQ = "file://{}#{}".format(
os.path.join(RESOURCE_DIR, "pyhelloworld3.zip"), TEST_NEW_REQ
)
TEST_ZIP_REQ = f"file://{RESOURCE_DIR}/pyhelloworld3.zip#{TEST_NEW_REQ}"
@pytest.fixture