| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Utility to confirm that a JSON summary written by GM contains no failures. | |
| 7 | |
| 8 Usage: | |
| 9 python confirm_no_failures_in_json.py <filename> | |
| 10 """ | |
| 11 | |
| 12 __author__ = 'Elliot Poger' | |
| 13 | |
| 14 | |
| 15 import json | |
| 16 import sys | |
| 17 | |
| 18 | |
| 19 # These constants must be kept in sync with the kJsonKey_ constants in | |
| 20 # gm_expectations.cpp ! | |
| 21 JSONKEY_ACTUALRESULTS = 'actual-results' | |
| 22 JSONKEY_ACTUALRESULTS_FAILED = 'failed' | |
| 23 | |
| 24 # This is the same indent level as used by jsoncpp, just for consistency. | |
| 25 JSON_INDENTLEVEL = 3 | |
| 26 | |
| 27 | |
| 28 def Assert(filepath): | |
| 29 """Raises an exception if the JSON summary at filepath contains any failed | |
| 30 tests, or if we were unable to read the JSON summary.""" | |
| 31 failed_tests = GetFailedTests(filepath) | |
| 32 if failed_tests: | |
| 33 raise Exception('JSON file %s contained these test failures...\n%s' % ( | |
| 34 filepath, json.dumps(failed_tests, indent=JSON_INDENTLEVEL))) | |
| 35 | |
| 36 | |
| 37 def GetFailedTests(filepath): | |
| 38 """Returns the dictionary of failed tests from the JSON file at filepath.""" | |
| 39 json_dict = json.load(open(filepath)) | |
| 40 actual_results = json_dict[JSONKEY_ACTUALRESULTS] | |
| 41 return actual_results[JSONKEY_ACTUALRESULTS_FAILED] | |
| 42 | |
| 43 | |
| 44 if '__main__' == __name__: | |
| 45 if len(sys.argv) != 2: | |
| 46 raise Exception('usage: %s <input-json-filepath>' % sys.argv[0]) | |
| 47 Assert(sys.argv[1]) | |
| OLD | NEW |