String formatting improvements for tests (#33663)
This commit is contained in:
1 parent
1c25468b21
commit
906385172a
33 files changed
+129
-155
No files matched your search
@@ -54,10 +54,10 @@ async def test_state_value(hass):
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, "cover_status")
|
||||
test_cover = {
|
||||
"command_state": "cat {}".format(path),
|
||||
"command_open": "echo 1 > {}".format(path),
|
||||
"command_close": "echo 1 > {}".format(path),
|
||||
"command_stop": "echo 0 > {}".format(path),
|
||||
"command_state": f"cat {path}",
|
||||
"command_open": f"echo 1 > {path}",
|
||||
"command_close": f"echo 1 > {path}",
|
||||
"command_stop": f"echo 0 > {path}",
|
||||
"value_template": "{{ value }}",
|
||||
}
|
||||
assert (
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestCommandLine(unittest.TestCase):
|
||||
"notify": {
|
||||
"name": "test",
|
||||
"platform": "command_line",
|
||||
"command": "echo $(cat) > {}".format(filename),
|
||||
"command": f"echo $(cat) > {filename}",
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -69,7 +69,7 @@ class TestCommandLine(unittest.TestCase):
|
||||
|
||||
with open(filename) as fil:
|
||||
# the echo command adds a line break
|
||||
assert fil.read() == "{}\n".format(message)
|
||||
assert fil.read() == f"{message}\n"
|
||||
|
||||
@patch("homeassistant.components.command_line.notify._LOGGER.error")
|
||||
def test_error_for_none_zero_exit_code(self, mock_error):
|
||||
|
||||
@@ -30,8 +30,8 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, "switch_status")
|
||||
test_switch = {
|
||||
"command_on": "echo 1 > {}".format(path),
|
||||
"command_off": "echo 0 > {}".format(path),
|
||||
"command_on": f"echo 1 > {path}",
|
||||
"command_off": f"echo 0 > {path}",
|
||||
}
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
@@ -64,9 +64,9 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, "switch_status")
|
||||
test_switch = {
|
||||
"command_state": "cat {}".format(path),
|
||||
"command_on": "echo 1 > {}".format(path),
|
||||
"command_off": "echo 0 > {}".format(path),
|
||||
"command_state": f"cat {path}",
|
||||
"command_on": f"echo 1 > {path}",
|
||||
"command_off": f"echo 0 > {path}",
|
||||
"value_template": '{{ value=="1" }}',
|
||||
}
|
||||
assert setup_component(
|
||||
@@ -102,9 +102,9 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
oncmd = json.dumps({"status": "ok"})
|
||||
offcmd = json.dumps({"status": "nope"})
|
||||
test_switch = {
|
||||
"command_state": "cat {}".format(path),
|
||||
"command_on": "echo '{}' > {}".format(oncmd, path),
|
||||
"command_off": "echo '{}' > {}".format(offcmd, path),
|
||||
"command_state": f"cat {path}",
|
||||
"command_on": f"echo '{oncmd}' > {path}",
|
||||
"command_off": f"echo '{offcmd}' > {path}",
|
||||
"value_template": '{{ value_json.status=="ok" }}',
|
||||
}
|
||||
assert setup_component(
|
||||
@@ -138,9 +138,9 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, "switch_status")
|
||||
test_switch = {
|
||||
"command_state": "cat {}".format(path),
|
||||
"command_on": "echo 1 > {}".format(path),
|
||||
"command_off": "echo 0 > {}".format(path),
|
||||
"command_state": f"cat {path}",
|
||||
"command_on": f"echo 1 > {path}",
|
||||
"command_off": f"echo 0 > {path}",
|
||||
}
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
|
||||
Reference in new issue
Block a user