Patchwork [060,of,179,tests-refactor] run-tests: move outputtimes() into TestRunner

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <8a4ad4abe4cd37419363.1399055897@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4556/
State Accepted
Commit d83f4e94512a6bdba9b11baf4cd1c69b7f0a3e7b
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397976479 25200
#      Sat Apr 19 23:47:59 2014 -0700
# Branch stable
# Node ID 8a4ad4abe4cd37419363baab641614c528fa9cd0
# Parent  123095a56a70bec3dc0076e96ebccf51ba6db377
run-tests: move outputtimes() into TestRunner

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -379,24 +379,16 @@  def terminate(proc):
         getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))()
     except OSError:
         pass
 
 def killdaemons(pidfile):
     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
                                logfn=vlog)
 
-def outputtimes(options):
-    vlog('# Producing time report')
-    times.sort(key=lambda t: (t[1], t[0]), reverse=True)
-    cols = '%7.3f   %s'
-    print '\n%-7s   %s' % ('Time', 'Test')
-    for test, timetaken in times:
-        print cols % (timetaken, test)
-
 def outputcoverage(runner):
 
     vlog('# Producing coverage report')
     os.chdir(runner.pythondir)
 
     def covrun(*args):
         cmd = 'coverage %s' % ' '.join(args)
         vlog('# Running: %s' % cmd)
@@ -1119,17 +1111,17 @@  def runtests(runner, tests):
         for s in results['!']:
             print "Failed %s: %s" % s
         runner.checkhglib("Tested")
         print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
             tested, skipped + ignored, warned, failed)
         if results['!']:
             print 'python hash seed:', os.environ['PYTHONHASHSEED']
         if runner.options.time:
-            outputtimes(runner.options)
+            runner.outputtimes()
 
         if runner.options.anycoverage:
             outputcoverage(runner)
     except KeyboardInterrupt:
         failed = True
         print "\ninterrupted!"
 
     if failed:
@@ -1294,16 +1286,24 @@  class TestRunner(object):
         the one we expect it to be.  If not, print a warning to stderr."""
         expecthg = os.path.join(self.pythondir, 'mercurial')
         actualhg = _gethgpath()
         if os.path.abspath(actualhg) != os.path.abspath(expecthg):
             sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
                              '         (expected %s)\n'
                              % (verb, actualhg, expecthg))
 
+    def outputtimes(self):
+        vlog('# Producing time report')
+        times.sort(key=lambda t: (t[1], t[0]), reverse=True)
+        cols = '%7.3f   %s'
+        print '\n%-7s   %s' % ('Time', 'Test')
+        for test, timetaken in times:
+            print cols % (timetaken, test)
+
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)