mirror of
https://github.com/esphome/esphome.git
synced 2026-09-21 20:18:43 +00:00
[core] Expand = delete to catch inconvertible return types, add to_exp test
- TemplatableFn = delete now catches both stateful lambdas AND stateless lambdas with inconvertible return types (e.g., string -> int) - Add test for to_exp with non-string output_type (lambda-wraps result)
This commit is contained in:
@@ -684,6 +684,15 @@ async def test_templatable__with_to_exp_callable() -> None:
|
||||
assert result == 84
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_templatable__with_to_exp_callable_and_output_type() -> None:
|
||||
"""When to_exp is provided with non-string output_type, result is lambda-wrapped."""
|
||||
result = await cg.templatable(42, [], ct.int_, to_exp=lambda x: x * 2)
|
||||
|
||||
assert isinstance(result, cg.LambdaExpression)
|
||||
assert result.capture == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_templatable__with_to_exp_dict() -> None:
|
||||
"""When to_exp is a dict, value is looked up."""
|
||||
|
||||
Reference in New Issue
Block a user