Made a SupyTestCase base class to handle COOL STUFF\!

This commit is contained in:
Jeremy Fincher 2004-02-16 04:12:35 +00:00
parent 5c660fd56e
commit 48d6c982ce
15 changed files with 35 additions and 27 deletions

View File

@ -33,7 +33,7 @@ from testsupport import *
Alias = Owner.loadPluginModule('Alias') Alias = Owner.loadPluginModule('Alias')
class FunctionsTest(unittest.TestCase): class FunctionsTest(SupyTestCase):
def testFindAliasCommand(self): def testFindAliasCommand(self):
s = 'command' s = 'command'
self.failIf(Alias.findAliasCommand(s, '')) self.failIf(Alias.findAliasCommand(s, ''))

View File

@ -40,7 +40,7 @@ except ImportError:
if sqlite is not None: if sqlite is not None:
MoobotFactoids = Owner.loadPluginModule('MoobotFactoids') MoobotFactoids = Owner.loadPluginModule('MoobotFactoids')
MF = MoobotFactoids MF = MoobotFactoids
class OptionListTestCase(unittest.TestCase): class OptionListTestCase(SupyTestCase):
def testPickOptions(self): def testPickOptions(self):
for i in xrange(10): for i in xrange(10):
self.failUnless(MF.pickOptions('(a|b)') in ['a', 'b']) self.failUnless(MF.pickOptions('(a|b)') in ['a', 'b'])

View File

@ -94,7 +94,7 @@ class OwnerTestCase(PluginTestCase, PluginDocumentation):
self.assertNotError('unload ALIAS') self.assertNotError('unload ALIAS')
class FunctionsTestCase(unittest.TestCase): class FunctionsTestCase(SupyTestCase):
def testLoadPluginModule(self): def testLoadPluginModule(self):
self.assertRaises(ImportError, Owner.loadPluginModule, 'asldj') self.assertRaises(ImportError, Owner.loadPluginModule, 'asldj')
self.failUnless(Owner.loadPluginModule('Owner')) self.failUnless(Owner.loadPluginModule('Owner'))

View File

@ -39,7 +39,7 @@ import callbacks
tokenize = callbacks.tokenize tokenize = callbacks.tokenize
class TokenizerTestCase(unittest.TestCase): class TokenizerTestCase(SupyTestCase):
def testEmpty(self): def testEmpty(self):
self.assertEqual(tokenize(''), []) self.assertEqual(tokenize(''), [])
@ -115,7 +115,7 @@ class TokenizerTestCase(unittest.TestCase):
self.assertEqual(tokenize(s), [s]) self.assertEqual(tokenize(s), [s])
class FunctionsTestCase(unittest.TestCase): class FunctionsTestCase(SupyTestCase):
def testCanonicalName(self): def testCanonicalName(self):
self.assertEqual('foo', callbacks.canonicalName('foo')) self.assertEqual('foo', callbacks.canonicalName('foo'))
self.assertEqual('foobar', callbacks.canonicalName('foo-bar')) self.assertEqual('foobar', callbacks.canonicalName('foo-bar'))

View File

@ -35,7 +35,7 @@ from testsupport import *
import itertools import itertools
class FunctionsTest(unittest.TestCase): class FunctionsTest(SupyTestCase):
def testCatch(self): def testCatch(self):
def f(): def f():
raise Exception raise Exception

View File

@ -39,14 +39,14 @@ import world
import ircdb import ircdb
import ircutils import ircutils
class IrcdbTestCase(unittest.TestCase): class IrcdbTestCase(SupyTestCase):
def setUp(self): def setUp(self):
world.testing = False world.testing = False
unittest.TestCase.setUp(self) SupyTestCase.setUp(self)
def tearDown(self): def tearDown(self):
world.testing = True world.testing = True
unittest.TestCase.tearDown(self) SupyTestCase.tearDown(self)
class FunctionsTestCase(IrcdbTestCase): class FunctionsTestCase(IrcdbTestCase):
def testIsAntiCapability(self): def testIsAntiCapability(self):
@ -91,7 +91,7 @@ class FunctionsTestCase(IrcdbTestCase):
self.assertEqual(ircdb.invertCapability('#foo,-bar'), '#foo,bar') self.assertEqual(ircdb.invertCapability('#foo,-bar'), '#foo,bar')
class CapabilitySetTestCase(unittest.TestCase): class CapabilitySetTestCase(SupyTestCase):
def testGeneral(self): def testGeneral(self):
d = ircdb.CapabilitySet() d = ircdb.CapabilitySet()
self.assertRaises(KeyError, d.check, 'foo') self.assertRaises(KeyError, d.check, 'foo')
@ -161,7 +161,7 @@ class CapabilitySetTestCase(unittest.TestCase):
self.failIf(s.check('-foo')) self.failIf(s.check('-foo'))
class UserCapabilitySetTestCase(unittest.TestCase): class UserCapabilitySetTestCase(SupyTestCase):
def testOwnerHasAll(self): def testOwnerHasAll(self):
d = ircdb.UserCapabilitySet(('owner',)) d = ircdb.UserCapabilitySet(('owner',))
self.failIf(d.check('-foo')) self.failIf(d.check('-foo'))

