mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Migrate startca tests from coroutine to async/await (#30354)
This commit is contained in:
parent
e099d57bde
commit
9fbe6d60cb
@ -1,13 +1,10 @@
|
|||||||
"""Tests for the Start.ca sensor platform."""
|
"""Tests for the Start.ca sensor platform."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components.startca.sensor import StartcaData
|
from homeassistant.components.startca.sensor import StartcaData
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_capped_setup(hass, aioclient_mock):
|
||||||
def test_capped_setup(hass, aioclient_mock):
|
|
||||||
"""Test the default setup."""
|
"""Test the default setup."""
|
||||||
config = {
|
config = {
|
||||||
"platform": "startca",
|
"platform": "startca",
|
||||||
@ -51,7 +48,7 @@ def test_capped_setup(hass, aioclient_mock):
|
|||||||
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text=result
|
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text=result
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from async_setup_component(hass, "sensor", {"sensor": config})
|
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||||
|
|
||||||
state = hass.states.get("sensor.start_ca_usage_ratio")
|
state = hass.states.get("sensor.start_ca_usage_ratio")
|
||||||
assert state.attributes.get("unit_of_measurement") == "%"
|
assert state.attributes.get("unit_of_measurement") == "%"
|
||||||
@ -102,8 +99,7 @@ def test_capped_setup(hass, aioclient_mock):
|
|||||||
assert state.state == "95.05"
|
assert state.state == "95.05"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_unlimited_setup(hass, aioclient_mock):
|
||||||
def test_unlimited_setup(hass, aioclient_mock):
|
|
||||||
"""Test the default setup."""
|
"""Test the default setup."""
|
||||||
config = {
|
config = {
|
||||||
"platform": "startca",
|
"platform": "startca",
|
||||||
@ -147,7 +143,7 @@ def test_unlimited_setup(hass, aioclient_mock):
|
|||||||
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text=result
|
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text=result
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from async_setup_component(hass, "sensor", {"sensor": config})
|
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||||
|
|
||||||
state = hass.states.get("sensor.start_ca_usage_ratio")
|
state = hass.states.get("sensor.start_ca_usage_ratio")
|
||||||
assert state.attributes.get("unit_of_measurement") == "%"
|
assert state.attributes.get("unit_of_measurement") == "%"
|
||||||
@ -198,8 +194,7 @@ def test_unlimited_setup(hass, aioclient_mock):
|
|||||||
assert state.state == "inf"
|
assert state.state == "inf"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_bad_return_code(hass, aioclient_mock):
|
||||||
def test_bad_return_code(hass, aioclient_mock):
|
|
||||||
"""Test handling a return code that isn't HTTP OK."""
|
"""Test handling a return code that isn't HTTP OK."""
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", status=404
|
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", status=404
|
||||||
@ -207,12 +202,11 @@ def test_bad_return_code(hass, aioclient_mock):
|
|||||||
|
|
||||||
scd = StartcaData(hass.loop, async_get_clientsession(hass), "NOTAKEY", 400)
|
scd = StartcaData(hass.loop, async_get_clientsession(hass), "NOTAKEY", 400)
|
||||||
|
|
||||||
result = yield from scd.async_update()
|
result = await scd.async_update()
|
||||||
assert result is False
|
assert result is False
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_bad_json_decode(hass, aioclient_mock):
|
||||||
def test_bad_json_decode(hass, aioclient_mock):
|
|
||||||
"""Test decoding invalid json result."""
|
"""Test decoding invalid json result."""
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text="this is not xml"
|
"https://www.start.ca/support/usage/api?key=" "NOTAKEY", text="this is not xml"
|
||||||
@ -220,5 +214,5 @@ def test_bad_json_decode(hass, aioclient_mock):
|
|||||||
|
|
||||||
scd = StartcaData(hass.loop, async_get_clientsession(hass), "NOTAKEY", 400)
|
scd = StartcaData(hass.loop, async_get_clientsession(hass), "NOTAKEY", 400)
|
||||||
|
|
||||||
result = yield from scd.async_update()
|
result = await scd.async_update()
|
||||||
assert result is False
|
assert result is False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user