diff options
Diffstat (limited to '')
| -rw-r--r-- | lang/python/tests/run-tests.py | 93 | 
1 files changed, 59 insertions, 34 deletions
diff --git a/lang/python/tests/run-tests.py b/lang/python/tests/run-tests.py index 95df1978..cec13b5e 100644 --- a/lang/python/tests/run-tests.py +++ b/lang/python/tests/run-tests.py @@ -17,10 +17,8 @@  # You should have received a copy of the GNU Lesser General Public  # License along with this program; if not, see <http://www.gnu.org/licenses/>. -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, division +from __future__ import print_function, unicode_literals  import argparse  import glob @@ -28,34 +26,50 @@ import os  import subprocess  import sys +del absolute_import, division, print_function, unicode_literals + +  class SplitAndAccumulate(argparse.Action):      def __call__(self, parser, namespace, values, option_string=None):          current = getattr(namespace, self.dest, list())          current.extend(values.split())          setattr(namespace, self.dest, current) +  parser = argparse.ArgumentParser(description='Run tests.') -parser.add_argument('tests', metavar='TEST', type=str, nargs='+', -                    help='A test to run') -parser.add_argument('-v', '--verbose', action="store_true", default=False, -                    help='Be verbose.') -parser.add_argument('-q', '--quiet', action="store_true", default=False, -                    help='Be quiet.') -parser.add_argument('--interpreters', metavar='PYTHON', type=str, -                    default=[], action=SplitAndAccumulate, -                    help='Use these interpreters to run the tests, ' + -                    'separated by spaces.') -parser.add_argument('--srcdir', type=str, -                    default=os.environ.get("srcdir", ""), -                    help='Location of the tests.') -parser.add_argument('--builddir', type=str, -                    default=os.environ.get("abs_builddir", ""), -                    help='Location of the tests.') -parser.add_argument('--python-libdir', type=str, -                    default=None, -                    help='Optional location of the in-tree module lib directory.') -parser.add_argument('--parallel', action="store_true", default=False, -                    help='Ignored.  For compatibility with run-tests.scm.') +parser.add_argument( +    'tests', metavar='TEST', type=str, nargs='+', help='A test to run') +parser.add_argument( +    '-v', '--verbose', action="store_true", default=False, help='Be verbose.') +parser.add_argument( +    '-q', '--quiet', action="store_true", default=False, help='Be quiet.') +parser.add_argument( +    '--interpreters', +    metavar='PYTHON', +    type=str, +    default=[], +    action=SplitAndAccumulate, +    help='Use these interpreters to run the tests, ' + 'separated by spaces.') +parser.add_argument( +    '--srcdir', +    type=str, +    default=os.environ.get("srcdir", ""), +    help='Location of the tests.') +parser.add_argument( +    '--builddir', +    type=str, +    default=os.environ.get("abs_builddir", ""), +    help='Location of the tests.') +parser.add_argument( +    '--python-libdir', +    type=str, +    default=None, +    help='Optional location of the in-tree module lib directory.') +parser.add_argument( +    '--parallel', +    action="store_true", +    default=False, +    help='Ignored.  For compatibility with run-tests.scm.')  args = parser.parse_args()  if not args.interpreters: @@ -64,26 +78,31 @@ if not args.interpreters:  out = sys.stdout if args.verbose else None  err = sys.stderr if args.verbose else None +  def status_to_str(code):      return {0: "PASS", 77: "SKIP", 99: "ERROR"}.get(code, "FAIL") +  results = list()  for interpreter in args.interpreters: -    version = subprocess.check_output( -        [interpreter, "-c", "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"]).strip().decode() +    version = subprocess.check_output([ +        interpreter, "-c", +        "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))" +    ]).strip().decode()      if args.python_libdir:          python_libdir = args.python_libdir      else: -        pattern = os.path.join(args.builddir, "..", -                               "{0}-gpg".format(os.path.basename(interpreter)), -                               "lib*") +        pattern = os.path.join(args.builddir, "..", "{0}-gpg".format( +            os.path.basename(interpreter)), "lib*")          libdirs = glob.glob(pattern)          if len(libdirs) == 0: -            sys.exit("Build directory matching {0!r} not found.".format(pattern)) +            sys.exit( +                "Build directory matching {0!r} not found.".format(pattern))          elif len(libdirs) > 1: -            sys.exit("Multiple build directories matching {0!r} found: {1}".format( -                pattern, libdirs)) +            sys.exit( +                "Multiple build directories matching {0!r} found: {1}".format( +                    pattern, libdirs))          python_libdir = libdirs[0]      env = dict(os.environ) @@ -95,16 +114,22 @@ for interpreter in args.interpreters:      for test in args.tests:          status = subprocess.call(              [interpreter, os.path.join(args.srcdir, test)], -            env=env, stdout=out, stderr=err) +            env=env, +            stdout=out, +            stderr=err)          if not args.quiet:              print("{0}: {1}".format(status_to_str(status), test))          results.append(status) +  def count(status):      return len(list(filter(lambda x: x == status, results))) + +  def failed():      return len(list(filter(lambda x: x not in (0, 77, 99), results))) +  if not args.quiet:      print("{0} tests run, {1} succeeded, {2} failed, {3} skipped.".format(          len(results), count(0), failed(), count(77)))  | 
