Add as_function to allow macros to return values (#142033)
This commit is contained in:
@@ -828,6 +828,23 @@ def test_apply_macro_with_arguments(hass: HomeAssistant) -> None:
|
||||
).async_render() == ["Hey, Alice!", "Hey, Bob!"]
|
||||
|
||||
|
||||
def test_as_function(hass: HomeAssistant) -> None:
|
||||
"""Test as_function."""
|
||||
assert (
|
||||
template.Template(
|
||||
"""
|
||||
{%- macro macro_double(num, returns) -%}
|
||||
{%- do returns(num * 2) -%}
|
||||
{%- endmacro -%}
|
||||
{%- set double = macro_double | as_function -%}
|
||||
{{ double(5) }}
|
||||
""",
|
||||
hass,
|
||||
).async_render()
|
||||
== 10
|
||||
)
|
||||
|
||||
|
||||
def test_logarithm(hass: HomeAssistant) -> None:
|
||||
"""Test logarithm."""
|
||||
tests = [
|
||||
|
||||
Reference in New Issue
Block a user