phenny-1/modules/test/test_tfw.py

73 lines
2.2 KiB
Python
Raw Permalink Normal View History

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-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)
self.phenny.say.assert_called_once_with(
"WHERE THE FUCK IS THAT? I guess you might think it's a place, but no one else does. Try again.")
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]
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]
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')
tfw.tfwev(self.phenny, input)
2012-05-31 03:39:40 -04:00
out = self.phenny.say.call_args[0][0]
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)
2014-04-25 17:15:33 -04:00
def test_meter(self):
input = Mock(group=lambda x: '24060')
tfw.tfw(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match('^[\-\d\.]+ Meters‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE)
self.assertTrue(m)
2013-10-01 01:40:03 -04:00
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)