tfw: tests and retry on first failure
parent
183609fdd1
commit
546b3113d5
|
@ -0,0 +1,47 @@
|
||||||
|
"""
|
||||||
|
test_tfw.py - tests for the fucking weather module
|
||||||
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
||||||
|
"""
|
||||||
|
|
||||||
|
# add current working directory to path
|
||||||
|
import sys
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import re
|
||||||
|
import unittest
|
||||||
|
from mock import MagicMock, Mock
|
||||||
|
from modules.tfw import tfw
|
||||||
|
|
||||||
|
class TestTfw(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.phenny = MagicMock()
|
||||||
|
|
||||||
|
#def test_badloc(self):
|
||||||
|
# input = Mock(group=lambda x: 'tu3jgoajgoahghqog')
|
||||||
|
# tfw(self.phenny, input)
|
||||||
|
#
|
||||||
|
# self.phenny.say.assert_called_once_with("UNKNOWN FUCKING LOCATION. Try another?")
|
||||||
|
|
||||||
|
def test_celsius(self):
|
||||||
|
input = Mock(group=lambda x: '24060')
|
||||||
|
tfw(self.phenny, input, celsius=True)
|
||||||
|
|
||||||
|
out = self.phenny.say.call_args[0][0]
|
||||||
|
m = re.match('^\d+°C‽ .* \- .*$', out, flags=re.UNICODE)
|
||||||
|
self.assertTrue(m)
|
||||||
|
|
||||||
|
def test_fahrenheit(self):
|
||||||
|
input = Mock(group=lambda x: '24060')
|
||||||
|
tfw(self.phenny, input, fahrenheit=True)
|
||||||
|
|
||||||
|
out = self.phenny.say.call_args[0][0]
|
||||||
|
m = re.match('^\d+°F‽ .* \- .*$', out, flags=re.UNICODE)
|
||||||
|
self.assertTrue(m)
|
||||||
|
|
||||||
|
def test_mev(self):
|
||||||
|
input = Mock(group=lambda x: '24060')
|
||||||
|
tfw(self.phenny, input)
|
||||||
|
|
||||||
|
out = self.phenny.say.call_args[0][0]
|
||||||
|
m = re.match('^[\d\.]+ meV‽ .* \- .*$', out, flags=re.UNICODE)
|
||||||
|
self.assertTrue(m)
|
|
@ -27,8 +27,12 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
|
||||||
try:
|
try:
|
||||||
req = web.get("http://thefuckingweather.com/?where={0}{1}".format(urlquote(where), celsius_param))
|
req = web.get("http://thefuckingweather.com/?where={0}{1}".format(urlquote(where), celsius_param))
|
||||||
except (HTTPError, IOError):
|
except (HTTPError, IOError):
|
||||||
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
# the fucking weather is fucking unstable, try again
|
||||||
return
|
try:
|
||||||
|
req = web.get("http://thefuckingweather.com/?where={0}{1}".format(urlquote(where), celsius_param))
|
||||||
|
except (HTTPError, IOError):
|
||||||
|
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
||||||
|
return
|
||||||
|
|
||||||
doc = lxml.html.fromstring(req)
|
doc = lxml.html.fromstring(req)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue