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_forecast_iterator(self):
instance = self.__test_instance
counter = 0
for weather in instance:
self.assertTrue(isinstance(weather, Weather))
counter += 1
self.assertEqual(instance.count_weathers(), counter)
def test_weather_history_at_id(self):
original_func = HttpClient.cacheable_get_json
HttpClient.cacheable_get_json = \
self.mock_api_call_returning_city_weather_history
result = self.__test_instance.weather_history_at_id(12345)
HttpClient.cacheable_get_json = original_func
self.assertTrue(isinstance(result, list))
for weather in result:
self.assertTrue(isinstance(weather, Weather))
from pyowm.webapi25.station import Station
from pyowm.webapi25.weather import Weather
from tests.unit.webapi25.json_test_dumps import STATION_JSON_DUMP
from tests.unit.webapi25.xml_test_dumps import STATION_XML_DUMP
class TestStation(unittest.TestCase):
__test_name = 'KNGU'
__test_station_type = 1
__test_status = 50
__test_station_ID = 2865
__test_lat = 36.9375
__test_lon = -76.2893
__test_distance = 18.95
__test_last_weather_instance = 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)
__test_instance = Station(__test_name, __test_station_ID,
__test_station_type, __test_status, __test_lat,
__test_lon, __test_distance,
__test_last_weather_instance)
def test_init_fails_with_invalid_coords(self):
self.assertRaises(ValueError, Station, self.__test_name,
self.__test_station_ID, self.__test_station_type,
self.__test_status, 120.0, self.__test_lon,
self.__test_distance,
self.__test_last_weather_instance)
def test_snippets(self):
# Will it be clear tomorrow at this time in Milan (Italy) ?
f_milan = self.__owm.daily_forecast("Milan,it")
self.assertIsNotNone(f_milan)
self.assertTrue(isinstance(f_milan, Forecaster))
tomorrow = timeutils.tomorrow()
will_be_clear = f_milan.will_be_clear_at(tomorrow)
self.assertTrue(isinstance(will_be_clear, bool))
# Search for current weather in London (UK)
o_london = self.__owm.weather_at_place('London,uk')
self.assertTrue(isinstance(o_london, Observation))
w_london = o_london.get_weather()
self.assertTrue(isinstance(w_london, Weather))
# Weather details
self.assertIsNotNone(w_london.get_wind())
self.assertIsNotNone(w_london.get_humidity())
self.assertIsNotNone(w_london.get_temperature('celsius'))
# Search current weather observations in the surroundings of
# lat=22.57W, lon=43.12S (Rio de Janeiro, BR)
os_rio = self.__owm.weather_around_coords(-22.57, -43.12)
self.assertIsNotNone(os_rio)
self.assertTrue(len(os_rio) > 0)
for o in os_rio:
self.assertTrue(isinstance(o, Observation))
'%Y-%m-%d %H:%M:%S+00').replace(tzinfo=UTC())
__test_end_coverage = 1379902600
__test_end_coverage_iso = "2013-09-23 02:16:40+00"
__test_date_end_coverage = datetime.strptime(__test_end_coverage_iso,
'%Y-%m-%d %H:%M:%S+00').replace(tzinfo=UTC())
__test_location = Location('test', 12.3, 43.7, 987, 'IT')
__test_weather_rainsnow = Weather(__test_time_1, 1378496400, 1378449600,
67, {"all": 30}, {"all": 1}, {"deg": 252.002, "speed": 4.100},
57, {"press": 1030.119, "sea_level": 1038.589},
{"temp": 294.199, "temp_kf": -1.899, "temp_max": 296.098,
"temp_min": 294.199
},
"Rain", "Light rain", 500, "10d", 1000, 300.0, 298.0, 296.0)
__test_weather_clouds = Weather(__test_middle_1_coverage, 1378496480,
1378449510, 23,
{"all": 0}, {}, {"deg": 103.4, "speed": 1.2}, 12,
{"press": 1070.119, "sea_level": 1078.589},
{"temp": 297.199, "temp_kf": -1.899, "temp_max": 299.0,
"temp_min": 295.6
},
"Clouds", "Overcast clouds", 804, "02d", 1000, 300.0, 298.0, 296.0)
__test_weather_sun_1 = Weather(__test_time_2, 1378496480, 1378449510, 5,
{"all": 0}, {}, {"deg": 103.4, "speed": 1.2}, 12,
{"press": 1090.119, "sea_level": 1078.589},
{"temp": 299.199, "temp_kf": -1.899, "temp_max": 301.0,
"temp_min": 297.6
},
"Clear", "Sky is clear", 800, "01d", 1000, 300.0, 298.0, 296.0)
__test_weather_sun_2 = Weather(__test_end_coverage, 1378496480, 1378449510,
5,
def test_weather_history_at_coords(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_weather_history_at_coords
result = self.__test_instance.weather_history_at_coords(51.503614, -0.107331)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, list))
for weather in result:
self.assertTrue(isinstance(weather, Weather))
temperature = {}
if 'weather' in d:
status = d['weather'][0]['main'].lower() #Sometimes provided with a leading upper case!
detailed_status = d['weather'][0]['description'].lower()
weather_code = d['weather'][0]['id']
weather_icon_name = d['weather'][0]['icon']
else:
status = u''
detailed_status = u''
weather_code = 0
weather_icon_name = u''
except KeyError:
raise ParseResponseError(''.join([__name__,': impossible to read ' \
'weather info from JSON data', linesep, str(d)]))
else:
return Weather(reference_time, sunset_time, sunrise_time, clouds,
rain, snow, wind, humidity, pressure, temperature,
status, detailed_status, weather_code,
weather_icon_name)
def _to_DOM(self):
"""
Dumps object data to a fully traversable DOM representation of the
object.
:returns: a ``xml.etree.Element`` object
"""
last_weather = None
if (self._last_weather
and isinstance(self._last_weather, weather.Weather)):
last_weather = self._last_weather._to_DOM()
root_node = ET.Element('station')
station_name_node = ET.SubElement(root_node, 'name')
station_name_node.text = str(self._name)
station_id_node = ET.SubElement(root_node, 'station_id')
station_id_node.text = str(self._station_ID)
station_type_node = ET.SubElement(root_node, 'station_type')
station_type_node.text = str(self._station_type)
status_node = ET.SubElement(root_node, 'status')
status_node.text = str(self._status)
coords_node = ET.SubElement(root_node, 'coords')
lat_node = ET.SubElement(coords_node, 'lat')
lat_node.text = str(self._lat)
lon_node = ET.SubElement(coords_node, 'lon')
lon_node.text = str(self._lon)