Add requitements for tests.

This commit is contained in:
Tobias Sauerwein
2017-11-19 23:05:18 +00:00
parent 8d1da7cc38
commit 2edd69fd64
4 changed files with 27 additions and 26 deletions

View File

@@ -631,7 +631,6 @@ omit =
homeassistant/components/weather/buienradar.py
homeassistant/components/weather/metoffice.py
homeassistant/components/weather/openweathermap.py
homeassistant/components/weather/yweather.py
homeassistant/components/weather/zamg.py
homeassistant/components/zeroconf.py
homeassistant/components/zwave/util.py

View File

@@ -125,27 +125,27 @@ class YahooWeatherWeather(WeatherEntity):
@property
def pressure(self):
"""Return the pressure."""
return self._data.yahoo.Atmosphere['pressure']
return float(self._data.yahoo.Atmosphere['pressure'])
@property
def humidity(self):
"""Return the humidity."""
return self._data.yahoo.Atmosphere['humidity']
return int(self._data.yahoo.Atmosphere['humidity'])
@property
def visibility(self):
"""Return the visibility."""
return self._data.yahoo.Atmosphere['visibility']
return float(self._data.yahoo.Atmosphere['visibility'])
@property
def wind_speed(self):
"""Return the wind speed."""
return self._data.yahoo.Wind['speed']
return float(self._data.yahoo.Wind['speed'])
@property
def wind_bearing(self):
"""Return the wind direction."""
return self._data.yahoo.Wind['direction']
return int(self._data.yahoo.Wind['direction'])
@property
def attribution(self):

View File

@@ -180,3 +180,6 @@ warrant==0.5.0
# homeassistant.components.sensor.yahoo_finance
yahoo-finance==1.4.0
# homeassistant.components.weather.yweather
yahooweather==0.9

View File

@@ -2,15 +2,13 @@
import json
import unittest
import requests_mock
from unittest.mock import patch, MagicMock
from unittest.mock import patch
import requests_mock # pylint: disable=import-error
#from homeassistant.components import weather
from homeassistant.components.weather import yweather
from homeassistant.components.weather import (
ATTR_WEATHER_ATTRIBUTION, ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_OZONE,
ATTR_WEATHER_PRESSURE, ATTR_WEATHER_TEMPERATURE, ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_SPEED, ATTR_FORECAST, ATTR_FORECAST_TEMP)
ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_PRESSURE, ATTR_WEATHER_TEMPERATURE,
ATTR_WEATHER_WIND_BEARING, ATTR_WEATHER_WIND_SPEED)
from homeassistant.util.unit_system import METRIC_SYSTEM
from homeassistant.setup import setup_component
@@ -21,19 +19,22 @@ def mock_responses(mock):
"""Mock responses for Yahoo Weather."""
base_url = 'https://query.yahooapis.com/v1/public/yql'
mock.get(base_url +
'?q=SELECT+woeid+FROM+geo.places+WHERE+text+%3D+%27%2832.87336'+
'?q=SELECT+woeid+FROM+geo.places+WHERE+text+%3D+%27%2832.87336' +
'%2C-117.22743%29%27&format=json',
text=load_fixture('yahooweather.json'))
def _yql_queryMock(yql):
def _yql_queryMock(yql): # pylint: disable=invalid-name
"""Mock yahoo query language query."""
return ('{"query": {"count": 1, "created": "2017-11-17T13:40:47Z", '
'"lang": "en-US", "results": {"place": {"woeid": "23511632"}}}}')
def get_woeidMock(lat, lon):
def get_woeidMock(lat, lon): # pylint: disable=invalid-name
"""Mock get woeid Where On Earth Identifiers."""
return '23511632'
class YahooWeatherMock():
"""Mock class for the YahooWeather object."""
@@ -43,43 +44,41 @@ class YahooWeatherMock():
self.temp_unit = temp_unit
self._data = json.loads(load_fixture('yahooweather.json'))
def updateWeather(self):
# pylint: disable=no-self-use
def updateWeather(self): # pylint: disable=invalid-name
"""Return sample values."""
return True
@property
def RawData(self):
def RawData(self): # pylint: disable=invalid-name
"""Raw Data."""
if self.woeid == '12345':
return json.loads('[]')
return self._data
@property
def Now(self):
def Now(self): # pylint: disable=invalid-name
"""Current weather data."""
if self.woeid == '111':
raise ValueError
return None
return self._data['query']['results']['channel']['item']['condition']
@property
def Atmosphere(self):
def Atmosphere(self): # pylint: disable=invalid-name
"""Atmosphere weather data."""
return self._data['query']['results']['channel']['atmosphere']
@property
def Wind(self):
def Wind(self): # pylint: disable=invalid-name
"""Wind weather data."""
return self._data['query']['results']['channel']['wind']
@property
def Forecast(self):
def Forecast(self): # pylint: disable=invalid-name
"""Forecast data 0-5 Days."""
if self.woeid == '123123':
raise ValueError
else:
return self._data['query']['results']['channel']['item']['forecast']
return None
return self._data['query']['results']['channel']['item']['forecast']
class TestWeather(unittest.TestCase):