2013-10-01 01:40:03 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-05-31 03:39:40 -04:00
|
|
|
"""
|
|
|
|
test_tfw.py - tests for the fucking weather module
|
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import unittest
|
2012-06-05 00:42:56 -04:00
|
|
|
import tools
|
2012-05-31 03:39:40 -04:00
|
|
|
from mock import MagicMock, Mock
|
2013-10-01 01:40:03 -04:00
|
|
|
from modules import tfw
|
2012-05-31 03:39:40 -04:00
|
|
|
|
2012-06-01 03:13:57 -04:00
|
|
|
|
2012-05-31 03:39:40 -04:00
|
|
|
class TestTfw(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.phenny = MagicMock()
|
|
|
|
|
2012-06-05 00:42:56 -04:00
|
|
|
def test_badloc(self):
|
|
|
|
input = Mock(group=lambda x: 'tu3jgoajgoahghqog')
|
2013-10-01 01:40:03 -04:00
|
|
|
tfw.tfw(self.phenny, input)
|
|
|
|
|
2013-01-10 22:08:52 -05:00
|
|
|
self.phenny.say.assert_called_once_with(
|
2013-10-01 01:40:03 -04:00
|
|
|
"WHERE THE FUCK IS THAT? Try another location.")
|
2012-05-31 03:39:40 -04:00
|
|
|
|
|
|
|
def test_celsius(self):
|
|
|
|
input = Mock(group=lambda x: '24060')
|
2013-10-01 01:40:03 -04:00
|
|
|
tfw.tfw(self.phenny, input, celsius=True)
|
2012-05-31 03:39:40 -04:00
|
|
|
|
|
|
|
out = self.phenny.say.call_args[0][0]
|
2013-01-10 22:08:52 -05:00
|
|
|
m = re.match('^\d+°C‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
|
2013-10-01 01:40:03 -04:00
|
|
|
flags=re.UNICODE)
|
2012-05-31 03:39:40 -04:00
|
|
|
self.assertTrue(m)
|
|
|
|
|
|
|
|
def test_fahrenheit(self):
|
|
|
|
input = Mock(group=lambda x: '24060')
|
2013-10-01 01:40:03 -04:00
|
|
|
tfw.tfw(self.phenny, input, fahrenheit=True)
|
2012-05-31 03:39:40 -04:00
|
|
|
|
|
|
|
out = self.phenny.say.call_args[0][0]
|
2013-01-10 22:08:52 -05:00
|
|
|
m = re.match('^\d+°F‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
|
2013-10-01 01:40:03 -04:00
|
|
|
flags=re.UNICODE)
|
2012-05-31 03:39:40 -04:00
|
|
|
self.assertTrue(m)
|
|
|
|
|
|
|
|
def test_mev(self):
|
|
|
|
input = Mock(group=lambda x: '24060')
|
2013-10-01 01:40:03 -04:00
|
|
|
tfw.tfw(self.phenny, input)
|
2012-05-31 03:39:40 -04:00
|
|
|
|
|
|
|
out = self.phenny.say.call_args[0][0]
|
2013-01-10 22:08:52 -05:00
|
|
|
m = re.match('^[\d\.]+ meV‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
|
2013-10-01 01:40:03 -04:00
|
|
|
flags=re.UNICODE)
|
|
|
|
self.assertTrue(m)
|
|
|
|
|
|
|
|
def test_sexy_time(self):
|
|
|
|
input = Mock(group=lambda x: 'KBCB')
|
|
|
|
tfw.web = MagicMock()
|
|
|
|
tfw.metar.parse = lambda x: Mock(temperature=21)
|
|
|
|
tfw.tfwf(self.phenny, input)
|
|
|
|
|
|
|
|
out = self.phenny.say.call_args[0][0]
|
|
|
|
m = re.match(
|
|
|
|
r'^69°F‽ IT\'S FUCKING SEXY TIME \- .*',
|
|
|
|
out,
|
|
|
|
flags=re.UNICODE)
|
2012-05-31 03:39:40 -04:00
|
|
|
self.assertTrue(m)
|