Store original result on template results (#42391)

* Store original result on template results

* Fix shell command test
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-10-26 11:30:58 +01:00
1 parent 6645cb2637
commit e552c9ba96
5 files changed
+108 -19

No files matched your search

+1 -1
View File
@@ -174,7 +174,7 @@ async def test_do_no_run_forever(hass, caplog):
assert await async_setup_component(
hass,
shell_command.DOMAIN,
{shell_command.DOMAIN: {"test_service": "sleep 10000"}},
{shell_command.DOMAIN: {"test_service": "sleep 10000s"}},
)
await hass.async_block_till_done()
+15 -2
View File
@@ -9,7 +9,7 @@ import pytest
import voluptuous as vol
import homeassistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import config_validation as cv, template
from tests.async_mock import Mock, patch
@@ -365,7 +365,7 @@ def test_slug():
schema(value)
def test_string():
def test_string(hass):
"""Test string validation."""
schema = vol.Schema(cv.string)
@@ -381,6 +381,19 @@ def test_string():
for value in (True, 1, "hello"):
schema(value)
# Test template support
for text, native in (
("[1, 2]", [1, 2]),
("{1, 2}", {1, 2}),
("(1, 2)", (1, 2)),
('{"hello": True}', {"hello": True}),
):
tpl = template.Template(text, hass)
result = tpl.async_render()
assert isinstance(result, template.ResultWrapper)
assert result == native
assert schema(result) == text
def test_string_with_no_html():
"""Test string with no html validation."""
+22
View File
@@ -2651,3 +2651,25 @@ async def test_legacy_templates(hass):
template.Template("{{ states.sensor.temperature.state }}", hass).async_render()
== "12"
)
async def test_is_static_still_ast_evals(hass):
"""Test is_static still convers to native type."""
tpl = template.Template("[1, 2]", hass)
assert tpl.is_static
assert tpl.async_render() == [1, 2]
async def test_result_wrappers(hass):
"""Test result wrappers."""
for text, native in (
("[1, 2]", [1, 2]),
("{1, 2}", {1, 2}),
("(1, 2)", (1, 2)),
('{"hello": True}', {"hello": True}),
):
tpl = template.Template(text, hass)
result = tpl.async_render()
assert isinstance(result, template.ResultWrapper)
assert result == native
assert result.render_result == text