Skip to content

Commit

Permalink
Migrate yr tests from coroutine to async/await (home-assistant#30351)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored and MartinHjelmare committed Jan 1, 2020
1 parent 33828ae commit bc6e2a0
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tests/components/yr/test_sensor.py
@@ -1,5 +1,4 @@
"""The tests for the Yr sensor platform."""
import asyncio
from datetime import datetime
from unittest.mock import patch

Expand All @@ -11,8 +10,7 @@
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/",
Expand All @@ -23,16 +21,15 @@ 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")

assert state.state == "3"
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/",
Expand All @@ -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"
Expand All @@ -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/",
Expand All @@ -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"
Expand Down

0 comments on commit bc6e2a0

Please sign in to comment.