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

+18 -37
View File
@@ -347,7 +347,7 @@ mock_mqtt_component = threadsafe_coroutine_factory(async_mock_mqtt_component)
def mock_component(hass, component):
"""Mock a component is setup."""
if component in hass.config.components:
AssertionError("Integration {} is already setup".format(component))
AssertionError(f"Integration {component} is already setup")
hass.config.components.add(component)
@@ -486,8 +486,8 @@ class MockModule:
partial_manifest=None,
):
"""Initialize the mock module."""
self.__name__ = "homeassistant.components.{}".format(domain)
self.__file__ = "homeassistant/components/{}".format(domain)
self.__name__ = f"homeassistant.components.{domain}"
self.__file__ = f"homeassistant/components/{domain}"
self.DOMAIN = domain
self.DEPENDENCIES = dependencies or []
self.REQUIREMENTS = requirements or []
@@ -728,7 +728,7 @@ def patch_yaml_files(files_dict, endswith=True):
return open(fname, encoding="utf-8")
# Not found
raise FileNotFoundError("File not found: {}".format(fname))
raise FileNotFoundError(f"File not found: {fname}")
return patch.object(yaml_loader, "open", mock_open_f, create=True)
@@ -791,9 +791,9 @@ def assert_setup_component(count, domain=None):
res = config.get(domain)
res_len = 0 if res is None else len(res)
assert res_len == count, "setup_component failed, expected {} got {}: {}".format(
count, res_len, res
)
assert (
res_len == count
), f"setup_component failed, expected {count} got {res_len}: {res}"
def init_recorder_component(hass, add_config=None):
@@ -824,9 +824,7 @@ def mock_restore_cache(hass, states):
)
data.last_states = last_states
_LOGGER.debug("Restore cache: %s", data.last_states)
assert len(data.last_states) == len(states), "Duplicate entity_id? {}".format(
states
)
assert len(data.last_states) == len(states), f"Duplicate entity_id? {states}"
async def get_restore_state_data() -> restore_state.RestoreStateData:
return data
@@ -855,7 +853,7 @@ class MockDependency:
base = MagicMock()
to_mock = {
"{}.{}".format(self.root, tom): resolve(base, tom.split("."))
f"{self.root}.{tom}": resolve(base, tom.split("."))
for tom in self.submodules
}
to_mock[self.root] = base
@@ -1017,10 +1015,7 @@ async def get_system_health_info(hass, domain):
def mock_integration(hass, module):
"""Mock an integration."""
integration = loader.Integration(
hass,
"homeassistant.components.{}".format(module.DOMAIN),
None,
module.mock_manifest(),
hass, f"homeassistant.components.{module.DOMAIN}", None, module.mock_manifest(),
)
_LOGGER.info("Adding mock integration: %s", module.DOMAIN)
@@ -1108,45 +1103,31 @@ class hashdict(dict):
return tuple(sorted(self.items()))
def __repr__(self): # noqa: D105 no docstring
return ", ".join("{0}={1}".format(str(i[0]), repr(i[1])) for i in self.__key())
return ", ".join(f"{i[0]!s}={i[1]!r}" for i in self.__key())
def __hash__(self): # noqa: D105 no docstring
return hash(self.__key())
def __setitem__(self, key, value): # noqa: D105 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def __delitem__(self, key): # noqa: D105 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def clear(self): # noqa: D102 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def pop(self, *args, **kwargs): # noqa: D102 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def popitem(self, *args, **kwargs): # noqa: D102 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def setdefault(self, *args, **kwargs): # noqa: D102 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
def update(self, *args, **kwargs): # noqa: D102 no docstring
raise TypeError(
"{0} does not support item assignment".format(self.__class__.__name__)
)
raise TypeError(f"{self.__class__.__name__} does not support item assignment")
# update is not ok because it mutates the object
# __add__ is ok because it creates a new object