From 2edd69fd64cde8e9b76cf96fcee50438fdc0c863 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Sun, 19 Nov 2017 23:05:18 +0000 Subject: [PATCH] Add requitements for tests. --- .coveragerc | 1 - homeassistant/components/weather/yweather.py | 10 ++--- requirements_test_all.txt | 3 ++ tests/components/weather/test_yweather.py | 39 ++++++++++---------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.coveragerc b/.coveragerc index dd3874a9ffd..142327bd389 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/homeassistant/components/weather/yweather.py b/homeassistant/components/weather/yweather.py index a043f3c2212..f7f9e81f776 100644 --- a/homeassistant/components/weather/yweather.py +++ b/homeassistant/components/weather/yweather.py @@ -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): diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4331b7d11e6..56c35b955b1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/weather/test_yweather.py b/tests/components/weather/test_yweather.py index 1d4dfea6f43..ce212275abd 100644 --- a/tests/components/weather/test_yweather.py +++ b/tests/components/weather/test_yweather.py @@ -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):