35 lines
786 B
Python
35 lines
786 B
Python
|
"""Test inputs."""
|
||
|
import pytest
|
||
|
|
||
|
from homeassistant.util.yaml import (
|
||
|
Input,
|
||
|
UndefinedSubstitution,
|
||
|
extract_inputs,
|
||
|
substitute,
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_extract_inputs():
|
||
|
"""Test extracting inputs from data."""
|
||
|
assert extract_inputs(Input("hello")) == {"hello"}
|
||
|
assert extract_inputs({"info": [1, Input("hello"), 2, Input("world")]}) == {
|
||
|
"hello",
|
||
|
"world",
|
||
|
}
|
||
|
|
||
|
|
||
|
def test_substitute():
|
||
|
"""Test we can substitute."""
|
||
|
assert substitute(Input("hello"), {"hello": 5}) == 5
|
||
|
|
||
|
with pytest.raises(UndefinedSubstitution):
|
||
|
substitute(Input("hello"), {})
|
||
|
|
||
|
assert (
|
||
|
substitute(
|
||
|
{"info": [1, Input("hello"), 2, Input("world")]},
|
||
|
{"hello": 5, "world": 10},
|
||
|
)
|
||
|
== {"info": [1, 5, 2, 10]}
|
||
|
)
|