Skip to content

Commit

Permalink
bump to version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
csparpa committed May 30, 2020
2 parents 98be51d + cdd59eb commit 14f3841
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/forecast.py
Expand Up @@ -144,4 +144,4 @@ def __iter__(self):
def __repr__(self):
return "<%s.%s - reception_time=%s, interval=%s>" % (__name__, \
self.__class__.__name__, self.reception_time('iso'),
self.interval)
self.interval)
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/location.py
Expand Up @@ -112,4 +112,4 @@ def to_dict(self):
def __repr__(self):
return "<%s.%s - id=%s, name=%s, lon=%s, lat=%s>" % (__name__, \
self.__class__.__name__, self.id, self.name, str(self.lon), \
str(self.lat))
str(self.lat))
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/observation.py
Expand Up @@ -142,4 +142,4 @@ def from_dict_of_lists(self, the_dict):
return [Observation.from_dict(item) for item in the_dict['list']]

# no way out..
raise exceptions.ParseAPIResponseError(''.join([__name__, ': impossible to read JSON data']))
raise exceptions.ParseAPIResponseError(''.join([__name__, ': impossible to read JSON data']))
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/stationhistory.py
Expand Up @@ -132,4 +132,4 @@ def to_dict(self):
"measurements": self.measurements}

def __repr__(self):
return "<%s.%s - station_id=%s, interval=%s>" % (__name__, self.__class__.__name__, self.station_id, self.interval)
return "<%s.%s - station_id=%s, interval=%s>" % (__name__, self.__class__.__name__, self.station_id, self.interval)
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/weather.py
Expand Up @@ -505,4 +505,4 @@ def to_dict(self):
'humidex': self.humidex,
'heat_index': self.heat_index,
'utc_offset': self.utc_offset,
'uvi': self.uvi}
'uvi': self.uvi}
12 changes: 12 additions & 0 deletions tests/integration/commons/test_http_client.py
Expand Up @@ -73,6 +73,18 @@ def test_get_geotiff(self):
self.assertIsNotNone(data)
self.assertIsInstance(data, bytes)

def test_get_png(self):
# http://httpbin.org/image/png
status, data = self.instance.get_png('http://httpbin.org/image/png')
self.assertIsNotNone(data)
self.assertIsInstance(data, bytes)

def test_get_geotiff(self):
# https://download.osgeo.org/geotiff/samples/made_up/bogota.tif
status, data = self.instance.get_geotiff('https://download.osgeo.org/geotiff/samples/made_up/bogota.tif')
self.assertIsNotNone(data)
self.assertIsInstance(data, bytes)


if __name__ == "__main__":
unittest.main()
Expand Down
32 changes: 0 additions & 32 deletions tests/integration/weatherapi25/test_ssl.py

This file was deleted.

6 changes: 6 additions & 0 deletions tests/unit/utils/test_geo.py
Expand Up @@ -175,6 +175,12 @@ def test_polygon_points(self):
self.assertTrue(result)
self.assertTrue(all([isinstance(p, geo.Point) for p in result]))

def test_polygon_points(self):
p = geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]])
result = p.points
self.assertTrue(result)
self.assertTrue(all([isinstance(p, geo.Point) for p in result]))

def test_polygon_from_points(self):
expected = geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [2.3, 57.32]]])
list_of_lists = [
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/weatherapi25/json_test_responses.py
Expand Up @@ -19,6 +19,16 @@
'"weather":[{"id":803,"main":"Clouds","description":"brokenclouds","icon":"04d"}]}]}'


WEATHER_AT_PLACES_IN_BBOX_JSON = '{"cod":"200","calctime":0.3107,"cnt":2,' \
'"list":[{"id":2208791,"name":"Yafran","coord":{"lon":12.52859,"lat":32.06329},"main":{"temp":9.68,"temp_min":9.681,' \
'"temp_max":9.681,"pressure":961.02,"sea_level":1036.82,"grnd_level":961.02,"humidity":85},"dt":1485784982,' \
'"wind":{"speed":3.96,"deg":356.5},"rain":{"3h":0.255},"clouds":{"all":88},"weather":[{"id":500,"main":"Rain",' \
'"description":"lightrain","icon":"10d"}]},{"id":2208425,"name":"Zuwarah","coord":{"lon":12.08199,"lat":32.931198},' \
'"main":{"temp":15.36,"temp_min":15.356,"temp_max":15.356,"pressure":1036.81,"sea_level":1037.79,' \
'"grnd_level":1036.81,"humidity":89},"dt":1485784982,"wind":{"speed":5.46,"deg":30.0002},"clouds":{"all":56},' \
'"weather":[{"id":803,"main":"Clouds","description":"brokenclouds","icon":"04d"}]}]}'


SEARCH_RESULTS_JSON = '{"cod": "200", "count": 2, "list": [{"clouds": {"all": ' \
'20}, "coord": {"lat": 51.50853, "lon": -0.12573999999999999}, "dt": 1378237178,' \
' "id": 2643743, "main": {"humidity": 56, "pressure": 1025, "temp": ' \
Expand Down
81 changes: 40 additions & 41 deletions tests/unit/weatherapi25/test_forecast.py
Expand Up @@ -7,42 +7,41 @@
from pyowm.commons.exceptions import APIResponseError, ParseAPIResponseError
from pyowm.utils.formatting import UTC
from tests.unit.weatherapi25.json_test_responses import (
THREE_HOURS_FORECAST_JSON, FORECAST_NOT_FOUND_JSON,
INTERNAL_SERVER_ERROR_JSON, FORECAST_MALFORMED_JSON)
THREE_HOURS_FORECAST_JSON, FORECAST_NOT_FOUND_JSON,
INTERNAL_SERVER_ERROR_JSON, FORECAST_MALFORMED_JSON)


