view tests/run.py @ 1512:6d0fe7ce9898

commands: fix command option registering A recent patch introduced svnopts as a way of sharing the svn command options between the old and the new way of registering a command. It turns out 'svnopts' was already used further up in the module to define the flags that should be added to *all* Mercurial commands. So our definition of it here cause us to add all of these options to all Mercurial commands. This was caught because it changes --rev to be '' instead of [], which breaks a number of assumptions in the other commands. Given that none of the subversion tests are command line tests, I'm not sure how to test this. It was caught in other extensions tests. (grafted from 3b1334407783a4379fd515e2ed9acc61e3f175ff) (grafted from 6db63ead5556f2bf72e423ca8c6df08ea3a5b009)
author Durham Goode <durham@fb.com>
date Wed, 24 May 2017 15:07:00 -0700
parents dcf9eff9b5b7
children
line wrap: on
line source

#!/usr/bin/env python

import optparse
import os
import sys
import unittest

if __name__ == '__main__':
    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")
    parser.add_option("", "--no-demandimport",
                      dest="demandimport", action="store_false", default=True,
                      help="disable Mercurial demandimport loading")
    parser.add_option("", "--bindings",
                      dest="bindings", action="store", default=None,
                      choices=["swig", "subvertpy"],
                      help="test using the specified bindings (swig or "
                      "subvertpy)")
    parser.add_option("", "--show-stdout",
                      dest="showstdout", action="store_true", default=False,
                      help="show stdout (hidden by default)")

    (options, args) = parser.parse_args()

    if options.verbose:
        testargs = { 'descriptions': 3, 'verbosity': 2 }
    else:
        testargs = {'descriptions': 2}

    sys.path.append(os.path.dirname(os.path.dirname(__file__)))

    if options.demandimport:
        from mercurial import demandimport
        demandimport.enable()

    if options.bindings:
        os.environ['HGSUBVERSION_BINDINGS'] = options.bindings

    # make sure our copy of hgsubversion gets imported by loading test_util
    import test_util
    test_util.TestBase

    # silence output when running outside nose
    if not options.showstdout:
        import tempfile
        sys.stdout = tempfile.TemporaryFile()

    args = [os.path.basename(os.path.splitext(arg)[0]).replace('-', '_')
            for arg in args]

    loader = unittest.TestLoader()
    suite = unittest.TestSuite()

    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

    if not args:
        suite.addTests(loader.discover('.'))

        if options.comprehensive:
            suite.addTests(loader.discover('comprehensive',
                                           top_level_dir='comprehensive'))
    else:
        sys.path.append(os.path.join(os.path.dirname(__file__), 'comprehensive'))

        suite.addTests(loader.loadTestsFromNames(args))

    runner = unittest.TextTestRunner(**testargs)
    result = runner.run(suite)
    if not result.wasSuccessful():
        sys.exit(1)