Patchwork [041,of,179,tests-refactor] run-tests: remove remaining uses of TestResult

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <52c6ed588aa1279f32fd.1399055878@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4536/
State Accepted
Commit 45ab0668d1b2bd53f7214cba3e106627136a7e14
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397967717 25200
#      Sat Apr 19 21:21:57 2014 -0700
# Branch stable
# Node ID 52c6ed588aa1279f32fd8653578d3d284ac65392
# Parent  c89ba785dd16e616d81d1147d1b813a1342fbccb
run-tests: remove remaining uses of TestResult

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -574,25 +574,23 @@  class Test(object):
 
     def __del__(self):
         for entry in self._daemonpids:
             killdaemons(entry)
 
         if self._threadtmp and not self._options.keep_tmpdir:
             shutil.rmtree(self._threadtmp, True)
 
-    def run(self, result):
+    def run(self):
         if not os.path.exists(self._path):
-            result.skipped = True
             return self.skip("Doesn't exist")
 
         options = self._options
         if not (options.whitelisted and self._test in options.whitelisted):
             if options.blacklist and self._test in options.blacklist:
-                result.skipped = True
                 return self.skip('blacklisted')
 
             if options.retest and not os.path.exists('%s.err' % self._test):
                 return self.ignore('not retesting')
 
             if options.keywords:
                 f = open(self._test)
                 t = f.read().lower() + self._test.lower()
@@ -613,57 +611,53 @@  class Test(object):
         testtmp = os.path.join(self._threadtmp, os.path.basename(self._path))
         os.mkdir(testtmp)
         replacements, port = self._getreplacements(testtmp)
         env = self._getenv(testtmp, port)
         self._daemonpids.append(env['DAEMON_PIDS'])
         createhgrc(env['HGRCPATH'], options)
 
         starttime = time.time()
-
-        def updateduration():
-            result.duration = time.time() - starttime
-
         try:
             ret, out = self._run(testtmp, replacements, env)
-            updateduration()
+            duration = time.time() - starttime
         except KeyboardInterrupt:
-            updateduration()
-            log('INTERRUPTED: %s (after %d seconds)' % (self._test,
-                                                        result.duration))
+            duration = time.time() - starttime
+            log('INTERRUPTED: %s (after %d seconds)' % (self._test, duration))
             raise
         except Exception, e:
-            updateduration()
             return self.fail('Exception during execution: %s' % e, 255)
 
         killdaemons(env['DAEMON_PIDS'])
 
         if not options.keep_tmpdir:
             shutil.rmtree(testtmp)
 
         def describe(ret):
             if ret < 0:
                 return 'killed by signal: %d' % -ret
             return 'returned error code %d' % ret
 
+        skipped = False
+
         if ret == SKIPPED_STATUS:
             if out is None: # Debug mode, nothing to parse.
                 missing = ['unknown']
                 failed = None
             else:
                 missing, failed = parsehghaveoutput(out)
 
             if not missing:
                 missing = ['irrelevant']
 
             if failed:
                 res = self.fail('hg have failed checking for %s' % failed[-1],
                                 ret)
             else:
-                result.skipped = True
+                skipped = True
                 res = self.skip(missing[-1])
         elif ret == 'timeout':
             res = self.fail('timed out', ret)
         elif out != self._refout:
             info = {}
             if not options.nodiff:
                 iolock.acquire()
                 if options.view:
@@ -682,31 +676,33 @@  class Test(object):
                 msg += 'output changed'
 
             res = self.fail(msg, ret)
         elif ret:
             res = self.fail(describe(ret), ret)
         else:
             res = self.success()
 
-        if (ret != 0 or out != self._refout) and not result.skipped \
+        if (ret != 0 or out != self._refout) and not skipped \
             and not options.debug:
             f = open(self._errpath, 'wb')
             for line in out:
                 f.write(line)
             f.close()
 
         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))
+
         return res
 
     def _run(self, testtmp, replacements, env):
         raise NotImplemented('Subclasses must implement Test.run()')
 
     def _getreplacements(self, testtmp):
         port = self._options.port + self._count * 3
         r = [
@@ -788,23 +784,16 @@  class Test(object):
         if self._options.verbose:
             log("\nSkipping %s: %s" % (self._path, msg))
 
         return 's', self._test, msg
 
     def ignore(self, msg):
         return 'i', self._test, msg
 
-class TestResult(object):
-    """Holds the result of a test execution."""
-
-    def __init__(self):
-        self.duration = None
-        self.skipped = False
-
 class PythonTest(Test):
     """A Python-based test."""
     def _run(self, testtmp, replacements, env):
         py3kswitch = self._options.py3k_warnings and ' -3' or ''
         cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self._path)
         vlog("# Running", cmd)
         if os.name == 'nt':
             replacements.append((r'\r\n', '\n'))
@@ -1151,20 +1140,17 @@  def runone(options, test, count):
             ref = os.path.join(TESTDIR, test + out)
             break
     else:
         return skip("unknown test type")
 
     vlog("# Test", test)
 
     t = runner(test, testpath, options, count, ref, err)
-    res = TestResult()
-    result = t.run(res)
-
-    times.append((test, res.duration))
+    result = t.run()
 
     del t # For cleanup side-effects.
 
     return result
 
 _hgpath = None
 
 def _gethgpath():