Chromium Code Reviews| Index: gm/confirm_no_failures_in_json.py |
| =================================================================== |
| --- gm/confirm_no_failures_in_json.py (revision 0) |
| +++ gm/confirm_no_failures_in_json.py (revision 0) |
| @@ -0,0 +1,46 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Utility to confirm that a JSON summary written by GM contains no failures. |
| + |
| +Usage: |
| + python confirm_no_failures_in_json.py <filename> |
| +""" |
| + |
| +__author__ = 'Elliot Poger' |
| + |
| + |
| +import json |
| +import sys |
| + |
| + |
| +# These constants must be kept in sync with the kJsonKey_ constants in |
| +# gm_expectations.cpp ! |
| +JSONKEY_ACTUALRESULTS = 'actual-results' |
| +JSONKEY_ACTUALRESULTS_FAILED = 'failed' |
| + |
| +# This is the same indent level as used by jsoncpp, just for consistency. |
| +JSON_INDENTLEVEL = 3 |
| + |
|
rmistry
2013/05/13 12:25:39
Nit: Please add one more new line here.
epoger
2013/05/14 15:03:00
Done.
|
| +def Assert(filepath): |
|
rmistry
2013/05/13 12:25:39
Should this function (and the one below) be privat
epoger
2013/05/14 15:03:00
I actually do envision them being used by other mo
rmistry
2013/05/14 18:36:44
Yes.
|
| + """Raises an exception if the JSON summary at filepath contains any failed |
| + tests, or if we were unable to read the JSON summary.""" |
| + failed_tests = GetFailedTests(filepath) |
| + if failed_tests: |
| + raise Exception('JSON file %s contained these test failures...\n%s' % ( |
| + filepath, json.dumps(failed_tests, indent=JSON_INDENTLEVEL))) |
| + |
| + |
| +def GetFailedTests(filepath): |
| + """Returns the dictionary of failed tests from the JSON file at filepath.""" |
| + json_dict = json.load(open(filepath)) |
| + actual_results = json_dict.get(JSONKEY_ACTUALRESULTS) |
|
rmistry
2013/05/13 12:25:39
If the json_dict does not have an 'actual-results'
epoger
2013/05/14 15:03:00
That's much better, thanks! It also signals an er
rmistry
2013/05/14 18:36:44
The failed key will always be present? or are we a
epoger
2013/05/14 18:56:08
The "failed" key should always be present... if th
|
| + return actual_results.get(JSONKEY_ACTUALRESULTS_FAILED) |
| + |
| + |
| +if '__main__' == __name__: |
| + if len(sys.argv) != 2: |
| + raise Exception('usage: %s <input-json-filepath>' % sys.argv[0]) |
| + Assert(sys.argv[1]) |