2005-12-16 17:29:13 +05:30
|
|
|
"""Copyright QinetiQ Ltd (2005) - See LICENSE.TXT for licensing information.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
def make_parser():
|
|
|
|
usage = "usage: %prog [options]"
|
|
|
|
parser = OptionParser(usage)
|
|
|
|
parser.add_option("-v", "--verbosity", type="int", dest="verbose_level", default=0,
|
|
|
|
help="Level of verboseness")
|
2005-12-18 02:43:45 +05:30
|
|
|
parser.add_option("-p", "--performance", action="store_true", dest="performance", default=False,
|
|
|
|
help="Run the performance tests.")
|
2005-12-16 17:29:13 +05:30
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def getTestSuites():
|
|
|
|
|
|
|
|
test_modules = [ i for i in os.listdir('.') if i[-8:] == "_Test.py" ]
|
|
|
|
|
|
|
|
test_suites = []
|
2005-12-18 02:43:45 +05:30
|
|
|
perf_suites = []
|
2005-12-16 17:29:13 +05:30
|
|
|
for module in test_modules:
|
|
|
|
mod = __import__(module[:-3])
|
|
|
|
test_suites.append(mod.testSuite())
|
2005-12-18 02:43:45 +05:30
|
|
|
try:
|
|
|
|
perf_suites.append(mod.perfSuite())
|
|
|
|
except:
|
|
|
|
pass
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
return (test_suites,perf_suites)
|
2005-12-16 17:29:13 +05:30
|
|
|
|
|
|
|
def allTheTests():
|
2005-12-18 02:43:45 +05:30
|
|
|
return unittest.TestSuite(getTestSuites()[0])
|
2005-12-16 17:29:13 +05:30
|
|
|
|
2005-12-18 02:43:45 +05:30
|
|
|
def perfTests():
|
|
|
|
return unittest.TestSuite(getTestSuites()[1])
|
|
|
|
|
2005-12-16 17:29:13 +05:30
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
console = logging.StreamHandler()
|
|
|
|
console.setLevel(logging.INFO)
|
|
|
|
console.setFormatter(logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s'))
|
|
|
|
|
|
|
|
logger = logging.getLogger('Gramps')
|
|
|
|
logger.addHandler(console)
|
|
|
|
|
|
|
|
(options,args) = make_parser().parse_args()
|
|
|
|
|
|
|
|
if options.verbose_level == 1:
|
|
|
|
logger.setLevel(logging.INFO)
|
2005-12-16 22:01:38 +05:30
|
|
|
console.setLevel(logging.INFO)
|
|
|
|
elif options.verbose_level == 2:
|
2005-12-16 17:29:13 +05:30
|
|
|
logger.setLevel(logging.DEBUG)
|
2005-12-16 22:01:38 +05:30
|
|
|
console.setLevel(logging.DEBUG)
|
|
|
|
elif options.verbose_level == 3:
|
|
|
|
logger.setLevel(logging.NOTSET)
|
|
|
|
console.setLevel(logging.NOTSET)
|
|
|
|
elif options.verbose_level >= 4:
|
2005-12-16 17:29:13 +05:30
|
|
|
logger.setLevel(logging.NOTSET)
|
2005-12-16 22:01:38 +05:30
|
|
|
console.setLevel(logging.NOTSET)
|
|
|
|
os.environ['GRAMPS_SIGNAL'] = "1"
|
2005-12-16 17:29:13 +05:30
|
|
|
else:
|
|
|
|
logger.setLevel(logging.ERROR)
|
2005-12-16 22:01:38 +05:30
|
|
|
console.setLevel(logging.ERROR)
|
2005-12-18 02:43:45 +05:30
|
|
|
|
|
|
|
|
|
|
|
if options.performance:
|
|
|
|
unittest.TextTestRunner(verbosity=options.verbose_level).run(perfTests())
|
|
|
|
else:
|
|
|
|
unittest.TextTestRunner(verbosity=options.verbose_level).run(allTheTests())
|