hass-core/tests/helpers/test_placeholder.py
Paulus Schoutsen 0fb587727c
Add initial blueprint support (#42469)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2020-11-02 15:00:13 +01:00

29 lines
901 B
Python

"""Test placeholders."""
import pytest
from homeassistant.helpers import placeholder
from homeassistant.util.yaml import Placeholder
def test_extract_placeholders():
"""Test extracting placeholders from data."""
assert placeholder.extract_placeholders(Placeholder("hello")) == {"hello"}
assert placeholder.extract_placeholders(
{"info": [1, Placeholder("hello"), 2, Placeholder("world")]}
) == {"hello", "world"}
def test_substitute():
"""Test we can substitute."""
assert placeholder.substitute(Placeholder("hello"), {"hello": 5}) == 5
with pytest.raises(placeholder.UndefinedSubstitution):
placeholder.substitute(Placeholder("hello"), {})
assert (
placeholder.substitute(
{"info": [1, Placeholder("hello"), 2, Placeholder("world")]},
{"hello": 5, "world": 10},
)
== {"info": [1, 5, 2, 10]}
)