phenny-1/modules/test/test_weather.py

69 lines
2.0 KiB
Python
Raw Normal View History

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 import weather
2012-06-02 06:08:29 -04:00
class TestWeather(unittest.TestCase):
def setUp(self):
self.phenny = MagicMock()
def test_locations(self):
def check_location(result, expected):
self.assertAlmostEqual(result[0], expected[0], places=1)
self.assertAlmostEqual(result[1], expected[1], places=1)
2012-06-02 06:08:29 -04:00
locations = [
('92121', (32.9, -117.2)),
('94110', (37.8, -122.4)),
('94041', (37.4, -122.1)),
('27959', (36.0, -75.6)),
('48067', (42.5, -83.1)),
('23606', (37.1, -76.5)),
('23113', (37.5, -77.6)),
2018-07-30 22:57:53 -04:00
('27517', (42.6, -7.8)),
('15213', (40.4, -80.0)),
2018-07-30 22:57:53 -04:00
('90210', (34.1, -118.3)),
('33109', (25.8, -80.1)),
('80201', (22.6, 120.3)),
2012-06-02 06:08:29 -04:00
("Berlin", (52.5, 13.4)),
("Paris", (48.9, 2.4)),
("Vilnius", (54.7, 25.3)),
2016-03-06 17:40:11 -05:00
('Blacksburg, VA', (37.2, -80.4)),
('Granger, IN', (41.8, -86.1)),
]
for query, expected in locations:
result = weather.location(query)
check_location(result, expected)
2016-03-06 17:40:11 -05:00
def test_code_94110(self):
icao = weather.code(self.phenny, '94110')
2016-03-06 17:40:11 -05:00
self.assertEqual(icao, 'KSFO')
2012-06-02 06:08:29 -04:00
2012-06-29 23:52:07 -04:00
def test_airport(self):
input = Mock(group=lambda x: 'KIAD')
weather.f_weather(self.phenny, input)
2012-06-02 06:08:29 -04:00
assert self.phenny.say.called is True
2012-06-29 23:52:07 -04:00
def test_place(self):
input = Mock(group=lambda x: 'Blacksburg')
weather.f_weather(self.phenny, input)
2012-06-29 23:52:07 -04:00
assert self.phenny.say.called is True
2012-06-29 23:52:07 -04:00
def test_notfound(self):
input = Mock(group=lambda x: 'Hell')
weather.f_weather(self.phenny, input)
2012-06-29 23:52:07 -04:00
self.phenny.say.called_once_with('#phenny',
2012-06-29 23:52:07 -04:00
"No NOAA data available for that location.")