View File

@ -38,7 +38,7 @@ import ircmsgs
import ircutils import ircutils
class IrcMsgTestCase(unittest.TestCase): class IrcMsgTestCase(SupyTestCase):
def testLen(self): def testLen(self):
for msg in msgs: for msg in msgs:
if msg.prefix: if msg.prefix:
@ -115,7 +115,7 @@ class IrcMsgTestCase(unittest.TestCase):
self.assertRaises(ircmsgs.MalformedIrcMsg, ircmsgs.IrcMsg, self.assertRaises(ircmsgs.MalformedIrcMsg, ircmsgs.IrcMsg,
args=('biff',), prefix='foo!bar@baz') args=('biff',), prefix='foo!bar@baz')
class FunctionsTestCase(unittest.TestCase): class FunctionsTestCase(SupyTestCase):
def testIsAction(self): def testIsAction(self):
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG' L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'
' #sourcereview :ACTION does something', ' #sourcereview :ACTION does something',

View File

@ -39,7 +39,7 @@ import plugins
class holder: class holder:
users = sets.Set(map(str, range(1000))) users = sets.Set(map(str, range(1000)))
class FunctionsTestCase(unittest.TestCase): class FunctionsTestCase(SupyTestCase):
class irc: class irc:
class state: class state:
channels = {'#foo': holder()} channels = {'#foo': holder()}

View File

@ -35,7 +35,7 @@ import ircmsgs
import privmsgs import privmsgs
import callbacks import callbacks
class FunctionsTest(unittest.TestCase): class FunctionsTest(SupyTestCase):
def testGetChannel(self): def testGetChannel(self):
channel = '#foo' channel = '#foo'
msg = ircmsgs.privmsg(channel, 'foo bar baz') msg = ircmsgs.privmsg(channel, 'foo bar baz')

View File

@ -36,7 +36,7 @@ import re
import conf import conf
import registry import registry
class ValuesTestCase(unittest.TestCase): class ValuesTestCase(SupyTestCase):
def testBoolean(self): def testBoolean(self):
v = registry.Boolean(True, """Help""") v = registry.Boolean(True, """Help""")
self.failUnless(v()) self.failUnless(v())

View File

@ -35,7 +35,7 @@ import time
import schedule import schedule
class TestSchedule(unittest.TestCase): class TestSchedule(SupyTestCase):
def testSchedule(self): def testSchedule(self):
sched = schedule.Schedule() sched = schedule.Schedule()
i = [0] i = [0]

View File

@ -35,7 +35,7 @@ import pickle
from structures import * from structures import *
class RingBufferTestCase(unittest.TestCase): class RingBufferTestCase(SupyTestCase):
def testInit(self): def testInit(self):
self.assertRaises(ValueError, RingBuffer, -1) self.assertRaises(ValueError, RingBuffer, -1)
self.assertRaises(ValueError, RingBuffer, 0) self.assertRaises(ValueError, RingBuffer, 0)
@ -198,7 +198,7 @@ class RingBufferTestCase(unittest.TestCase):
self.assertEqual(L, range(3)) self.assertEqual(L, range(3))
class QueueTest(unittest.TestCase): class QueueTest(SupyTestCase):
def testReset(self): def testReset(self):
q = queue() q = queue()
q.enqueue(1) q.enqueue(1)
@ -363,7 +363,7 @@ class QueueTest(unittest.TestCase):
queue = smallqueue queue = smallqueue
class SmallQueueTest(unittest.TestCase): class SmallQueueTest(SupyTestCase):
def testReset(self): def testReset(self):
q = queue() q = queue()
q.enqueue(1) q.enqueue(1)
@ -527,7 +527,7 @@ class SmallQueueTest(unittest.TestCase):
self.assertEqual(q, pickle.loads(pickle.dumps(q))) self.assertEqual(q, pickle.loads(pickle.dumps(q)))
class MaxLengthQueueTestCase(unittest.TestCase): class MaxLengthQueueTestCase(SupyTestCase):
def testInit(self): def testInit(self):
q = MaxLengthQueue(3, (1, 2, 3)) q = MaxLengthQueue(3, (1, 2, 3))
self.assertEqual(list(q), [1, 2, 3]) self.assertEqual(list(q), [1, 2, 3])
@ -549,7 +549,7 @@ class MaxLengthQueueTestCase(unittest.TestCase):
self.assertEqual(q[0], 3) self.assertEqual(q[0], 3)
class TwoWayDictionaryTestCase(unittest.TestCase): class TwoWayDictionaryTestCase(SupyTestCase):
def testInit(self): def testInit(self):
d = TwoWayDictionary(foo='bar') d = TwoWayDictionary(foo='bar')
self.failUnless('foo' in d) self.failUnless('foo' in d)
@ -576,7 +576,7 @@ class TwoWayDictionaryTestCase(unittest.TestCase):
self.failIf('foo' in d) self.failIf('foo' in d)
class PersistentDictionaryTestCase(unittest.TestCase): class PersistentDictionaryTestCase(SupyTestCase):
def test(self): def test(self):
d = PersistentDictionary('test.dict') d = PersistentDictionary('test.dict')
d['foo'] = 'bar' d['foo'] = 'bar'

View File

@ -34,7 +34,7 @@ import sets
import utils import utils
class UtilsTest(unittest.TestCase): class UtilsTest(SupyTestCase):
def testMatchCase(self): def testMatchCase(self):
f = utils.matchCase f = utils.matchCase
self.assertEqual('bar', f('foo', 'bar')) self.assertEqual('bar', f('foo', 'bar'))

View File

@ -34,7 +34,7 @@ from testsupport import *
import webutils import webutils
class WebutilsTestCase(unittest.TestCase): class WebutilsTestCase(SupyTestCase):
def testGetDomain(self): def testGetDomain(self):
self.assertEqual(webutils.getDomain('http://slashdot.org/foo/bar.exe'), self.assertEqual(webutils.getDomain('http://slashdot.org/foo/bar.exe'),
'slashdot.org') 'slashdot.org')

View File

@ -39,6 +39,7 @@ import time
started = time.time() started = time.time()
import unittest import unittest
import log
import conf import conf
import utils import utils
import ircdb import ircdb
@ -99,7 +100,13 @@ class TimeoutError(AssertionError):
def __str__(self): def __str__(self):
return '%r timed out' % self.args[0] return '%r timed out' % self.args[0]
class PluginTestCase(unittest.TestCase):
class SupyTestCase(unittest.TestCase):
def setUp(self):
log.critical('Beginning test case %s', self.id())
unittest.TestCase.setUp(self)
class PluginTestCase(SupyTestCase):
"""Subclass this to write a test case for a plugin. See test/test_Fun.py """Subclass this to write a test case for a plugin. See test/test_Fun.py
for an example. for an example.
""" """
@ -108,10 +115,11 @@ class PluginTestCase(unittest.TestCase):
cleanConfDir = True cleanConfDir = True
cleanDataDir = True cleanDataDir = True
def setUp(self, nick='test'): def setUp(self, nick='test'):
# Set conf variables appropriately.
if self.__class__ in (PluginTestCase, ChannelPluginTestCase): if self.__class__ in (PluginTestCase, ChannelPluginTestCase):
# Necessary because there's a test in here that shouldn\'t run. # Necessary because there's a test in here that shouldn\'t run.
return return
SupyTestCase.setUp(self)
# Set conf variables appropriately.
conf.supybot.prefixChars.set('@') conf.supybot.prefixChars.set('@')
conf.supybot.reply.whenNotCommand.setValue(False) conf.supybot.reply.whenNotCommand.setValue(False)
self.myVerbose = world.myVerbose self.myVerbose = world.myVerbose