2003-04-03 00:30:34 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-04-03 00:30:34 +02:00
|
|
|
# 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.
|
|
|
|
###
|
|
|
|
|
2004-07-23 06:20:13 +02:00
|
|
|
__revision__ = "$Id$"
|
2004-07-23 06:18:59 +02:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
import os
|
|
|
|
|
2004-09-01 08:13:30 +02:00
|
|
|
print 'Testing begun, pid=%s' % os.getpid()
|
|
|
|
|
2003-09-24 09:28:25 +02:00
|
|
|
import supybot
|
2004-01-01 20:51:48 +01:00
|
|
|
import logging
|
2003-08-23 05:47:00 +02:00
|
|
|
|
2004-01-20 22:50:38 +01:00
|
|
|
if not os.path.exists('test-conf'):
|
|
|
|
os.mkdir('test-conf')
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
registryFilename = os.path.join('test-conf', 'test.conf')
|
|
|
|
fd = file(registryFilename, 'w')
|
|
|
|
fd.write("""
|
|
|
|
supybot.directories.data: test-data
|
|
|
|
supybot.directories.conf: test-conf
|
2004-01-31 18:46:19 +01:00
|
|
|
supybot.directories.log: test-logs
|
2004-08-01 16:38:37 +02:00
|
|
|
supybot.reply.whenNotCommand: True
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.log.stdout: False
|
2004-02-01 00:33:33 +01:00
|
|
|
supybot.log.level: DEBUG
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.log.detailedTracebacks: False
|
2004-09-09 00:39:30 +02:00
|
|
|
supybot.log.individualPluginLogfiles: True
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.throttleTime: 0
|
2004-08-26 01:03:42 +02:00
|
|
|
supybot.reply.whenAddressedBy.chars: @
|
2004-04-30 04:13:42 +02:00
|
|
|
supybot.protocols.irc.throttleTime: -1
|
2004-07-26 08:05:39 +02:00
|
|
|
supybot.networks.test.server: should.not.need.this
|
2004-07-26 08:20:03 +02:00
|
|
|
supybot.nick: test
|
2004-01-18 08:58:26 +01:00
|
|
|
""")
|
|
|
|
fd.close()
|
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.registry as registry
|
2004-01-18 08:58:26 +01:00
|
|
|
registry.open(registryFilename)
|
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.log as log
|
|
|
|
import supybot.conf as conf
|
2004-01-18 20:35:36 +01:00
|
|
|
conf.allowEval = True
|
2004-02-13 09:53:19 +01:00
|
|
|
conf.supybot.flush.setValue(False)
|
2003-08-23 05:47:00 +02:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.fix as fix
|
2003-04-03 08:59:00 +02:00
|
|
|
|
2003-08-17 04:02:53 +02:00
|
|
|
import re
|
2004-09-06 10:19:20 +02:00
|
|
|
import sys
|
2003-04-03 08:59:00 +02:00
|
|
|
import glob
|
2004-09-06 10:19:20 +02:00
|
|
|
import atexit
|
2003-04-03 08:59:00 +02:00
|
|
|
import os.path
|
2003-04-03 00:30:34 +02:00
|
|
|
import unittest
|
2003-04-03 08:59:00 +02:00
|
|
|
|
2004-09-06 10:19:20 +02:00
|
|
|
import supybot.utils as utils
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.world as world
|
2003-04-14 09:21:27 +02:00
|
|
|
|
2003-10-11 19:34:52 +02:00
|
|
|
class path(str):
|
|
|
|
"""A class to represent platform-independent paths."""
|
|
|
|
_r = re.compile(r'[\\/]')
|
|
|
|
def __hash__(self):
|
|
|
|
return reduce(lambda h, s: h ^ hash(s), self._r.split(self), 0)
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self._r.split(self) == self._r.split(other)
|
|
|
|
|
2003-04-03 08:59:00 +02:00
|
|
|
if __name__ == '__main__':
|
2004-01-01 20:51:48 +01:00
|
|
|
import testsupport
|
2003-10-07 16:09:13 +02:00
|
|
|
import optparse
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
if not os.path.exists(conf.supybot.directories.data()):
|
|
|
|
os.mkdir(conf.supybot.directories.data())
|
2003-10-05 06:42:46 +02:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
if not os.path.exists(conf.supybot.directories.conf()):
|
|
|
|
os.mkdir(conf.supybot.directories.conf())
|
2003-10-05 06:42:46 +02:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
if not os.path.exists(conf.supybot.directories.log()):
|
|
|
|
os.mkdir(conf.supybot.directories.log())
|
2003-10-05 06:42:46 +02:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
pluginLogDir = os.path.join(conf.supybot.directories.log(), 'plugins')
|
|
|
|
if not os.path.exists(pluginLogDir):
|
|
|
|
os.mkdir(pluginLogDir)
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-11-26 19:21:12 +01:00
|
|
|
for filename in os.listdir(pluginLogDir):
|
|
|
|
os.remove(os.path.join(pluginLogDir, filename))
|
2003-10-05 06:42:46 +02:00
|
|
|
|
2003-10-07 16:09:13 +02:00
|
|
|
parser = optparse.OptionParser(usage='Usage: %prog [options]',
|
|
|
|
version='Supybot %s' % conf.version)
|
|
|
|
parser.add_option('-e', '--exclude', action='append',
|
|
|
|
dest='exclusions', metavar='TESTFILE',
|
|
|
|
help='Exclude this test from the test run.')
|
2003-10-09 18:59:12 +02:00
|
|
|
parser.add_option('-t', '--timeout', action='store', type='int',
|
|
|
|
dest='timeout',
|
|
|
|
help='Sets the timeout for tests to return responses.')
|
|
|
|
parser.add_option('-p', '--plugindir', action='append',
|
|
|
|
metavar='plugindir', dest='plugindirs',
|
|
|
|
help='Adds a directory to the list of directories in '
|
|
|
|
'which to search for plugins.')
|
2003-10-15 06:43:52 +02:00
|
|
|
parser.add_option('-v', '--verbose', action='store_true', default=False,
|
|
|
|
help='Sets the verbose flag, printing extra information '
|
|
|
|
'about each test that runs.')
|
2004-09-09 00:39:30 +02:00
|
|
|
parser.add_option('', '--no-network', action='store_true', default=False,
|
2004-09-09 02:09:03 +02:00
|
|
|
dest='nonetwork', help='Causes the network-based tests '
|
|
|
|
'not to run.')
|
2004-09-09 00:39:30 +02:00
|
|
|
parser.add_option('', '--no-plugins', action='store_true', default=False,
|
2004-09-09 02:09:03 +02:00
|
|
|
dest='noplugins',
|
2004-01-01 20:51:48 +01:00
|
|
|
help='Causes the plugin tests not to run.')
|
2004-09-06 10:19:20 +02:00
|
|
|
parser.add_option('', '--trace', action='store_true', default=False,
|
|
|
|
help='Traces all calls made.')
|
2003-10-07 16:09:13 +02:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if not args:
|
2004-01-01 20:51:48 +01:00
|
|
|
if options.noplugins:
|
|
|
|
pattern = 'test_[a-z]*.py'
|
|
|
|
else:
|
|
|
|
pattern = 'test_*.py'
|
|
|
|
args = map(path, glob.glob(os.path.join('test', pattern)))
|
2003-10-20 10:22:22 +02:00
|
|
|
|
2003-10-07 16:09:13 +02:00
|
|
|
if options.exclusions:
|
2004-02-13 09:53:19 +01:00
|
|
|
for (i, s) in enumerate(options.exclusions):
|
|
|
|
if not s.startswith('test/') and not s.startswith('test\\'):
|
|
|
|
s = 'test/' + s
|
|
|
|
if not s.endswith('.py'):
|
|
|
|
s += '.py'
|
2003-10-11 19:34:52 +02:00
|
|
|
for name in map(path, options.exclusions):
|
2003-10-07 16:09:13 +02:00
|
|
|
args = [s for s in args if s != name]
|
2003-10-20 10:22:22 +02:00
|
|
|
|
2003-10-09 18:59:12 +02:00
|
|
|
if options.timeout:
|
|
|
|
PluginTestCase.timeout = options.timeout
|
2003-10-20 10:22:22 +02:00
|
|
|
|
2004-09-06 10:19:20 +02:00
|
|
|
if options.trace:
|
|
|
|
traceFilename = conf.supybot.directories.log.dirize('trace.log')
|
|
|
|
fd = file(traceFilename, 'w')
|
|
|
|
sys.settrace(utils.callTracer(fd))
|
|
|
|
atexit.register(fd.close)
|
|
|
|
atexit.register(lambda : sys.settrace(None))
|
|
|
|
|
2003-10-09 18:59:12 +02:00
|
|
|
if options.plugindirs:
|
2003-10-23 05:26:36 +02:00
|
|
|
options.plugindirs.reverse()
|
2003-10-09 18:59:12 +02:00
|
|
|
conf.pluginDirs.extend(options.plugindirs)
|
2003-10-23 05:26:36 +02:00
|
|
|
conf.pluginDirs.reverse()
|
2003-10-20 10:22:22 +02:00
|
|
|
|
2003-10-15 06:43:52 +02:00
|
|
|
if options.verbose:
|
|
|
|
world.myVerbose = True
|
|
|
|
else:
|
|
|
|
world.myVerbose = False
|
2003-10-20 10:22:22 +02:00
|
|
|
|
2004-01-01 20:51:48 +01:00
|
|
|
if options.nonetwork:
|
|
|
|
testsupport.network = False
|
|
|
|
|
2004-08-26 07:23:24 +02:00
|
|
|
log.testing = True
|
2003-04-08 09:25:16 +02:00
|
|
|
world.testing = True
|
2003-10-07 16:09:13 +02:00
|
|
|
names = [os.path.splitext(os.path.basename(name))[0] for name in args]
|
2003-10-21 08:11:34 +02:00
|
|
|
names.sort()
|
2003-04-03 08:59:00 +02:00
|
|
|
suite = unittest.defaultTestLoader.loadTestsFromNames(names)
|
2003-04-03 10:17:00 +02:00
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
2003-04-03 08:59:00 +02:00
|
|
|
runner.run(suite)
|
2003-08-17 08:25:41 +02:00
|
|
|
print 'Total asserts: %s' % unittest.asserts
|
2003-08-18 00:13:10 +02:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|