2013-08-09 11:43:20 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2010-05-14 19:39:26 +04:00
|
|
|
import optparse
|
2008-10-08 07:13:14 +04:00
|
|
|
import os
|
|
|
|
import sys
|
2016-06-16 06:54:51 +03:00
|
|
|
import unittest
|
2009-06-11 13:34:37 +04:00
|
|
|
|
2008-10-08 07:13:14 +04:00
|
|
|
if __name__ == '__main__':
|
2010-05-14 19:39:26 +04:00
|
|
|
description = ("This script runs the hgsubversion tests. If no tests are "
|
|
|
|
"specified, all known tests are implied.")
|
|
|
|
parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]",
|
|
|
|
description=description)
|
|
|
|
parser.add_option("-A", "--all",
|
|
|
|
dest="comprehensive", action="store_true", default=False,
|
|
|
|
help="include slow, but comprehensive tests")
|
|
|
|
parser.add_option("-v", "--verbose",
|
|
|
|
dest="verbose", action="store_true", default=False,
|
|
|
|
help="enable verbose output")
|
2010-05-14 22:27:24 +04:00
|
|
|
parser.add_option("", "--no-demandimport",
|
|
|
|
dest="demandimport", action="store_false", default=True,
|
|
|
|
help="disable Mercurial demandimport loading")
|
2010-09-03 01:23:02 +04:00
|
|
|
parser.add_option("", "--bindings",
|
|
|
|
dest="bindings", action="store", default=None,
|
|
|
|
choices=["swig", "subvertpy"],
|
|
|
|
help="test using the specified bindings (swig or "
|
|
|
|
"subvertpy)")
|
2010-09-08 11:50:11 +04:00
|
|
|
parser.add_option("", "--show-stdout",
|
|
|
|
dest="showstdout", action="store_true", default=False,
|
|
|
|
help="show stdout (hidden by default)")
|
2009-05-28 10:48:57 +04:00
|
|
|
|
2010-05-14 19:39:26 +04:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.verbose:
|
|
|
|
testargs = { 'descriptions': 3, 'verbosity': 2 }
|
|
|
|
else:
|
|
|
|
testargs = {'descriptions': 2}
|
2009-03-27 05:42:52 +03:00
|
|
|
|
2010-05-18 23:46:50 +04:00
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
2010-05-14 22:27:24 +04:00
|
|
|
if options.demandimport:
|
|
|
|
from mercurial import demandimport
|
|
|
|
demandimport.enable()
|
|
|
|
|
2010-09-03 01:23:02 +04:00
|
|
|
if options.bindings:
|
2010-09-14 17:25:45 +04:00
|
|
|
os.environ['HGSUBVERSION_BINDINGS'] = options.bindings
|
2010-09-03 01:23:02 +04:00
|
|
|
|
2010-07-14 17:39:21 +04:00
|
|
|
# make sure our copy of hgsubversion gets imported by loading test_util
|
|
|
|
import test_util
|
|
|
|
test_util.TestBase
|
|
|
|
|
2009-05-15 19:24:08 +04:00
|
|
|
# silence output when running outside nose
|
2010-09-08 11:50:11 +04:00
|
|
|
if not options.showstdout:
|
|
|
|
import tempfile
|
|
|
|
sys.stdout = tempfile.TemporaryFile()
|
2009-05-15 19:24:08 +04:00
|
|
|
|
2016-06-12 15:55:57 +03:00
|
|
|
args = [os.path.basename(os.path.splitext(arg)[0]).replace('-', '_')
|
|
|
|
for arg in args]
|
2009-05-28 10:48:57 +04:00
|
|
|
|
2013-08-07 18:16:49 +04:00
|
|
|
loader = unittest.TestLoader()
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
|
2016-06-16 06:54:51 +03:00
|
|
|
if sys.version_info[:2] < (2, 7):
|
|
|
|
import glob
|
|
|
|
def discover(start_dir, pattern='test*.py', top_level_dir=None):
|
|
|
|
tests = []
|
|
|
|
sys.path.append(start_dir)
|
|
|
|
for path in glob.glob(os.path.join(start_dir, pattern)):
|
|
|
|
name = os.path.splitext(os.path.basename(path))[0]
|
|
|
|
tests.append(loader.loadTestsFromModule(__import__(name)))
|
|
|
|
return tests
|
|
|
|
loader.discover = discover
|
|
|
|
|
2009-05-28 10:48:57 +04:00
|
|
|
if not args:
|
2016-06-16 06:54:51 +03:00
|
|
|
suite.addTests(loader.discover('.'))
|
2016-06-12 15:55:57 +03:00
|
|
|
|
|
|
|
if options.comprehensive:
|
|
|
|
suite.addTests(loader.discover('comprehensive',
|
|
|
|
top_level_dir='comprehensive'))
|
2009-05-28 10:48:57 +04:00
|
|
|
else:
|
2016-06-12 15:55:57 +03:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive'))
|
|
|
|
|
|
|
|
suite.addTests(loader.loadTestsFromNames(args))
|
2009-05-28 10:48:57 +04:00
|
|
|
|
2010-05-14 19:39:26 +04:00
|
|
|
runner = unittest.TextTestRunner(**testargs)
|
2013-08-07 18:16:49 +04:00
|
|
|
result = runner.run(suite)
|
2010-03-02 02:45:00 +03:00
|
|
|
if not result.wasSuccessful():
|
|
|
|
sys.exit(1)
|