Migrate yr tests from coroutine to async/await (#30351)

This commit is contained in:
Franck Nijhof 2020-01-01 16:21:37 +01:00 committed by Martin Hjelmare
parent 33828ae514
commit bc6e2a06e6

View file

@ -1,5 +1,4 @@
"""The tests for the Yr sensor platform."""
import asyncio
from datetime import datetime
from unittest.mock import patch
@ -11,8 +10,7 @@ from tests.common import assert_setup_component, load_fixture
NOW = datetime(2016, 6, 9, 1, tzinfo=dt_util.UTC)
@asyncio.coroutine
def test_default_setup(hass, aioclient_mock):
async def test_default_setup(hass, aioclient_mock):
"""Test the default setup."""
aioclient_mock.get(
"https://aa015h6buqvih86i1.api.met.no/" "weatherapi/locationforecast/1.9/",
@ -23,7 +21,7 @@ def test_default_setup(hass, aioclient_mock):
with patch(
"homeassistant.components.yr.sensor.dt_util.utcnow", return_value=NOW
), assert_setup_component(1):
yield from async_setup_component(hass, "sensor", {"sensor": config})
await async_setup_component(hass, "sensor", {"sensor": config})
state = hass.states.get("sensor.yr_symbol")
@ -31,8 +29,7 @@ def test_default_setup(hass, aioclient_mock):
assert state.attributes.get("unit_of_measurement") is None
@asyncio.coroutine
def test_custom_setup(hass, aioclient_mock):
async def test_custom_setup(hass, aioclient_mock):
"""Test a custom setup."""
aioclient_mock.get(
"https://aa015h6buqvih86i1.api.met.no/" "weatherapi/locationforecast/1.9/",
@ -54,7 +51,7 @@ def test_custom_setup(hass, aioclient_mock):
with patch(
"homeassistant.components.yr.sensor.dt_util.utcnow", return_value=NOW
), assert_setup_component(1):
yield from async_setup_component(hass, "sensor", {"sensor": config})
await async_setup_component(hass, "sensor", {"sensor": config})
state = hass.states.get("sensor.yr_pressure")
assert state.attributes.get("unit_of_measurement") == "hPa"
@ -77,8 +74,7 @@ def test_custom_setup(hass, aioclient_mock):
assert state.state == "3.5"
@asyncio.coroutine
def test_forecast_setup(hass, aioclient_mock):
async def test_forecast_setup(hass, aioclient_mock):
"""Test a custom setup with 24h forecast."""
aioclient_mock.get(
"https://aa015h6buqvih86i1.api.met.no/" "weatherapi/locationforecast/1.9/",
@ -101,7 +97,7 @@ def test_forecast_setup(hass, aioclient_mock):
with patch(
"homeassistant.components.yr.sensor.dt_util.utcnow", return_value=NOW
), assert_setup_component(1):
yield from async_setup_component(hass, "sensor", {"sensor": config})
await async_setup_component(hass, "sensor", {"sensor": config})
state = hass.states.get("sensor.yr_pressure")
assert state.attributes.get("unit_of_measurement") == "hPa"