Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 321e039a62
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (65 sloc) 2.518 kb
Tests for phenny's
import unittest
from mock import call, patch, Mock
import irc
class OriginTest(unittest.TestCase):
def setUp(self): = Mock()
def test_server(self):
source = ""
origin = irc.Origin(, source, [])
self.assertEqual(, '')
def test_privmsg(self):
source = "Foobar!"
args = ['PRIVMSG', '#phenny']
origin = irc.Origin(, source, args)
self.assertEqual(origin.nick, 'Foobar')
self.assertEqual(origin.user, 'foo')
self.assertEqual(, '')
self.assertEqual(origin.sender, '#phenny')
class BotTest(unittest.TestCase):
def setUp(self, mock_async, mock_thread):
self.nick = 'foo' = 'Phenny' = irc.Bot(self.nick,, '#phenny')
def test_login(self, mock_write): = False
call(('NICK', self.nick)),
call(('USER', self.nick, '+iw', self.nick),
def test_ping(self, mock_write): = b"PING"
mock_write.assert_called_once_with(('PONG', ''))
def test_msg(self, mock_push):'#phenny', 'hi')
mock_push.assert_called_once_with(b'PRIVMSG #phenny :hi\r\n')
@patch('time.sleep') # patch sleep so test runs faster
def test_msgflood(self, mock_push, mock_sleep):'#phenny', 'flood')'#phenny', 'flood')'#phenny', 'flood')'#phenny', 'flood')'#phenny', 'flood')'#phenny', 'flood')
mock_push.assert_called_with(b'PRIVMSG #phenny :...\r\n')
self.assertEqual(mock_sleep.call_count, 5)
def test_action(self, mock_msg):'foo', 'is')
mock_msg.assert_called_once_with('foo', '\x01ACTION is\x01')
def test_notice(self, mock_write):
notice = "This is a notice!"'jqh', notice)
mock_write.assert_called_once_with(('NOTICE', 'jqh'), notice)
Jump to Line
Something went wrong with that request. Please try again.