Migrate fido tests from coroutine to async/await (#30391)

This commit is contained in:
Franck Nijhof 2020-01-02 21:22:13 +01:00 committed by Andrew Sayre
parent 7b00e94184
commit 5b2b86987b

View File

@ -1,5 +1,4 @@
"""The test for the fido sensor platform.""" """The test for the fido sensor platform."""
import asyncio
import logging import logging
import sys import sys
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -27,8 +26,7 @@ class FidoClientMock:
"""Return fake fido data.""" """Return fake fido data."""
return {"balance": 160.12, "1112223344": {"data_remaining": 100.33}} return {"balance": 160.12, "1112223344": {"data_remaining": 100.33}}
@asyncio.coroutine async def fetch_data(self):
def fetch_data(self):
"""Return fake fetching data.""" """Return fake fetching data."""
pass pass
@ -36,8 +34,7 @@ class FidoClientMock:
class FidoClientMockError(FidoClientMock): class FidoClientMockError(FidoClientMock):
"""Fake Fido client error.""" """Fake Fido client error."""
@asyncio.coroutine async def fetch_data(self):
def fetch_data(self):
"""Return fake fetching data.""" """Return fake fetching data."""
raise PyFidoErrorMock("Fake Error") raise PyFidoErrorMock("Fake Error")
@ -63,8 +60,7 @@ def fake_async_add_entities(component, update_before_add=False):
pass pass
@asyncio.coroutine async def test_fido_sensor(loop, hass):
def test_fido_sensor(loop, hass):
"""Test the Fido number sensor.""" """Test the Fido number sensor."""
with patch( with patch(
"homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock "homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock
@ -79,7 +75,7 @@ def test_fido_sensor(loop, hass):
} }
} }
with assert_setup_component(1): with assert_setup_component(1):
yield from async_setup_component(hass, "sensor", config) await async_setup_component(hass, "sensor", config)
state = hass.states.get("sensor.fido_1112223344_balance") state = hass.states.get("sensor.fido_1112223344_balance")
assert state.state == "160.12" assert state.state == "160.12"
assert state.attributes.get("number") == "1112223344" assert state.attributes.get("number") == "1112223344"
@ -87,8 +83,7 @@ def test_fido_sensor(loop, hass):
assert state.state == "100.33" assert state.state == "100.33"
@asyncio.coroutine async def test_error(hass, caplog):
def test_error(hass, caplog):
"""Test the Fido sensor errors.""" """Test the Fido sensor errors."""
caplog.set_level(logging.ERROR) caplog.set_level(logging.ERROR)
sys.modules["pyfido"] = PyFidoFakeModule() sys.modules["pyfido"] = PyFidoFakeModule()
@ -96,5 +91,5 @@ def test_error(hass, caplog):
config = {} config = {}
fake_async_add_entities = MagicMock() fake_async_add_entities = MagicMock()
yield from fido.async_setup_platform(hass, config, fake_async_add_entities) await fido.async_setup_platform(hass, config, fake_async_add_entities)
assert fake_async_add_entities.called is False assert fake_async_add_entities.called is False