rename tests to test

This commit is contained in:
mutantmonkey
2012-05-30 23:39:23 -07:00
parent 1f9a35b699
commit 183609fdd1
2 changed files with 0 additions and 0 deletions

82
test/test_bot.py Normal file
View File

@@ -0,0 +1,82 @@
"""
Tests for phenny's bot.py
"""
# add current working directory to path
import sys
sys.path.append('.')
import unittest
from mock import call, patch, Mock
import bot
class BotTest(unittest.TestCase):
@patch('bot.Phenny.setup')
def setUp(self, mock_setup):
class MockConfig(object):
nick = 'phenny'
password = 'nickserv_pass'
name = 'Phenny'
host = 'irc.example.com'
port = 6667
ssl = False
ipv6 = True
channels = ['#phenny']
owner = 'phenny_owner'
admins = [owner, 'phenny_admin']
prefix = '.'
self.bot = bot.Phenny(MockConfig)
def test_input(self):
class MockOrigin(object):
nick = 'sock_puppet'
sender = '#phenny'
origin = MockOrigin()
text = "Are you ready for phenny?"
match = Mock()
event = "PRIVMSG"
args = ('#phenny', )
cmdinput = self.bot.input(origin, text, text, match, event, args)
self.assertEqual(cmdinput.sender, origin.sender)
self.assertEqual(cmdinput.nick, origin.nick)
self.assertEqual(cmdinput.event, event)
self.assertEqual(cmdinput.bytes, text)
self.assertEqual(cmdinput.match, match)
self.assertEqual(cmdinput.group, match.group)
self.assertEqual(cmdinput.groups, match.groups)
self.assertEqual(cmdinput.args, args)
self.assertEqual(cmdinput.admin, False)
self.assertEqual(cmdinput.owner, False)
def test_owner(self):
class MockOrigin(object):
nick = 'phenny_owner'
sender = '#phenny'
origin = MockOrigin()
text = "Are you ready for phenny?"
match = Mock()
event = "PRIVMSG"
args = ('#phenny', )
cmdinput = self.bot.input(origin, text, text, match, event, args)
self.assertEqual(cmdinput.owner, True)
def test_admin(self):
class MockOrigin(object):
nick = 'phenny_admin'
sender = '#phenny'
origin = MockOrigin()
text = "Are you ready for phenny?"
match = Mock()
event = "PRIVMSG"
args = ('#phenny', )
cmdinput = self.bot.input(origin, text, text, match, event, args)
self.assertEqual(cmdinput.admin, True)

90
test/test_irc.py Normal file
View File

@@ -0,0 +1,90 @@
"""
Tests for phenny's irc.py
"""
# add current working directory to path
import sys
sys.path.append('.')
import unittest
from mock import call, patch, Mock
import irc
class OriginTest(unittest.TestCase):
def setUp(self):
self.bot = Mock()
def test_server(self):
source = "foobar.example.com"
origin = irc.Origin(self.bot, source, [])
self.assertEqual(origin.host, '')
def test_privmsg(self):
source = "Foobar!foo@bar.example.com"
args = ['PRIVMSG', '#phenny']
origin = irc.Origin(self.bot, source, args)
self.assertEqual(origin.nick, 'Foobar')
self.assertEqual(origin.user, 'foo')
self.assertEqual(origin.host, 'bar.example.com')
self.assertEqual(origin.sender, '#phenny')
class BotTest(unittest.TestCase):
@patch('threading.RLock')
@patch('asynchat.async_chat')
def setUp(self, mock_async, mock_thread):
self.nick = 'foo'
self.name = 'Phenny'
self.bot = irc.Bot(self.nick, self.name, '#phenny')
@patch('irc.Bot.write')
def test_login(self, mock_write):
self.bot.verbose = False
self.bot.handle_connect()
mock_write.assert_has_calls([
call(('NICK', self.nick)),
call(('USER', self.nick, '+iw', self.nick), self.name)
])
@patch('irc.Bot.write')
def test_ping(self, mock_write):
self.bot.buffer = b"PING"
self.bot.found_terminator()
mock_write.assert_called_once_with(('PONG', ''))
@patch('irc.Bot.push')
def test_msg(self, mock_push):
self.bot.msg('#phenny', 'hi')
mock_push.assert_called_once_with(b'PRIVMSG #phenny :hi\r\n')
@patch('time.sleep') # patch sleep so test runs faster
@patch('irc.Bot.push')
def test_msgflood(self, mock_push, mock_sleep):
self.bot.msg('#phenny', 'flood')
self.bot.msg('#phenny', 'flood')
self.bot.msg('#phenny', 'flood')
self.bot.msg('#phenny', 'flood')
self.bot.msg('#phenny', 'flood')
self.bot.msg('#phenny', 'flood')
mock_push.assert_called_with(b'PRIVMSG #phenny :...\r\n')
self.assertEqual(mock_sleep.call_count, 5)
@patch('irc.Bot.msg')
def test_action(self, mock_msg):
self.bot.action('foo', 'is')
mock_msg.assert_called_once_with('foo', '\x01ACTION is\x01')
@patch('irc.Bot.write')
def test_notice(self, mock_write):
notice = "This is a notice!"
self.bot.notice('jqh', notice)
mock_write.assert_called_once_with(('NOTICE', 'jqh'), notice)