Update weather tests to pytest style (#40917)

This commit is contained in:
Antetokounpo 2020-10-01 03:14:48 -04:00 committed by GitHub
parent 632bf4f7f7
commit df1e910ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,4 @@
"""The tests for the Weather component.""" """The tests for the Weather component."""
import unittest
from homeassistant.components import weather from homeassistant.components import weather
from homeassistant.components.weather import ( from homeassistant.components.weather import (
ATTR_FORECAST, ATTR_FORECAST,
@ -17,32 +15,19 @@ from homeassistant.components.weather import (
ATTR_WEATHER_WIND_BEARING, ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_SPEED, ATTR_WEATHER_WIND_SPEED,
) )
from homeassistant.setup import setup_component from homeassistant.setup import async_setup_component
from homeassistant.util.unit_system import METRIC_SYSTEM from homeassistant.util.unit_system import METRIC_SYSTEM
from tests.common import get_test_home_assistant
async def test_attributes(hass):
class TestWeather(unittest.TestCase):
"""Test the Weather component."""
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.units = METRIC_SYSTEM
assert setup_component(
self.hass, weather.DOMAIN, {"weather": {"platform": "demo"}}
)
self.hass.block_till_done()
self.addCleanup(self.tear_down_cleanup)
def tear_down_cleanup(self):
"""Stop down everything that was started."""
self.hass.stop()
def test_attributes(self):
"""Test weather attributes.""" """Test weather attributes."""
state = self.hass.states.get("weather.demo_weather_south") assert await async_setup_component(
hass, weather.DOMAIN, {"weather": {"platform": "demo"}}
)
hass.config.units = METRIC_SYSTEM
await hass.async_block_till_done()
state = hass.states.get("weather.demo_weather_south")
assert state is not None assert state is not None
assert state.state == "sunny" assert state.state == "sunny"
@ -57,10 +42,7 @@ class TestWeather(unittest.TestCase):
assert data.get(ATTR_WEATHER_ATTRIBUTION) == "Powered by Home Assistant" assert data.get(ATTR_WEATHER_ATTRIBUTION) == "Powered by Home Assistant"
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_CONDITION) == "rainy" assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_CONDITION) == "rainy"
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION) == 1 assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION) == 1
assert ( assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) == 60
data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY)
== 60
)
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP) == 22 assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP) == 22
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP_LOW) == 15 assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP_LOW) == 15
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_CONDITION) == "fog" assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_CONDITION) == "fog"
@ -68,14 +50,20 @@ class TestWeather(unittest.TestCase):
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP) == 21 assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP) == 21
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP_LOW) == 12 assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP_LOW) == 12
assert ( assert (
data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) == 100
== 100
) )
assert len(data.get(ATTR_FORECAST)) == 7 assert len(data.get(ATTR_FORECAST)) == 7
def test_temperature_convert(self):
async def test_temperature_convert(hass):
"""Test temperature conversion.""" """Test temperature conversion."""
state = self.hass.states.get("weather.demo_weather_north") assert await async_setup_component(
hass, weather.DOMAIN, {"weather": {"platform": "demo"}}
)
hass.config.units = METRIC_SYSTEM
await hass.async_block_till_done()
state = hass.states.get("weather.demo_weather_north")
assert state is not None assert state is not None
assert state.state == "rainy" assert state.state == "rainy"