From 0ba6438922cb56cd40b6679cb5aab404b44aff86 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Fri, 29 Jun 2012 20:52:07 -0700 Subject: [PATCH] weather: handle bad locations better --- modules/test/test_weather.py | 20 +++++++++++++++++++- modules/weather.py | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/test/test_weather.py b/modules/test/test_weather.py index 5238387..874b087 100644 --- a/modules/test/test_weather.py +++ b/modules/test/test_weather.py @@ -26,10 +26,28 @@ class TestWeather(unittest.TestCase): self.assertEqual(icao, 'KIAD') - def test_location(self): + def test_airport(self): input = Mock( match=Mock(group=lambda x: 'KIAD'), sender='#phenny', nick='phenny_test') f_weather(self.phenny, input) assert self.phenny.msg.called is True + + def test_place(self): + input = Mock( + match=Mock(group=lambda x: 'Blacksburg'), + sender='#phenny', nick='phenny_test') + f_weather(self.phenny, input) + + assert self.phenny.msg.called is True + + def test_notfound(self): + input = Mock( + match=Mock(group=lambda x: 'Hell'), + sender='#phenny', nick='phenny_test') + f_weather(self.phenny, input) + + self.phenny.msg.called_once_with('#phenny', + "No NOAA data available for that location.") + diff --git a/modules/weather.py b/modules/weather.py index 58e0fe5..45b0afa 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -83,6 +83,10 @@ def f_weather(self, origin, match, args): try: bytes = web.get(uri % icao_code) except AttributeError: raise GrumbleError('OH CRAP NOAA HAS GONE DOWN THE WEB IS BROKEN') + except urllib.error.HTTPError: + self.msg(origin.sender, "No NOAA data available for that location.") + return + if 'Not Found' in bytes: self.msg(origin.sender, icao_code+': no such ICAO code, or no NOAA data') return