diff --git a/scripts/supybot-test b/scripts/supybot-test index b25c03a81..d48ecfaba 100644 --- a/scripts/supybot-test +++ b/scripts/supybot-test @@ -163,16 +163,21 @@ if __name__ == '__main__': pluginDirs = set([os.path.dirname(s) or '.' for s in args]) conf.supybot.directories.plugins.setValue(list(pluginDirs)) pluginNames = set([os.path.basename(s) for s in args]) - suites = [] load = unittest.defaultTestLoader.loadTestsFromModule for pluginName in pluginNames: if pluginName.endswith('.py'): pluginName = pluginName[:-3] - pluginModule = plugin.loadPluginModule(pluginName) + try: + pluginModule = plugin.loadPluginModule(pluginName) + except ImportError, e: + sys.stderr.write('Failed to load plugin %s: %s\n' % (pluginName,e)) + sys.stderr.write('(pluginDirs: %s)' % + conf.supybot.directories.plugins()) + sys.exit(-1) if hasattr(pluginModule, 'test'): - suites.append(load(pluginModule.test)) - - suite = unittest.TestSuite(suites) + test.suites.append(load(pluginModule.test)) + + suite = unittest.TestSuite(test.suites) runner = unittest.TextTestRunner(verbosity=2) runner.run(suite) diff --git a/src/test.py b/src/test.py index 76ba68898..56a4f63e4 100644 --- a/src/test.py +++ b/src/test.py @@ -53,6 +53,9 @@ import supybot.callbacks as callbacks network = True +# This is the global list of suites that are to be run. +suites = [] + originalCallbacksGetHelp = callbacks.getHelp lastGetHelp = 'x'*1000 def cachingGetHelp(method, name=None): diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 000000000..1f11b3439 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,32 @@ +### +# Copyright (c) 2005, Jeremiah Fincher +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +import test + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test.py b/test/test.py new file mode 100644 index 000000000..47b500d02 --- /dev/null +++ b/test/test.py @@ -0,0 +1,48 @@ +### +# Copyright (c) 2005, Jeremiah Fincher +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +import os.path +import unittest + +import supybot.test as test + +load = unittest.defaultTestLoader.loadTestsFromModule + +GLOBALS = globals() +dirname = os.path.dirname(__file__) +for filename in os.listdir(dirname): + if filename.startswith('test_') and filename.endswith('.py'): + name = filename[:-3] + exec 'import %s' % name in GLOBALS + test.suites.append(load(GLOBALS[name])) + +module = None + + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_callbacks.py b/test/test_callbacks.py index df4e06a4c..7729b18e0 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import supybot.conf as conf import supybot.utils as utils @@ -272,7 +272,7 @@ class FunctionsTestCase(SupyTestCase): class PrivmsgTestCase(ChannelPluginTestCase): - plugins = ('Utilities', 'Misc', 'Http') + plugins = ('Utilities', 'Misc',) conf.allowEval = True timeout = 2 def testEmptySquareBrackets(self): @@ -280,6 +280,7 @@ class PrivmsgTestCase(ChannelPluginTestCase): def testHelpNoNameError(self): # This will raise a NameError if some dynamic scoping isn't working + self.assertNotError('load Http') self.assertHelp('extension') def testMaximumNestingDepth(self): diff --git a/test/test_commands.py b/test/test_commands.py index 8881abc40..0aed74c21 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * from supybot.commands import * import supybot.irclib as irclib diff --git a/test/test_fix.py b/test/test_fix.py index 49ec547f4..7b7413f69 100644 --- a/test/test_fix.py +++ b/test/test_fix.py @@ -29,7 +29,7 @@ ## from __future__ import generators -from testsupport import * +from supybot.test import * import random import itertools diff --git a/test/test_ircdb.py b/test/test_ircdb.py index 3f0428c30..25560387d 100644 --- a/test/test_ircdb.py +++ b/test/test_ircdb.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import os import unittest diff --git a/test/test_irclib.py b/test/test_irclib.py index 1eaea4e1b..ca0e4e57d 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import copy import pickle @@ -36,6 +36,11 @@ import supybot.conf as conf import supybot.irclib as irclib import supybot.ircmsgs as ircmsgs +# The test framework used to provide these, but not it doesn't. We'll add +# messages to as we find bugs (if indeed we find bugs). +msgs = [] +rawmsgs = [] + class IrcMsgQueueTestCase(SupyTestCase): mode = ircmsgs.op('#foo', 'jemfinch') msg = ircmsgs.privmsg('#foo', 'hey, you') @@ -226,22 +231,24 @@ class IrcStateTestCase(SupyTestCase): self.failUnless(st.channels['#foo'].isOp('baz')) def testHistory(self): - oldconfmaxhistory = conf.supybot.protocols.irc.maxHistoryLength() - conf.supybot.protocols.irc.maxHistoryLength.setValue(10) - state = irclib.IrcState() - for msg in msgs: - try: - state.addMsg(self.irc, msg) - except Exception: - pass - self.failIf(len(state.history) > - conf.supybot.protocols.irc.maxHistoryLength()) - self.assertEqual(len(state.history), - conf.supybot.protocols.irc.maxHistoryLength()) - self.assertEqual(list(state.history), - msgs[len(msgs) - - conf.supybot.protocols.irc.maxHistoryLength():]) - conf.supybot.protocols.irc.maxHistoryLength.setValue(oldconfmaxhistory) + if len(msgs) < 10: + return + maxHistoryLength = conf.supybot.protocols.irc.maxHistoryLength + oldconfmaxhistory = maxHistoryLength() + try: + maxHistoryLength.setValue(10) + state = irclib.IrcState() + for msg in msgs: + try: + state.addMsg(self.irc, msg) + except Exception: + pass + self.failIf(len(state.history) > maxHistoryLength()) + self.assertEqual(len(state.history), maxHistoryLength()) + self.assertEqual(list(state.history), + msgs[len(msgs) - maxHistoryLength():]) + finally: + maxHistoryLength.setValue(oldconfmaxhistory) def testWasteland005(self): state = irclib.IrcState() diff --git a/test/test_ircmsgs.py b/test/test_ircmsgs.py index f7a2cdf77..c0db281f6 100644 --- a/test/test_ircmsgs.py +++ b/test/test_ircmsgs.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import copy import pickle @@ -35,6 +35,10 @@ import pickle import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils +# The test framework used to provide these, but not it doesn't. We'll add +# messages to as we find bugs (if indeed we find bugs). +msgs = [] +rawmsgs = [] class IrcMsgTestCase(SupyTestCase): def testLen(self): @@ -59,7 +63,7 @@ class IrcMsgTestCase(SupyTestCase): def testEq(self): for msg in msgs: self.assertEqual(msg, msg) - self.failIf(msgs[0] == []) # Comparison to unhashable type. + self.failIf(msgs and msgs[0] == []) # Comparison to unhashable type. def testNe(self): for msg in msgs: diff --git a/test/test_ircutils.py b/test/test_ircutils.py index 2bdbd3b38..5bdec62b6 100644 --- a/test/test_ircutils.py +++ b/test/test_ircutils.py @@ -28,7 +28,7 @@ ### -from testsupport import * +from supybot.test import * import copy import random @@ -36,6 +36,11 @@ import random import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils +# The test framework used to provide these, but not it doesn't. We'll add +# messages to as we find bugs (if indeed we find bugs). +msgs = [] +rawmsgs = [] + class FunctionsTestCase(SupyTestCase): hostmask = 'foo!bar@baz' def testHostmaskPatternEqual(self): diff --git a/test/test_plugin.py b/test/test_plugin.py new file mode 100644 index 000000000..b9531d7a9 --- /dev/null +++ b/test/test_plugin.py @@ -0,0 +1,41 @@ +### +# Copyright (c) 2005, Jeremiah Fincher +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions, and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions, and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the author of this software nor the name of +# contributors to this software may be used to endorse or promote products +# derived from this software without specific prior written consent. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +### + +from supybot.test import * + +import supybot.plugin as plugin + +class FunctionsTestCase(SupyTestCase): + def testLoadPluginModule(self): + self.assertRaises(ImportError, plugin.loadPluginModule, 'asldj') + self.failUnless(plugin.loadPluginModule('Owner')) + self.failUnless(plugin.loadPluginModule('owner')) + + +# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_plugins.py b/test/test_plugins.py index a3714be8e..f0782380b 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import sets diff --git a/test/test_privmsgs.py b/test/test_privmsgs.py index 5f7404481..1320b5f82 100644 --- a/test/test_privmsgs.py +++ b/test/test_privmsgs.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import supybot.ircmsgs as ircmsgs import supybot.privmsgs as privmsgs diff --git a/test/test_registry.py b/test/test_registry.py index d956843ab..9cc7d5ee6 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import re diff --git a/test/test_schedule.py b/test/test_schedule.py index 779cee52c..0849eba87 100644 --- a/test/test_schedule.py +++ b/test/test_schedule.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import time diff --git a/test/test_standardSubstitute.py b/test/test_standardSubstitute.py index 7741a5a3d..70f04cece 100644 --- a/test/test_standardSubstitute.py +++ b/test/test_standardSubstitute.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import sets diff --git a/test/test_structures.py b/test/test_structures.py index 58b280664..790a0720b 100644 --- a/test/test_structures.py +++ b/test/test_structures.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import pickle diff --git a/test/test_utils.py b/test/test_utils.py index 12b06df30..e3e22b83d 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import sets import supybot.utils as utils diff --git a/test/test_webutils.py b/test/test_webutils.py index 216776b59..b283bcfe7 100644 --- a/test/test_webutils.py +++ b/test/test_webutils.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### -from testsupport import * +from supybot.test import * import supybot.webutils as webutils