[PATCH 2 of 5] run-tests: factor json entry creation logic

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri May 8 13:53:55 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1431107478 25200
#      Fri May 08 10:51:18 2015 -0700
# Node ID a91fdefde29532d3d947422947327867015da537
# Parent  dccc3de8c055f386a1dbfe72e86091251dbd0b50
run-tests: factor json entry creation logic

We are about to add more timing related information to each entry. Having a
single place where the json entry is created is going to be much simpler.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1528,30 +1528,20 @@ class TextTestRunner(unittest.TextTestRu
                 timesd = {}
                 for test, cuser, csys, real in result.times:
                     timesd[test] = (real, cuser, csys)
 
                 outcome = {}
-                for tc in result.successes:
-                    testresult = {'result': 'success',
-                                  'time': ('%0.3f' % timesd[tc.name][0]),
-                                  'cuser': ('%0.3f' % timesd[tc.name][1]),
-                                  'csys': ('%0.3f' % timesd[tc.name][2])}
-                    outcome[tc.name] = testresult
-
-                for tc, error in result.failures:
-                    testresult = {'result': 'failure',
-                                  'time': ('%0.3f' % timesd[tc.name][0]),
-                                  'cuser': ('%0.3f' % timesd[tc.name][1]),
-                                  'csys': ('%0.3f' % timesd[tc.name][2])}
-                    outcome[tc.name] = testresult
-
-                for tc, reason in result.skipped:
-                    testresult = {'result': 'skip',
-                                  'time': ('%0.3f' % timesd[tc.name][0]),
-                                  'cuser': ('%0.3f' % timesd[tc.name][1]),
-                                  'csys': ('%0.3f' % timesd[tc.name][2])}
-                    outcome[tc.name] = testresult
+                groups = [('success', ((tc, None) for tc in result.successes)),
+                          ('failure', result.failures),
+                          ('skip', result.skipped)]
+                for res, testcases in groups:
+                    for tc, __ in testcases:
+                        testresult = {'result': res,
+                                      'time': ('%0.3f' % timesd[tc.name][0]),
+                                      'cuser': ('%0.3f' % timesd[tc.name][1]),
+                                      'csys': ('%0.3f' % timesd[tc.name][2])}
+                        outcome[tc.name] = testresult
 
                 jsonout = json.dumps(outcome, sort_keys=True, indent=4)
                 fp.writelines(("testreport =", jsonout))
             finally:
                 fp.close()


More information about the Mercurial-devel mailing list