Include script script_execution in script and automation traces (#48576)
This commit is contained in:
parent
9d085778c2
commit
9f481e1642
6 changed files with 228 additions and 20 deletions
|
@ -86,9 +86,10 @@ def assert_element(trace_element, expected_element, path):
|
|||
assert not trace_element._variables
|
||||
|
||||
|
||||
def assert_action_trace(expected):
|
||||
def assert_action_trace(expected, expected_script_execution="finished"):
|
||||
"""Assert a trace condition sequence is as expected."""
|
||||
action_trace = trace.trace_get(clear=False)
|
||||
script_execution = trace.script_execution_get()
|
||||
trace.trace_clear()
|
||||
expected_trace_keys = list(expected.keys())
|
||||
assert list(action_trace.keys()) == expected_trace_keys
|
||||
|
@ -98,6 +99,8 @@ def assert_action_trace(expected):
|
|||
path = f"[{trace_key_index}][{index}]"
|
||||
assert_element(action_trace[key][index], element, path)
|
||||
|
||||
assert script_execution == expected_script_execution
|
||||
|
||||
|
||||
def async_watch_for_action(script_obj, message):
|
||||
"""Watch for message in last_action."""
|
||||
|
@ -620,7 +623,8 @@ async def test_delay_template_invalid(hass, caplog):
|
|||
{
|
||||
"0": [{"result": {"event": "test_event", "event_data": {}}}],
|
||||
"1": [{"error_type": script._StopScript}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="aborted",
|
||||
)
|
||||
|
||||
|
||||
|
@ -680,7 +684,8 @@ async def test_delay_template_complex_invalid(hass, caplog):
|
|||
{
|
||||
"0": [{"result": {"event": "test_event", "event_data": {}}}],
|
||||
"1": [{"error_type": script._StopScript}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="aborted",
|
||||
)
|
||||
|
||||
|
||||
|
@ -717,7 +722,8 @@ async def test_cancel_delay(hass):
|
|||
assert_action_trace(
|
||||
{
|
||||
"0": [{"result": {"delay": 5.0, "done": False}}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="cancelled",
|
||||
)
|
||||
|
||||
|
||||
|
@ -969,13 +975,15 @@ async def test_cancel_wait(hass, action_type):
|
|||
assert_action_trace(
|
||||
{
|
||||
"0": [{"result": {"wait": {"completed": False, "remaining": None}}}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="cancelled",
|
||||
)
|
||||
else:
|
||||
assert_action_trace(
|
||||
{
|
||||
"0": [{"result": {"wait": {"trigger": None, "remaining": None}}}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="cancelled",
|
||||
)
|
||||
|
||||
|
||||
|
@ -1131,6 +1139,7 @@ async def test_wait_continue_on_timeout(
|
|||
if continue_on_timeout is False:
|
||||
expected_trace["0"][0]["result"]["timeout"] = True
|
||||
expected_trace["0"][0]["error_type"] = script._StopScript
|
||||
expected_script_execution = "aborted"
|
||||
else:
|
||||
expected_trace["1"] = [
|
||||
{
|
||||
|
@ -1138,7 +1147,8 @@ async def test_wait_continue_on_timeout(
|
|||
"variables": variable_wait,
|
||||
}
|
||||
]
|
||||
assert_action_trace(expected_trace)
|
||||
expected_script_execution = "finished"
|
||||
assert_action_trace(expected_trace, expected_script_execution)
|
||||
|
||||
|
||||
async def test_wait_template_variables_in(hass):
|
||||
|
@ -1404,7 +1414,8 @@ async def test_condition_warning(hass, caplog):
|
|||
"1": [{"error_type": script._StopScript, "result": {"result": False}}],
|
||||
"1/condition": [{"error_type": ConditionError}],
|
||||
"1/condition/entity_id/0": [{"error_type": ConditionError}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="aborted",
|
||||
)
|
||||
|
||||
|
||||
|
@ -1456,7 +1467,8 @@ async def test_condition_basic(hass, caplog):
|
|||
"0": [{"result": {"event": "test_event", "event_data": {}}}],
|
||||
"1": [{"error_type": script._StopScript, "result": {"result": False}}],
|
||||
"1/condition": [{"result": {"result": False}}],
|
||||
}
|
||||
},
|
||||
expected_script_execution="aborted",
|
||||
)
|
||||
|
||||
|
||||
|
@ -2141,7 +2153,7 @@ async def test_propagate_error_service_not_found(hass):
|
|||
}
|
||||
],
|
||||
}
|
||||
assert_action_trace(expected_trace)
|
||||
assert_action_trace(expected_trace, expected_script_execution="error")
|
||||
|
||||
|
||||
async def test_propagate_error_invalid_service_data(hass):
|
||||
|
@ -2178,7 +2190,7 @@ async def test_propagate_error_invalid_service_data(hass):
|
|||
}
|
||||
],
|
||||
}
|
||||
assert_action_trace(expected_trace)
|
||||
assert_action_trace(expected_trace, expected_script_execution="error")
|
||||
|
||||
|
||||
async def test_propagate_error_service_exception(hass):
|
||||
|
@ -2219,7 +2231,7 @@ async def test_propagate_error_service_exception(hass):
|
|||
}
|
||||
],
|
||||
}
|
||||
assert_action_trace(expected_trace)
|
||||
assert_action_trace(expected_trace, expected_script_execution="error")
|
||||
|
||||
|
||||
async def test_referenced_entities(hass):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue