From 48d6c982ceda0a5ef06c350208f871a70a6240e5 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 16 Feb 2004 04:12:35 +0000 Subject: [PATCH] Made a SupyTestCase base class to handle COOL STUFF\! --- test/test_Alias.py | 2 +- test/test_MoobotFactoids.py | 2 +- test/test_Owner.py | 2 +- test/test_callbacks.py | 4 ++-- test/test_fix.py | 2 +- test/test_ircdb.py | 10 +++++----- test/test_ircmsgs.py | 4 ++-- test/test_plugins.py | 2 +- test/test_privmsgs.py | 2 +- test/test_registry.py | 2 +- test/test_schedule.py | 2 +- test/test_structures.py | 12 ++++++------ test/test_utils.py | 2 +- test/test_webutils.py | 2 +- test/testsupport.py | 12 ++++++++++-- 15 files changed, 35 insertions(+), 27 deletions(-) diff --git a/test/test_Alias.py b/test/test_Alias.py index 20b0ac5e4..69972d439 100644 --- a/test/test_Alias.py +++ b/test/test_Alias.py @@ -33,7 +33,7 @@ from testsupport import * Alias = Owner.loadPluginModule('Alias') -class FunctionsTest(unittest.TestCase): +class FunctionsTest(SupyTestCase): def testFindAliasCommand(self): s = 'command' self.failIf(Alias.findAliasCommand(s, '')) diff --git a/test/test_MoobotFactoids.py b/test/test_MoobotFactoids.py index bc893df64..d8296b099 100644 --- a/test/test_MoobotFactoids.py +++ b/test/test_MoobotFactoids.py @@ -40,7 +40,7 @@ except ImportError: if sqlite is not None: MoobotFactoids = Owner.loadPluginModule('MoobotFactoids') MF = MoobotFactoids - class OptionListTestCase(unittest.TestCase): + class OptionListTestCase(SupyTestCase): def testPickOptions(self): for i in xrange(10): self.failUnless(MF.pickOptions('(a|b)') in ['a', 'b']) diff --git a/test/test_Owner.py b/test/test_Owner.py index aa4315ad3..1e6fd4b24 100644 --- a/test/test_Owner.py +++ b/test/test_Owner.py @@ -94,7 +94,7 @@ class OwnerTestCase(PluginTestCase, PluginDocumentation): self.assertNotError('unload ALIAS') -class FunctionsTestCase(unittest.TestCase): +class FunctionsTestCase(SupyTestCase): def testLoadPluginModule(self): self.assertRaises(ImportError, Owner.loadPluginModule, 'asldj') self.failUnless(Owner.loadPluginModule('Owner')) diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 84ff948ab..dd5f399c2 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -39,7 +39,7 @@ import callbacks tokenize = callbacks.tokenize -class TokenizerTestCase(unittest.TestCase): +class TokenizerTestCase(SupyTestCase): def testEmpty(self): self.assertEqual(tokenize(''), []) @@ -115,7 +115,7 @@ class TokenizerTestCase(unittest.TestCase): self.assertEqual(tokenize(s), [s]) -class FunctionsTestCase(unittest.TestCase): +class FunctionsTestCase(SupyTestCase): def testCanonicalName(self): self.assertEqual('foo', callbacks.canonicalName('foo')) self.assertEqual('foobar', callbacks.canonicalName('foo-bar')) diff --git a/test/test_fix.py b/test/test_fix.py index 380b0270d..1e16a7afc 100644 --- a/test/test_fix.py +++ b/test/test_fix.py @@ -35,7 +35,7 @@ from testsupport import * import itertools -class FunctionsTest(unittest.TestCase): +class FunctionsTest(SupyTestCase): def testCatch(self): def f(): raise Exception diff --git a/test/test_ircdb.py b/test/test_ircdb.py index 574311a18..2c9c8f07b 100644 --- a/test/test_ircdb.py +++ b/test/test_ircdb.py @@ -39,14 +39,14 @@ import world import ircdb import ircutils -class IrcdbTestCase(unittest.TestCase): +class IrcdbTestCase(SupyTestCase): def setUp(self): world.testing = False - unittest.TestCase.setUp(self) + SupyTestCase.setUp(self) def tearDown(self): world.testing = True - unittest.TestCase.tearDown(self) + SupyTestCase.tearDown(self) class FunctionsTestCase(IrcdbTestCase): def testIsAntiCapability(self): @@ -91,7 +91,7 @@ class FunctionsTestCase(IrcdbTestCase): self.assertEqual(ircdb.invertCapability('#foo,-bar'), '#foo,bar') -class CapabilitySetTestCase(unittest.TestCase): +class CapabilitySetTestCase(SupyTestCase): def testGeneral(self): d = ircdb.CapabilitySet() self.assertRaises(KeyError, d.check, 'foo') @@ -161,7 +161,7 @@ class CapabilitySetTestCase(unittest.TestCase): self.failIf(s.check('-foo')) -class UserCapabilitySetTestCase(unittest.TestCase): +class UserCapabilitySetTestCase(SupyTestCase): def testOwnerHasAll(self): d = ircdb.UserCapabilitySet(('owner',)) self.failIf(d.check('-foo')) diff --git a/test/test_ircmsgs.py b/test/test_ircmsgs.py index a1d389e34..d4d34dd4b 100644 --- a/test/test_ircmsgs.py +++ b/test/test_ircmsgs.py @@ -38,7 +38,7 @@ import ircmsgs import ircutils -class IrcMsgTestCase(unittest.TestCase): +class IrcMsgTestCase(SupyTestCase): def testLen(self): for msg in msgs: if msg.prefix: @@ -115,7 +115,7 @@ class IrcMsgTestCase(unittest.TestCase): self.assertRaises(ircmsgs.MalformedIrcMsg, ircmsgs.IrcMsg, args=('biff',), prefix='foo!bar@baz') -class FunctionsTestCase(unittest.TestCase): +class FunctionsTestCase(SupyTestCase): def testIsAction(self): L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG' ' #sourcereview :ACTION does something', diff --git a/test/test_plugins.py b/test/test_plugins.py index e4202f4ec..1458b0c0b 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -39,7 +39,7 @@ import plugins class holder: users = sets.Set(map(str, range(1000))) -class FunctionsTestCase(unittest.TestCase): +class FunctionsTestCase(SupyTestCase): class irc: class state: channels = {'#foo': holder()} diff --git a/test/test_privmsgs.py b/test/test_privmsgs.py index d52004b59..e45ee92da 100644 --- a/test/test_privmsgs.py +++ b/test/test_privmsgs.py @@ -35,7 +35,7 @@ import ircmsgs import privmsgs import callbacks -class FunctionsTest(unittest.TestCase): +class FunctionsTest(SupyTestCase): def testGetChannel(self): channel = '#foo' msg = ircmsgs.privmsg(channel, 'foo bar baz') diff --git a/test/test_registry.py b/test/test_registry.py index ce23fa9a1..3c7b6b612 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -36,7 +36,7 @@ import re import conf import registry -class ValuesTestCase(unittest.TestCase): +class ValuesTestCase(SupyTestCase): def testBoolean(self): v = registry.Boolean(True, """Help""") self.failUnless(v()) diff --git a/test/test_schedule.py b/test/test_schedule.py index 53b89b32b..f5010570c 100644 --- a/test/test_schedule.py +++ b/test/test_schedule.py @@ -35,7 +35,7 @@ import time import schedule -class TestSchedule(unittest.TestCase): +class TestSchedule(SupyTestCase): def testSchedule(self): sched = schedule.Schedule() i = [0] diff --git a/test/test_structures.py b/test/test_structures.py index c5439f68f..a6fa86bf8 100644 --- a/test/test_structures.py +++ b/test/test_structures.py @@ -35,7 +35,7 @@ import pickle from structures import * -class RingBufferTestCase(unittest.TestCase): +class RingBufferTestCase(SupyTestCase): def testInit(self): self.assertRaises(ValueError, RingBuffer, -1) self.assertRaises(ValueError, RingBuffer, 0) @@ -198,7 +198,7 @@ class RingBufferTestCase(unittest.TestCase): self.assertEqual(L, range(3)) -class QueueTest(unittest.TestCase): +class QueueTest(SupyTestCase): def testReset(self): q = queue() q.enqueue(1) @@ -363,7 +363,7 @@ class QueueTest(unittest.TestCase): queue = smallqueue -class SmallQueueTest(unittest.TestCase): +class SmallQueueTest(SupyTestCase): def testReset(self): q = queue() q.enqueue(1) @@ -527,7 +527,7 @@ class SmallQueueTest(unittest.TestCase): self.assertEqual(q, pickle.loads(pickle.dumps(q))) -class MaxLengthQueueTestCase(unittest.TestCase): +class MaxLengthQueueTestCase(SupyTestCase): def testInit(self): q = MaxLengthQueue(3, (1, 2, 3)) self.assertEqual(list(q), [1, 2, 3]) @@ -549,7 +549,7 @@ class MaxLengthQueueTestCase(unittest.TestCase): self.assertEqual(q[0], 3) -class TwoWayDictionaryTestCase(unittest.TestCase): +class TwoWayDictionaryTestCase(SupyTestCase): def testInit(self): d = TwoWayDictionary(foo='bar') self.failUnless('foo' in d) @@ -576,7 +576,7 @@ class TwoWayDictionaryTestCase(unittest.TestCase): self.failIf('foo' in d) -class PersistentDictionaryTestCase(unittest.TestCase): +class PersistentDictionaryTestCase(SupyTestCase): def test(self): d = PersistentDictionary('test.dict') d['foo'] = 'bar' diff --git a/test/test_utils.py b/test/test_utils.py index dfb67bafb..a2e607189 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -34,7 +34,7 @@ import sets import utils -class UtilsTest(unittest.TestCase): +class UtilsTest(SupyTestCase): def testMatchCase(self): f = utils.matchCase self.assertEqual('bar', f('foo', 'bar')) diff --git a/test/test_webutils.py b/test/test_webutils.py index b26d242ca..0ade604a5 100644 --- a/test/test_webutils.py +++ b/test/test_webutils.py @@ -34,7 +34,7 @@ from testsupport import * import webutils -class WebutilsTestCase(unittest.TestCase): +class WebutilsTestCase(SupyTestCase): def testGetDomain(self): self.assertEqual(webutils.getDomain('http://slashdot.org/foo/bar.exe'), 'slashdot.org') diff --git a/test/testsupport.py b/test/testsupport.py index f02713543..39f574f86 100644 --- a/test/testsupport.py +++ b/test/testsupport.py @@ -39,6 +39,7 @@ import time started = time.time() import unittest +import log import conf import utils import ircdb @@ -99,7 +100,13 @@ class TimeoutError(AssertionError): def __str__(self): 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 for an example. """ @@ -108,10 +115,11 @@ class PluginTestCase(unittest.TestCase): cleanConfDir = True cleanDataDir = True def setUp(self, nick='test'): - # Set conf variables appropriately. if self.__class__ in (PluginTestCase, ChannelPluginTestCase): # Necessary because there's a test in here that shouldn\'t run. return + SupyTestCase.setUp(self) + # Set conf variables appropriately. conf.supybot.prefixChars.set('@') conf.supybot.reply.whenNotCommand.setValue(False) self.myVerbose = world.myVerbose