2012-06-02 06:08:29 -04:00
|
|
|
"""
|
|
|
|
test_weather.py - tests for the weather module
|
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import unittest
|
|
|
|
from mock import MagicMock, Mock, patch
|
|
|
|
from modules.weather import location, local, code, f_weather
|
|
|
|
|
|
|
|
|
|
|
|
class TestWeather(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.phenny = MagicMock()
|
|
|
|
|
2013-08-24 21:45:05 -04:00
|
|
|
def test_locations(self):
|
|
|
|
def check_places(*args):
|
|
|
|
def validate(actual_name, actual_lat, actual_lon):
|
|
|
|
names = [n.strip() for n in actual_name.split(',')]
|
|
|
|
for arg in args:
|
|
|
|
self.assertIn(arg, names)
|
|
|
|
return validate
|
2012-06-02 06:08:29 -04:00
|
|
|
|
2013-08-24 21:45:05 -04:00
|
|
|
locations = [
|
|
|
|
('92121', check_places("San Diego", "California")),
|
|
|
|
('94110', check_places("San Francisco", "California")),
|
|
|
|
('94041', check_places("Mountain View", "California")),
|
|
|
|
('27959', check_places("Nags Head", "North Carolina")),
|
|
|
|
('48067', check_places("Royal Oak", "Michigan")),
|
|
|
|
('23606', check_places("Newport News", "Virginia")),
|
|
|
|
('23113', check_places("Midlothian", "Virginia")),
|
|
|
|
('27517', check_places("Chapel Hill", "North Carolina")),
|
|
|
|
('46530', check_places("Granger", "Indiana")),
|
|
|
|
('15213', check_places("Pittsburgh", "Pennsylvania")),
|
|
|
|
('90210', check_places("Beverly Hills", "California")),
|
|
|
|
('12144', check_places("Clinton Park", "New York")),
|
|
|
|
('33109', check_places("Homestead", "Florida")),
|
|
|
|
('80201', check_places("Denver", "Colorado")),
|
2012-06-02 06:08:29 -04:00
|
|
|
|
2013-08-24 21:45:05 -04:00
|
|
|
("Berlin", check_places("Berlin", "Deutschland")),
|
2013-11-02 01:10:12 -04:00
|
|
|
("Paris", check_places("Paris", "France métropolitaine")),
|
|
|
|
("Vilnius", check_places("Vilnius", "Lietuva")),
|
2016-03-06 17:40:11 -05:00
|
|
|
|
|
|
|
('Blacksburg, VA', check_places("Blacksburg", "Virginia")),
|
2013-08-24 21:45:05 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
for loc, validator in locations:
|
|
|
|
names, lat, lon = location(loc)
|
|
|
|
validator(names, lat, lon)
|
|
|
|
|
2016-03-06 17:40:11 -05:00
|
|
|
def test_code_94110(self):
|
|
|
|
icao = code(self.phenny, '94110')
|
|
|
|
self.assertEqual(icao, 'KSFO')
|
2012-06-02 06:08:29 -04:00
|
|
|
|
2012-06-29 23:52:07 -04:00
|
|
|
def test_airport(self):
|
2013-01-10 20:24:17 -05:00
|
|
|
input = Mock(group=lambda x: 'KIAD')
|
2012-06-02 06:08:29 -04:00
|
|
|
f_weather(self.phenny, input)
|
|
|
|
|
2013-01-10 20:24:17 -05:00
|
|
|
assert self.phenny.say.called is True
|
2012-06-29 23:52:07 -04:00
|
|
|
|
|
|
|
def test_place(self):
|
2013-01-10 20:24:17 -05:00
|
|
|
input = Mock(group=lambda x: 'Blacksburg')
|
2012-06-29 23:52:07 -04:00
|
|
|
f_weather(self.phenny, input)
|
|
|
|
|
2013-01-10 20:24:17 -05:00
|
|
|
assert self.phenny.say.called is True
|
2012-06-29 23:52:07 -04:00
|
|
|
|
|
|
|
def test_notfound(self):
|
2013-01-10 20:24:17 -05:00
|
|
|
input = Mock(group=lambda x: 'Hell')
|
2012-06-29 23:52:07 -04:00
|
|
|
f_weather(self.phenny, input)
|
|
|
|
|
2013-01-10 20:24:17 -05:00
|
|
|
self.phenny.say.called_once_with('#phenny',
|
2012-06-29 23:52:07 -04:00
|
|
|
"No NOAA data available for that location.")
|