run-tests: refactor json entry creation logic
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 08 May 2015 10:51:18 -0700
changeset 24981 012b79d549d8
parent 24980 2dadd81c68fb
child 24982 5c15f7e0f52b
run-tests: refactor 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.
tests/run-tests.py
--- a/tests/run-tests.py	Thu May 07 23:20:24 2015 -0700
+++ b/tests/run-tests.py	Fri May 08 10:51:18 2015 -0700
@@ -1535,26 +1535,16 @@
                     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))