mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Migrate teksavvy tests from coroutine to async/await (#30353)
This commit is contained in:
parent
9fbe6d60cb
commit
9ba0daa358
@ -1,13 +1,10 @@
|
|||||||
"""Tests for the TekSavvy sensor platform."""
|
"""Tests for the TekSavvy sensor platform."""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components.teksavvy.sensor import TekSavvyData
|
from homeassistant.components.teksavvy.sensor import TekSavvyData
|
||||||
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": "teksavvy",
|
"platform": "teksavvy",
|
||||||
@ -45,7 +42,7 @@ def test_capped_setup(hass, aioclient_mock):
|
|||||||
text=result,
|
text=result,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from async_setup_component(hass, "sensor", {"sensor": config})
|
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||||
|
|
||||||
state = hass.states.get("sensor.teksavvy_data_limit")
|
state = hass.states.get("sensor.teksavvy_data_limit")
|
||||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||||
@ -88,8 +85,7 @@ def test_capped_setup(hass, aioclient_mock):
|
|||||||
assert state.state == "173.25"
|
assert state.state == "173.25"
|
||||||
|
|
||||||
|
|
||||||
@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": "teksavvy",
|
"platform": "teksavvy",
|
||||||
@ -127,7 +123,7 @@ def test_unlimited_setup(hass, aioclient_mock):
|
|||||||
text=result,
|
text=result,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from async_setup_component(hass, "sensor", {"sensor": config})
|
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||||
|
|
||||||
state = hass.states.get("sensor.teksavvy_data_limit")
|
state = hass.states.get("sensor.teksavvy_data_limit")
|
||||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||||
@ -170,8 +166,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://api.teksavvy.com/"
|
"https://api.teksavvy.com/"
|
||||||
@ -182,12 +177,11 @@ def test_bad_return_code(hass, aioclient_mock):
|
|||||||
|
|
||||||
tsd = TekSavvyData(hass.loop, async_get_clientsession(hass), "notakey", 400)
|
tsd = TekSavvyData(hass.loop, async_get_clientsession(hass), "notakey", 400)
|
||||||
|
|
||||||
result = yield from tsd.async_update()
|
result = await tsd.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://api.teksavvy.com/"
|
"https://api.teksavvy.com/"
|
||||||
@ -198,5 +192,5 @@ def test_bad_json_decode(hass, aioclient_mock):
|
|||||||
|
|
||||||
tsd = TekSavvyData(hass.loop, async_get_clientsession(hass), "notakey", 400)
|
tsd = TekSavvyData(hass.loop, async_get_clientsession(hass), "notakey", 400)
|
||||||
|
|
||||||
result = yield from tsd.async_update()
|
result = await tsd.async_update()
|
||||||
assert result is False
|
assert result is False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user