Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_weather_at_fails_with_bad_parameter(self):
self.assertRaises(TypeError, Forecaster.get_weather_at,
self.__test_instance, 45.7)
def test_most_cold_returning_None(self):
fcstr = Forecaster(Forecast("daily", 1379089800, self.__test_location,
[self.__test_none_values]))
self.assertFalse(fcstr.most_hot())
assert isinstance(limit, int), "'limit' must be an int or None"
if limit < 1:
raise ValueError("'limit' must be None or greater than zero")
params = {'id': id, 'lang': self._language}
if limit is not None:
params['cnt'] = limit
uri = http_client.HttpClient.to_url(DAILY_FORECAST_URL,
self._API_key,
self._subscription_type,
self._use_ssl)
_, json_data = self._wapi.cacheable_get_json(uri, params=params)
forecast = self._parsers['forecast'].parse_JSON(json_data)
if forecast is not None:
forecast.set_interval("daily")
return forecaster.Forecaster(forecast)
else:
return None
def to_forecast(self, data, interval):
forecast = self.forecast.parse_JSON(data)
if forecast is not None:
forecast.set_interval(interval)
return Forecaster(forecast)
else:
return None
:returns: a *Forecaster* instance or ``None`` if forecast data is not
available for the specified location
:raises: *ParseResponseException* when OWM web API responses' data
cannot be parsed, *APICallException* when OWM web API can not be
reached
"""
assert type(id) is int, "'id' must be an int"
if id < 0:
raise ValueError("'id' value must be greater than 0")
json_data = self._httpclient.call_API(THREE_HOURS_FORECAST_URL,
{'id': id,
'lang': self._language})
forecast = self._parsers['forecast'].parse_JSON(json_data)
if forecast is not None:
forecast.set_interval("3h")
return forecaster.Forecaster(forecast)
else:
return None
assert type(id) is int, "'id' must be an int"
if id < 0:
raise ValueError("'id' value must be greater than 0")
if limit is not None:
assert isinstance(limit, int), "'limit' must be an int or None"
if limit < 1:
raise ValueError("'limit' must be None or greater than zero")
params = {'id': id, 'lang': self._language}
if limit is not None:
params['cnt'] = limit
json_data = self._httpclient.call_API(DAILY_FORECAST_URL, params)
forecast = self._parsers['forecast'].parse_JSON(json_data)
if forecast is not None:
forecast.set_interval("daily")
return forecaster.Forecaster(forecast)
else:
return None
def to_forecast(self, data, interval):
forecast = self.forecast.parse_JSON(data)
if forecast is not None:
forecast.set_interval(interval)
return Forecaster(forecast)
else:
return None
:raises: *ParseResponseException* when OWM web API responses' data
cannot be parsed, *APICallException* when OWM web API can not be
reached
"""
assert type(lon) is float or type(lon) is int, "'lon' must be a float"
if lon < -180.0 or lon > 180.0:
raise ValueError("'lon' value must be between -180 and 180")
assert type(lat) is float or type(lat) is int, "'lat' must be a float"
if lat < -90.0 or lat > 90.0:
raise ValueError("'lat' value must be between -90 and 90")
params = {'lon': lon, 'lat': lat, 'lang': self._language}
json_data = self._httpclient.call_API(THREE_HOURS_FORECAST_URL, params)
forecast = self._parsers['forecast'].parse_JSON(json_data)
if forecast is not None:
forecast.set_interval("3h")
return forecaster.Forecaster(forecast)
else:
return None