class TestForecast(unittest.TestCase):

__test_reception_time = 1234567
__test_iso_reception_time = "1970-01-15 06:56:07+00"
__test_date_reception_time = datetime.strptime(__test_iso_reception_time,
'%Y-%m-%d %H:%M:%S+00').replace(tzinfo=UTC())
'%Y-%m-%d %H:%M:%S+00').replace(tzinfo=UTC())
__test_location = Location('test', 12.3, 43.7, 987, 'IT')
__test_weathers = [Weather(1378459200, 1378496400, 1378449600, 67,
{"all": 20}, {"all": 0}, {"deg": 252.002, "speed": 1.100}, 57,
{"press": 1030.119, "sea_level": 1038.589},
{"temp": 294.199, "temp_kf": -1.899, "temp_max": 296.098,
"temp_min": 294.199
},
"Clouds", "Overcast clouds", 804, "04d", 1000, 300.0, 298.0, 296.0),
Weather(1378459690, 1378496480, 1378449510, 23, {"all": 10},
{"all": 0}, {"deg": 103.4, "speed": 4.2}, 12,
{"press": 1070.119, "sea_level": 1078.589},
{"temp": 297.199, "temp_kf": -1.899, "temp_max": 299.0,
"temp_min": 295.6
},
"Clear", "Sky is clear", 804, "02d", 1000, 300.0, 298.0, 296.0)
]
{"all": 20}, {"all": 0}, {"deg": 252.002, "speed": 1.100}, 57,
{"press": 1030.119, "sea_level": 1038.589},
{"temp": 294.199, "temp_kf": -1.899, "temp_max": 296.098,
"temp_min": 294.199
},
"Clouds", "Overcast clouds", 804, "04d", 1000, 300.0, 298.0, 296.0),
Weather(1378459690, 1378496480, 1378449510, 23, {"all": 10},
{"all": 0}, {"deg": 103.4, "speed": 4.2}, 12,
{"press": 1070.119, "sea_level": 1078.589},
{"temp": 297.199, "temp_kf": -1.899, "temp_max": 299.0,
"temp_min": 295.6
},
"Clear", "Sky is clear", 804, "02d", 1000, 300.0, 298.0, 296.0)
]
__test_n_weathers = len(__test_weathers)
__test_instance = Forecast("daily", __test_reception_time, __test_location,
__test_weathers)
__bad_json = '{"a": "test", "b": 1.234, "c": [ "hello", "world"] }'
__bad_json_2 = '{ "city": {"id": 2643743,' \
'"name": "London","coord": {"lon": -0.12574,"lat": 51.50853},"country": ' \
'"GB","population": 1000000} }'
'"name": "London","coord": {"lon": -0.12574,"lat": 51.50853},"country": ' \
'"GB","population": 1000000} }'
__no_items_found_json = '{"count": "0", "city": {"id": 2643743,' \
'"name": "London","coord": {"lon": -0.12574,"lat": 51.50853},"country": ' \
'"GB","population": 1000000} }'
'"name": "London","coord": {"lon": -0.12574,"lat": 51.50853},"country": ' \
'"GB","population": 1000000} }'

FORECAST_JSON_DUMP = '{"reception_time": 1234567, "interval": "daily", ' \
'"location": {"country": "IT", "name": "test", ' \
Expand Down Expand Up @@ -72,21 +71,21 @@ class TestForecast(unittest.TestCase):

