2005-01-20 00:12:50 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
|
|
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2011, James McCoy
|
2005-01-20 00:12:50 +01: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.
|
|
|
|
###
|
|
|
|
|
|
|
|
import os
|
2013-01-04 20:23:48 +01:00
|
|
|
import sys
|
2005-01-20 00:12:50 +01:00
|
|
|
import time
|
2005-02-18 08:31:19 +01:00
|
|
|
import shutil
|
2005-01-20 00:12:50 +01:00
|
|
|
started = time.time()
|
|
|
|
|
|
|
|
import supybot
|
|
|
|
import logging
|
2013-10-27 11:53:36 +01:00
|
|
|
import traceback
|
2005-01-20 00:12:50 +01:00
|
|
|
|
|
|
|
# We need to do this before we import conf.
|
|
|
|
if not os.path.exists('test-conf'):
|
|
|
|
os.mkdir('test-conf')
|
|
|
|
|
|
|
|
registryFilename = os.path.join('test-conf', 'test.conf')
|
2012-08-04 13:13:16 +02:00
|
|
|
fd = open(registryFilename, 'w')
|
2005-01-20 00:12:50 +01:00
|
|
|
fd.write("""
|
2015-09-20 15:45:43 +02:00
|
|
|
supybot.directories.data: %(base_dir)s/test-data
|
|
|
|
supybot.directories.conf: %(base_dir)s/test-conf
|
|
|
|
supybot.directories.log: %(base_dir)s/test-logs
|
2005-01-20 00:12:50 +01:00
|
|
|
supybot.reply.whenNotCommand: True
|
|
|
|
supybot.log.stdout: False
|
2015-08-29 23:02:20 +02:00
|
|
|
supybot.log.stdout.level: ERROR
|
2005-02-04 06:59:07 +01:00
|
|
|
supybot.log.level: DEBUG
|
2015-09-20 15:45:43 +02:00
|
|
|
supybot.log.format: %%(levelname)s %%(message)s
|
2005-01-20 00:12:50 +01:00
|
|
|
supybot.log.plugins.individualLogfiles: False
|
|
|
|
supybot.protocols.irc.throttleTime: 0
|
|
|
|
supybot.reply.whenAddressedBy.chars: @
|
|
|
|
supybot.networks.test.server: should.not.need.this
|
|
|
|
supybot.nick: test
|
|
|
|
supybot.databases.users.allowUnregistration: True
|
2015-09-20 15:45:43 +02:00
|
|
|
""" % {'base_dir': os.getcwd()})
|
2005-01-20 00:12:50 +01:00
|
|
|
fd.close()
|
|
|
|
|
|
|
|
import supybot.registry as registry
|
2012-08-04 13:13:16 +02:00
|
|
|
registry.open_registry(registryFilename)
|
2005-01-20 00:12:50 +01:00
|
|
|
|
|
|
|
import supybot.log as log
|
|
|
|
import supybot.conf as conf
|
|
|
|
conf.allowEval = True
|
|
|
|
conf.supybot.flush.setValue(False)
|
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import atexit
|
|
|
|
import os.path
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.world as world
|
2005-05-30 21:20:36 +02:00
|
|
|
import supybot.callbacks as callbacks
|
2005-01-20 00:12:50 +01:00
|
|
|
world.startedAt = started
|
|
|
|
|
|
|
|
import logging
|
|
|
|
class TestLogFilter(logging.Filter):
|
|
|
|
bads = [
|
|
|
|
'No callbacks in',
|
|
|
|
'Invalid channel database',
|
|
|
|
'Exact error',
|
|
|
|
'Invalid user dictionary',
|
|
|
|
'because of noFlush',
|
|
|
|
'Queuing NICK',
|
|
|
|
'Queuing USER',
|
|
|
|
'IgnoresDB.reload failed',
|
|
|
|
'Starting log for',
|
|
|
|
'Irc object for test dying',
|
|
|
|
'Last Irc,',
|
|
|
|
]
|
|
|
|
def filter(self, record):
|
|
|
|
for bad in self.bads:
|
|
|
|
if bad in record.msg:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
log._logger.addFilter(TestLogFilter())
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2005-02-02 22:09:45 +01:00
|
|
|
import glob
|
2005-01-20 00:12:50 +01:00
|
|
|
import os.path
|
|
|
|
import optparse
|
|
|
|
import supybot.test as test
|
|
|
|
import supybot.plugin as plugin
|
|
|
|
|
|
|
|
parser = optparse.OptionParser(usage='Usage: %prog [options] [plugins]',
|
|
|
|
version='Supybot %s' % conf.version)
|
2005-02-18 08:31:19 +01:00
|
|
|
parser.add_option('-c', '--clean', action='store_true', default=False,
|
|
|
|
dest='clean', help='Cleans the various data/conf/logs'
|
|
|
|
'directories before running tests.')
|
2011-08-22 20:07:39 +02:00
|
|
|
parser.add_option('-t', '--timeout', action='store', type='float',
|
2005-01-20 00:12:50 +01:00
|
|
|
dest='timeout',
|
2011-08-22 20:07:39 +02:00
|
|
|
help='Sets the timeout, in seconds, for tests to return '
|
|
|
|
'responses.')
|
2015-08-29 23:02:20 +02:00
|
|
|
parser.add_option('-v', '--verbose', action='count', default=0,
|
|
|
|
help='Increase verbosity, logging extra information '
|
2005-01-20 00:12:50 +01:00
|
|
|
'about each test that runs.')
|
|
|
|
parser.add_option('', '--no-network', action='store_true', default=False,
|
|
|
|
dest='nonetwork', help='Causes the network-based tests '
|
|
|
|
'not to run.')
|
|
|
|
parser.add_option('', '--trace', action='store_true', default=False,
|
|
|
|
help='Traces all calls made. Unless you\'re really in '
|
|
|
|
'a pinch, you probably shouldn\'t do this; it results '
|
|
|
|
'in copious amounts of output.')
|
2005-02-02 22:09:45 +01:00
|
|
|
parser.add_option('', '--plugins-dir',
|
|
|
|
action='append', dest='pluginsDirs', default=[],
|
|
|
|
help='Looks in in the given directory for plugins and '
|
|
|
|
'loads the tests from all of them.')
|
2013-01-06 17:17:26 +01:00
|
|
|
parser.add_option('', '--exclude',
|
|
|
|
action='append', dest='excludePlugins', default=[],
|
|
|
|
help='List of plugins you do not want --plugins-dir '
|
|
|
|
'to include.')
|
2013-04-11 19:09:50 +02:00
|
|
|
parser.add_option('', '--disable-multiprocessing', action='store_true',
|
|
|
|
dest='disableMultiprocessing',
|
|
|
|
help='Disables multiprocessing stuff.')
|
2015-08-29 23:02:20 +02:00
|
|
|
parser.add_option('', '--verbose-unexcepted-errors', action='store_true',
|
|
|
|
dest='verboseUnexceptectedErros',
|
|
|
|
help='Show the full traceback of unexpected errors.')
|
2005-01-20 00:12:50 +01:00
|
|
|
(options, args) = parser.parse_args()
|
2005-02-02 22:09:45 +01:00
|
|
|
|
2014-08-14 14:16:15 +02:00
|
|
|
world.disableMultiprocessing = options.disableMultiprocessing
|
2013-04-11 19:09:50 +02:00
|
|
|
|
2005-02-02 22:09:45 +01:00
|
|
|
# This must go before checking for args, of course.
|
|
|
|
for pluginDir in options.pluginsDirs:
|
|
|
|
for name in glob.glob(os.path.join(pluginDir, '*')):
|
|
|
|
#print '***', name
|
2013-08-03 16:06:23 +02:00
|
|
|
if not any(map(lambda x:name in x,
|
|
|
|
map(glob.glob, options.excludePlugins))) and \
|
|
|
|
os.path.isdir(name):
|
2005-02-02 22:09:45 +01:00
|
|
|
args.append(name)
|
|
|
|
|
2005-01-20 00:12:50 +01:00
|
|
|
if not args:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(-1)
|
2005-01-31 14:06:43 +01:00
|
|
|
|
2005-01-20 00:12:50 +01:00
|
|
|
if options.timeout:
|
|
|
|
test.timeout = options.timeout
|
|
|
|
|
|
|
|
if options.trace:
|
|
|
|
traceFilename = conf.supybot.directories.log.dirize('trace.log')
|
2012-08-04 13:13:16 +02:00
|
|
|
fd = open(traceFilename, 'w')
|
2005-01-31 14:06:43 +01:00
|
|
|
sys.settrace(utils.gen.callTracer(fd))
|
2005-01-20 00:12:50 +01:00
|
|
|
atexit.register(fd.close)
|
|
|
|
atexit.register(lambda : sys.settrace(None))
|
|
|
|
|
2015-08-29 23:02:20 +02:00
|
|
|
world.myVerbose = options.verbose
|
2005-01-20 00:12:50 +01:00
|
|
|
|
|
|
|
if options.nonetwork:
|
2005-01-20 00:33:33 +01:00
|
|
|
test.network = False
|
2005-01-20 00:12:50 +01:00
|
|
|
|
|
|
|
log.testing = True
|
|
|
|
world.testing = True
|
|
|
|
|
|
|
|
args = [s.rstrip('\\/') for s in args]
|
|
|
|
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])
|
|
|
|
load = unittest.defaultTestLoader.loadTestsFromModule
|
|
|
|
for pluginName in pluginNames:
|
|
|
|
if pluginName.endswith('.py'):
|
|
|
|
pluginName = pluginName[:-3]
|
2005-01-23 20:42:25 +01:00
|
|
|
try:
|
|
|
|
pluginModule = plugin.loadPluginModule(pluginName)
|
2013-04-27 16:16:08 +02:00
|
|
|
except (ImportError, callbacks.Error) as e:
|
2013-10-27 11:53:36 +01:00
|
|
|
sys.stderr.write('Failed to load plugin %s:' % pluginName)
|
|
|
|
traceback.print_exc()
|
2008-06-16 13:52:37 +02:00
|
|
|
sys.stderr.write('(pluginDirs: %s)\n' %
|
2005-01-23 20:42:25 +01:00
|
|
|
conf.supybot.directories.plugins())
|
2008-06-03 05:48:55 +02:00
|
|
|
continue
|
2005-01-20 00:12:50 +01:00
|
|
|
if hasattr(pluginModule, 'test'):
|
2005-01-23 20:42:25 +01:00
|
|
|
test.suites.append(load(pluginModule.test))
|
2005-01-31 14:06:43 +01:00
|
|
|
|
2005-01-23 20:42:25 +01:00
|
|
|
suite = unittest.TestSuite(test.suites)
|
2005-01-20 00:12:50 +01:00
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
2013-04-27 16:16:08 +02:00
|
|
|
print('Testing began at %s (pid %s)' % (time.ctime(), os.getpid()))
|
2005-02-18 08:31:19 +01:00
|
|
|
if options.clean:
|
|
|
|
shutil.rmtree(conf.supybot.directories.log())
|
|
|
|
shutil.rmtree(conf.supybot.directories.conf())
|
|
|
|
shutil.rmtree(conf.supybot.directories.data())
|
2013-01-04 20:23:48 +01:00
|
|
|
result = runner.run(suite)
|
2005-01-20 00:12:50 +01:00
|
|
|
|
|
|
|
if hasattr(unittest, 'asserts'):
|
2013-04-27 16:16:08 +02:00
|
|
|
print('Total asserts: %s' % unittest.asserts)
|
2005-01-20 00:12:50 +01:00
|
|
|
|
2013-01-04 20:23:48 +01:00
|
|
|
if result.wasSuccessful():
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-03-12 00:26:49 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|