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_next_year(self):
result = timeutils.next_year()
expected = datetime.now() + timedelta(days=365)
self.assertAlmostEqual(
float(timeformatutils.to_UNIXtime(expected)),
float(timeformatutils.to_UNIXtime(result)))
def test_last_week(self):
result = timeutils.last_week()
expected = datetime.now() + timedelta(days=-7)
self.assertAlmostEqual(
float(timeformatutils.to_UNIXtime(expected)),
float(timeformatutils.to_UNIXtime(result)))
def test_last_week(self):
result = timeutils.last_week()
expected = datetime.now() + timedelta(days=-7)
self.assertAlmostEqual(
float(timeformatutils.to_UNIXtime(expected)),
float(timeformatutils.to_UNIXtime(result)))
def test_next_hour(self):
result = timeutils.next_hour()
expected = datetime.now() + timedelta(hours=1)
self.assertAlmostEqual(
float(timeformatutils.to_UNIXtime(expected)),
float(timeformatutils.to_UNIXtime(result)))
def test_next_year(self):
result = timeutils.next_year()
expected = datetime.now() + timedelta(days=365)
self.assertAlmostEqual(
float(timeformatutils.to_UNIXtime(expected)),
float(timeformatutils.to_UNIXtime(result)))
def test_to_UNIXtime(self):
unix = 1378459200
iso = "2013-09-06 09:20:00+00"
date = datetime(2013, 9, 6, 9, 20, 0, tzinfo=timeformatutils.UTC())
self.assertEqual(unix, timeformatutils.to_UNIXtime(unix))
self.assertEqual(unix, timeformatutils.to_UNIXtime(iso))
self.assertEqual(unix, timeformatutils.to_UNIXtime(date))
cannot be parsed, *APICallException* when OWM web API can not be
reached, *ValueError* if the time boundaries are not in the correct
chronological order, if one of the time boundaries is not ``None``
and the other is or if one or both of the time boundaries are after
the current time
"""
assert type(id) is int, "'id' must be an int"
if id < 0:
raise ValueError("'id' value must be greater than 0")
params = {'id': id, 'lang': self._language}
if start is None and end is None:
pass
elif start is not None and end is not None:
unix_start = timeformatutils.to_UNIXtime(start)
unix_end = timeformatutils.to_UNIXtime(end)
if unix_start >= unix_end:
raise ValueError("Error: the start time boundary must " \
"precede the end time!")
current_time = time()
if unix_start > current_time:
raise ValueError("Error: the start time boundary must " \
"precede the current time!")
params['start'] = str(unix_start)
params['end'] = str(unix_end)
else:
raise ValueError("Error: one of the time boundaries is None, " \
"while the other is not!")
uri = http_client.HttpClient.to_url(CITY_WEATHER_HISTORY_URL,
self._API_key,
self._subscription_type,
self._use_ssl)
def get_alerts_since(self, timestamp):
"""
Returns all the `Alert` objects of this `Trigger` that were fired since the specified timestamp.
:param timestamp: time object representing the point in time since when alerts have to be fetched
:type timestamp: int, ``datetime.datetime`` or ISO8601-formatted string
:return: list of `Alert` instances
"""
unix_timestamp = timeformatutils.to_UNIXtime(timestamp)
result = []
for alert in self.alerts:
if alert.last_update >= unix_timestamp:
result.append(alert)
return result
:raises: *ParseResponseException* when OWM web API responses' data
cannot be parsed, *APICallException* when OWM web API can not be
reached, *ValueError* if the time boundaries are not in the correct
chronological order, if one of the time boundaries is not ``None``
and the other is or if one or both of the time boundaries are after
the current time
"""
assert type(id) is int, "'id' must be an int"
if id < 0:
raise ValueError("'id' value must be greater than 0")
params = {'id': id, 'lang': self._language}
if start is None and end is None:
pass
elif start is not None and end is not None:
unix_start = timeformatutils.to_UNIXtime(start)
unix_end = timeformatutils.to_UNIXtime(end)
if unix_start >= unix_end:
raise ValueError("Error: the start time boundary must " \
"precede the end time!")
current_time = time()
if unix_start > current_time:
raise ValueError("Error: the start time boundary must " \
"precede the current time!")
params['start'] = str(unix_start)
params['end'] = str(unix_end)
else:
raise ValueError("Error: one of the time boundaries is None, " \
"while the other is not!")
uri = http_client.HttpClient.to_url(CITY_WEATHER_HISTORY_URL,
self._API_key,
self._subscription_type,
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, *ValueError* if the time boundaries are not in the correct
chronological order, if one of the time boundaries is not ``None``
and the other is or if one or both of the time boundaries are after
the current time
"""
OWM25._assert_is_string("name", name)
params = {'q': name, 'lang': self._language}
if start is None and end is None:
pass
elif start is not None and end is not None:
unix_start = timeformatutils.to_UNIXtime(start)
unix_end = timeformatutils.to_UNIXtime(end)
if unix_start >= unix_end:
raise ValueError("Error: the start time boundary must "
"precede the end time!")
current_time = time()
if unix_start > current_time:
raise ValueError("Error: the start time boundary must "
"precede the current time!")
params['start'] = str(unix_start)
params['end'] = str(unix_end)
else:
raise ValueError("Error: one of the time boundaries is None, "
"while the other is not!")
json_data = self._httpclient.call_API(CITY_WEATHER_HISTORY_URL,
params)
return self._parsers['weather_history'].parse_JSON(json_data)