def test_actualize(self):
weathers = [Weather(1378459200, 1378496400, 1378449600, 67,
{"all": 20}, {"all": 0}, {"deg": 252.002, "speed": 1.100}, 57,
{"press": 1030.119, "sea_level": 1038.589},
{"temp": 294.199, "temp_kf": -1.899, "temp_max": 296.098,
"temp_min": 294.199
},
"Clouds", "Overcast clouds", 804, "04d", 1000, 300.0, 298.0, 296.0),
# will this time ever be reached?
Weather(9999999999, 1378496480, 1378449510, 23, {"all": 10},
{"all": 0}, {"deg": 103.4, "speed": 4.2}, 12,
{"press": 1070.119, "sea_level": 1078.589},
{"temp": 297.199, "temp_kf": -1.899, "temp_max": 299.0,
"temp_min": 295.6
},
"Clear", "Sky is clear", 804, "02d", 1000, 300.0, 298.0, 296.0)
]
{"all": 20}, {"all": 0}, {"deg": 252.002, "speed": 1.100}, 57,
{"press": 1030.119, "sea_level": 1038.589},
{"temp": 294.199, "temp_kf": -1.899, "temp_max": 296.098,
"temp_min": 294.199
},
"Clouds", "Overcast clouds", 804, "04d", 1000, 300.0, 298.0, 296.0),
# will this time ever be reached?
Weather(9999999999, 1378496480, 1378449510, 23, {"all": 10},
{"all": 0}, {"deg": 103.4, "speed": 4.2}, 12,
{"press": 1070.119, "sea_level": 1078.589},
{"temp": 297.199, "temp_kf": -1.899, "temp_max": 299.0,
"temp_min": 295.6
},
"Clear", "Sky is clear", 804, "02d", 1000, 300.0, 298.0, 296.0)
]
f = Forecast("daily", self.__test_reception_time, self.__test_location,
weathers)
self.assertEqual(2, len(f))
Expand All @@ -107,7 +106,7 @@ def test_getters_return_expected_3h_data(self):
Test either for "3h" forecast and "daily" ones
"""
instance = Forecast("3h", self.__test_reception_time,
self.__test_location, self.__test_weathers)
self.__test_location, self.__test_weathers)
self.assertEqual(instance.interval, "3h")
self.assertEqual(instance.reception_time(),
self.__test_reception_time)
Expand All @@ -116,7 +115,7 @@ def test_getters_return_expected_3h_data(self):

def test_getters_return_expected_daily_data(self):
instance = Forecast("daily", self.__test_reception_time,
self.__test_location, self.__test_weathers)
self.__test_location, self.__test_weathers)
self.assertEqual(instance.interval, "daily")
self.assertEqual(instance.reception_time(),
self.__test_reception_time)
Expand All @@ -139,7 +138,7 @@ def test__iter__(self):
self.assertTrue(isinstance(weather, Weather))
counter += 1
self.assertEqual(len(instance.weathers), counter)

def test__len__(self):
self.assertEqual(len(self.__test_instance), len(self.__test_weathers))

Expand Down Expand Up @@ -184,4 +183,4 @@ def test_to_dict(self):
self.assertEqual(expected, result)

def test__repr(self):
print(self.__test_instance)
print(self.__test_instance)
2 changes: 1 addition & 1 deletion tests/unit/weatherapi25/test_location.py
Expand Up @@ -115,4 +115,4 @@ def test_to_geopoint(self):
sorted(result.geojson()))

def test__repr(self):
print(self.__test_instance)
print(self.__test_instance)
2 changes: 1 addition & 1 deletion tests/unit/weatherapi25/test_observation.py
Expand Up @@ -153,4 +153,4 @@ def test_from_dict_of_lists_when_server_error(self):
Observation.from_dict_of_lists(json.loads(INTERNAL_SERVER_ERROR_JSON))

def test__repr(self):
print(self.__test_instance)
print(self.__test_instance)
2 changes: 1 addition & 1 deletion tests/unit/weatherapi25/test_stationhistory.py
Expand Up @@ -98,4 +98,4 @@ def test_to_dict(self):
self.assertEqual(expected, result)

def test__repr(self):
print(self.__test_instance)
print(self.__test_instance)
2 changes: 1 addition & 1 deletion tests/unit/weatherapi25/test_weather.py
Expand Up @@ -785,4 +785,4 @@ def test_one_call_daily_from_dic(self):
self.assertEqual(278.55, result2.temperature()["feels_like_day"])
self.assertEqual(276.84, result2.temperature()["feels_like_night"])
self.assertEqual(278.55, result2.temperature()["feels_like_eve"])
self.assertEqual(278.55, result2.temperature()["feels_like_morn"])
self.assertEqual(278.55, result2.temperature()["feels_like_morn"])
1 change: 0 additions & 1 deletion tests/unit/weatherapi25/test_weathercoderegistry.py
Expand Up @@ -36,4 +36,3 @@ def test_get_instance(self):

def test_repr(self):
print(self.__test_instance)

0 comments on commit 14f3841

Please sign in to comment.