From 888854adb2a833cef964f632a98afa3d8406ef32 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Sat, 2 Jun 2012 15:06:08 -0700 Subject: [PATCH] add clock tests --- modules/test/test_clock.py | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 modules/test/test_clock.py diff --git a/modules/test/test_clock.py b/modules/test/test_clock.py new file mode 100644 index 0000000..d6038df --- /dev/null +++ b/modules/test/test_clock.py @@ -0,0 +1,77 @@ +""" +test_clock.py - tests for the clock module +author: mutantmonkey +""" + +import re +import datetime +import unittest +from mock import MagicMock, Mock, patch +from modules.clock import f_time, beats, yi, tock, npl + + +class TestClock(unittest.TestCase): + def setUp(self): + self.phenny = MagicMock() + + @patch('time.time') + def test_time(self, mock_time): + mock_time.return_value = 1338674651 + input = Mock( + match=Mock(group=lambda x: 'EDT'), + sender='#phenny', nick='phenny_test') + f_time(self.phenny, input) + + self.phenny.msg.called_once_with('#phenny', + "Sat, 02 Jun 2012 18:04:11 EDT") + + @patch('time.time') + def test_beats_zero(self, mock_time): + mock_time.return_value = 0 + beats(self.phenny, None) + + self.phenny.say.assert_called_with('@041') + + @patch('time.time') + def test_beats_normal(self, mock_time): + mock_time.return_value = 369182 + beats(self.phenny, None) + + self.phenny.say.assert_called_with('@314') + + @patch('time.time') + def test_yi_normal(self, mock_time): + mock_time.return_value = 369182 + yi(self.phenny, None) + + self.phenny.say.assert_called_with('Not yet...') + + @patch('time.time') + def test_yi_soon(self, mock_time): + mock_time.return_value = 1339419000 + yi(self.phenny, None) + + self.phenny.say.assert_called_with('Soon...') + + @patch('time.time') + def test_yi_now(self, mock_time): + mock_time.return_value = 1339419650 + yi(self.phenny, None) + + self.phenny.say.assert_called_with('Yes! PARTAI!') + + def test_tock(self): + tock(self.phenny, None) + + out = self.phenny.say.call_args[0][0] + m = re.match('^.* - tycho.usno.navy.mil$', + out, flags=re.UNICODE) + self.assertTrue(m) + + def test_npl(self): + npl(self.phenny, None) + + out = self.phenny.say.call_args[0][0] + m = re.match('^.* - ntp1.npl.co.uk$', + out, flags=re.UNICODE) + self.assertTrue(m)