1
0
mirror of https://github.com/esphome/esphome.git synced 2025-07-04 06:03:14 +01:00

Introduce new async-def coroutine syntax ()

This commit is contained in:
Otto Winter
2021-05-17 07:14:15 +02:00
committed by GitHub
parent 95ed3e9d46
commit d4686c0fb1
10 changed files with 391 additions and 238 deletions

@ -6,25 +6,24 @@ from esphome import const
from esphome.cpp_generator import MockObj
def test_gpio_pin_expression__conf_is_none(monkeypatch):
target = ch.gpio_pin_expression(None)
actual = next(target)
@pytest.mark.asyncio
async def test_gpio_pin_expression__conf_is_none(monkeypatch):
actual = await ch.gpio_pin_expression(None)
assert actual is None
def test_gpio_pin_expression__new_pin(monkeypatch):
target = ch.gpio_pin_expression(
@pytest.mark.asyncio
async def test_gpio_pin_expression__new_pin(monkeypatch):
actual = await ch.gpio_pin_expression(
{const.CONF_NUMBER: 42, const.CONF_MODE: "input", const.CONF_INVERTED: False}
)
actual = next(target)
assert isinstance(actual, MockObj)
def test_register_component(monkeypatch):
@pytest.mark.asyncio
async def test_register_component(monkeypatch):
var = Mock(base="foo.bar")
app_mock = Mock(register_component=Mock(return_value=var))
@ -36,9 +35,7 @@ def test_register_component(monkeypatch):
add_mock = Mock()
monkeypatch.setattr(ch, "add", add_mock)
target = ch.register_component(var, {})
actual = next(target)
actual = await ch.register_component(var, {})
assert actual is var
add_mock.assert_called_once()
@ -46,18 +43,19 @@ def test_register_component(monkeypatch):
assert core_mock.component_ids == []
def test_register_component__no_component_id(monkeypatch):
@pytest.mark.asyncio
async def test_register_component__no_component_id(monkeypatch):
var = Mock(base="foo.eek")
core_mock = Mock(component_ids=["foo.bar"])
monkeypatch.setattr(ch, "CORE", core_mock)
with pytest.raises(ValueError, match="Component ID foo.eek was not declared to"):
target = ch.register_component(var, {})
next(target)
await ch.register_component(var, {})
def test_register_component__with_setup_priority(monkeypatch):
@pytest.mark.asyncio
async def test_register_component__with_setup_priority(monkeypatch):
var = Mock(base="foo.bar")
app_mock = Mock(register_component=Mock(return_value=var))
@ -69,7 +67,7 @@ def test_register_component__with_setup_priority(monkeypatch):
add_mock = Mock()
monkeypatch.setattr(ch, "add", add_mock)
target = ch.register_component(
actual = await ch.register_component(
var,
{
const.CONF_SETUP_PRIORITY: "123",
@ -77,8 +75,6 @@ def test_register_component__with_setup_priority(monkeypatch):
},
)
actual = next(target)
assert actual is var
add_mock.assert_called()
assert add_mock.call_count == 3