Patchwork [3,of,5] run-tests: stop explicit expansion of time data

login
register
mail settings
Submitter Pierre-Yves David
Date May 8, 2015, 6:53 p.m.
Message ID <d875416ce6d6ce611ec5.1431111236@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8981/
State Accepted
Headers show

Comments

Pierre-Yves David - May 8, 2015, 6:53 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1431056751 25200
#      Thu May 07 20:45:51 2015 -0700
# Node ID d875416ce6d6ce611ec5005d05e89faf07e8ce1a
# Parent  a91fdefde29532d3d947422947327867015da537
run-tests: stop explicit expansion of time data

We are about to record more complex time related data, this would requires
repeated changes of every loop touching times data. That would also extend such
line to a point were things become too long. Instead we iterate on each entry
and expand value in the loops. We keep intermediate variables in most case to
preserve readability.

The loop producing json data do a strange inversion for no obvious reason. We
preserved that for now and will fix it in another changeset.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1487,12 +1487,11 @@  class TextTestRunner(unittest.TextTestRu
             self.stream.writeln('Errored %s: %s' % (test.name, msg))
 
         if self._runner.options.xunit:
             xuf = open(self._runner.options.xunit, 'wb')
             try:
-                timesd = dict(
-                    (test, real) for test, cuser, csys, real in result.times)
+                timesd = dict((t[0], t[3]) for t in result.times)
                 doc = minidom.Document()
                 s = doc.createElement('testsuite')
                 s.setAttribute('name', 'run-tests')
                 s.setAttribute('tests', str(result.testsRun))
                 s.setAttribute('errors', "0") # TODO
@@ -1524,11 +1523,13 @@  class TextTestRunner(unittest.TextTestRu
                 raise ImportError("json module not installed")
             jsonpath = os.path.join(self._runner._testdir, 'report.json')
             fp = open(jsonpath, 'w')
             try:
                 timesd = {}
-                for test, cuser, csys, real in result.times:
+                for tdata in result.times:
+                    test = tdata[0]
+                    real, cuser, csys = tdata[3], tdata[1], tdata[2]
                     timesd[test] = (real, cuser, csys)
 
                 outcome = {}
                 groups = [('success', ((tc, None) for tc in result.successes)),
                           ('failure', result.failures),
@@ -1566,11 +1567,13 @@  class TextTestRunner(unittest.TextTestRu
         self.stream.writeln('# Producing time report')
         times.sort(key=lambda t: (t[3]))
         cols = '%7.3f %7.3f %7.3f   %s'
         self.stream.writeln('%-7s %-7s %-7s   %s' % ('cuser', 'csys', 'real',
                     'Test'))
-        for test, cuser, csys, real in times:
+        for tdata in times:
+            test = tdata[0]
+            cuser, csys, real = tdata[1:4]
             self.stream.writeln(cols % (cuser, csys, real, test))
 
 class TestRunner(object):
     """Holds context for executing tests.