[PATCH 063 of 179 tests-refactor] run-tests: move times global into TestRunner

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 13:38:20 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397977146 25200
#      Sat Apr 19 23:59:06 2014 -0700
# Branch stable
# Node ID c1607865d400300adb74bfc4723b735c87b56671
# Parent  af393a79440d034e45e54921cbff4be164d7aa33
run-tests: move times global into TestRunner

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -390,16 +390,17 @@ class Test(object):
     Test instances can be run multiple times via run(). However, multiple
     runs cannot be run concurrently.
     """
 
     def __init__(self, runner, test, count, refpath):
         path = os.path.join(runner.testdir, test)
         errpath = os.path.join(runner.testdir, '%s.err' % test)
 
+        self._runner = runner
         self._testdir = runner.testdir
         self._test = test
         self._path = path
         self._options = runner.options
         self._count = count
         self._daemonpids = []
         self._refpath = refpath
         self._errpath = errpath
@@ -539,17 +540,17 @@ class Test(object):
         vlog("# Ret was:", ret)
 
         if not options.verbose:
             iolock.acquire()
             sys.stdout.write(res[0])
             sys.stdout.flush()
             iolock.release()
 
-        times.append((self._test, duration))
+        self._runner.times.append((self._test, duration))
 
         return res
 
     def _run(self, testtmp, replacements, env):
         # This should be implemented in child classes to run tests.
         return self._skip('unknown test type')
 
     def _getreplacements(self, testtmp):
@@ -984,17 +985,16 @@ def _gethgpath():
     pipe = os.popen(cmd % PYTHON)
     try:
         _hgpath = pipe.read().strip()
     finally:
         pipe.close()
     return _hgpath
 
 results = {'.':[], '!':[], '~': [], 's':[], 'i':[]}
-times = []
 iolock = threading.Lock()
 abort = False
 
 def scheduletests(runner, tests):
     jobs = runner.options.jobs
     done = queue.Queue()
     running = 0
     count = 0
@@ -1101,16 +1101,17 @@ class TestRunner(object):
         self.options = None
         self.testdir = None
         self.hgtmp = None
         self.inst = None
         self.bindir = None
         self.tmpbinddir = None
         self.pythondir = None
         self.coveragefile = None
+        self.times = [] # Holds execution times of tests.
         self._createdfiles = []
 
     def gettest(self, test, count):
         """Obtain a Test by looking at its filename.
 
         Returns a Test instance. The Test may not be runnable if it doesn't
         map to a known type.
         """
@@ -1267,20 +1268,20 @@ class TestRunner(object):
         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)
+        self.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:
+        for test, timetaken in self.times:
             print cols % (timetaken, test)
 
     def outputcoverage(self):
         vlog('# Producing coverage report')
         os.chdir(self.pythondir)
 
         def covrun(*args):
             cmd = 'coverage %s' % ' '.join(args)


More information about the Mercurial-devel mailing list