Various string cleanups (#30435)

* Remove some unnecessary string concatenations

* Replace some simple str.formats with f-strings

* Replace some string concatenations with f-strings
This commit is contained in:
Ville Skyttä authored and Paulus Schoutsen committed 2020-01-03 14:47:06 +01:00
1 parent 5ad209c6fd
commit fa4fa30461
105 files changed
+241 -314

No files matched your search

+2 -2
View File
@@ -84,7 +84,7 @@ async def test_discovery_single_instance(hass, discovery_flow_conf, source):
flow.context = {}
MockConfigEntry(domain="test").add_to_hass(hass)
result = await getattr(flow, "async_step_{}".format(source))({})
result = await getattr(flow, f"async_step_{source}")({})
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "single_instance_allowed"
@@ -97,7 +97,7 @@ async def test_discovery_confirmation(hass, discovery_flow_conf, source):
flow.hass = hass
flow.context = {}
result = await getattr(flow, "async_step_{}".format(source))({})
result = await getattr(flow, f"async_step_{source}")({})
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "confirm"
+2 -2
View File
@@ -103,8 +103,8 @@ async def test_setup_recovers_when_setup_raises(hass):
OrderedDict(
[
(DOMAIN, {"platform": "mod1"}),
("{} 2".format(DOMAIN), {"platform": "non_exist"}),
("{} 3".format(DOMAIN), {"platform": "mod2"}),
(f"{DOMAIN} 2", {"platform": "non_exist"}),
(f"{DOMAIN} 3", {"platform": "mod2"}),
]
)
)
+2 -2
View File
@@ -541,7 +541,7 @@ async def test_setup_entry(hass):
assert await entity_platform.async_setup_entry(config_entry)
await hass.async_block_till_done()
full_name = "{}.{}".format(entity_platform.domain, config_entry.domain)
full_name = f"{entity_platform.domain}.{config_entry.domain}"
assert full_name in hass.config.components
assert len(hass.states.async_entity_ids()) == 1
assert len(registry.entities) == 1
@@ -560,7 +560,7 @@ async def test_setup_entry_platform_not_ready(hass, caplog):
with patch.object(entity_platform, "async_call_later") as mock_call_later:
assert not await ent_platform.async_setup_entry(config_entry)
full_name = "{}.{}".format(ent_platform.domain, config_entry.domain)
full_name = f"{ent_platform.domain}.{config_entry.domain}"
assert full_name not in hass.config.components
assert len(async_setup_entry.mock_calls) == 1
assert "Platform test not ready yet" in caplog.text
+1 -1
View File
@@ -62,7 +62,7 @@ async def test_loading_parallel(hass, store, hass_storage, caplog):
assert results[0] is MOCK_DATA
assert results[1] is MOCK_DATA
assert caplog.text.count("Loading data for {}".format(store.key))
assert caplog.text.count(f"Loading data for {store.key}")
async def test_saving_with_delay(hass, store, hass_storage):
+1 -1
View File
@@ -19,7 +19,7 @@ def test_temperature_not_a_number(hass):
with pytest.raises(Exception) as exception:
display_temp(hass, temp, TEMP_CELSIUS, PRECISION_HALVES)
assert "Temperature is not a number: {}".format(temp) in str(exception.value)
assert f"Temperature is not a number: {temp}" in str(exception.value)
def test_celsius_halves(hass):
+3 -3
View File
@@ -65,7 +65,7 @@ def assert_result_info(info, result, entities=None, domains=None, all_states=Fal
def test_template_equality():
"""Test template comparison and hashing."""
template_one = template.Template("{{ template_one }}")
template_one_1 = template.Template("{{ template_" + "one }}")
template_one_1 = template.Template("{{ template_one }}")
template_two = template.Template("{{ template_two }}")
assert template_one == template_one_1
@@ -486,9 +486,9 @@ def test_timestamp_custom(hass):
for inp, fmt, local, out in tests:
if fmt:
fil = "timestamp_custom('{}')".format(fmt)
fil = f"timestamp_custom('{fmt}')"
elif fmt and local:
fil = "timestamp_custom('{0}', {1})".format(fmt, local)
fil = f"timestamp_custom('{fmt}', {local})"
else:
fil = "timestamp_custom"