| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Utility to display a summary of JSON-format GM results, and exit with | 6 """Utility to display a summary of JSON-format GM results, and exit with |
| 7 a nonzero errorcode if there were non-ignored failures in the GM results. | 7 a nonzero errorcode if there were non-ignored failures in the GM results. |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 python display_json_results.py <filename> | 10 python display_json_results.py <filename> |
| 11 | 11 |
| 12 TODO(epoger): We may want to add flags to set the following: | 12 TODO(epoger): We may want to add flags to set the following: |
| 13 - which error types cause a nonzero return code | 13 - which error types cause a nonzero return code |
| 14 - maximum number of tests to list for any one ResultAccumulator | 14 - maximum number of tests to list for any one ResultAccumulator |
| 15 (to keep the output reasonably short) | 15 (to keep the output reasonably short) |
| 16 """ | 16 """ |
| 17 | 17 |
| 18 __author__ = 'Elliot Poger' | 18 __author__ = 'Elliot Poger' |
| 19 | 19 |
| 20 | 20 |
| 21 import json | 21 # system-level imports |
| 22 import sys | 22 import sys |
| 23 | 23 |
| 24 | 24 # local imports |
| 25 # These constants must be kept in sync with the kJsonKey_ constants in | 25 import gm_json |
| 26 # gm_expectations.cpp ! | |
| 27 JSONKEY_ACTUALRESULTS = 'actual-results' | |
| 28 JSONKEY_ACTUALRESULTS_FAILED = 'failed' | |
| 29 JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored' | |
| 30 JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison' | |
| 31 JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded' | |
| 32 | 26 |
| 33 | 27 |
| 34 class ResultAccumulator(object): | 28 class ResultAccumulator(object): |
| 35 """Object that accumulates results of a given type, and can generate a | 29 """Object that accumulates results of a given type, and can generate a |
| 36 summary upon request.""" | 30 summary upon request.""" |
| 37 | 31 |
| 38 def __init__(self, name, do_list, do_fail): | 32 def __init__(self, name, do_list, do_fail): |
| 39 """name: name of the category this result type falls into | 33 """name: name of the category this result type falls into |
| 40 do_list: whether to list all of the tests with this results type | 34 do_list: whether to list all of the tests with this results type |
| 41 do_fail: whether to return with nonzero exit code if there are any | 35 do_fail: whether to return with nonzero exit code if there are any |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return summary | 72 return summary |
| 79 | 73 |
| 80 | 74 |
| 81 def Display(filepath): | 75 def Display(filepath): |
| 82 """Displays a summary of the results in a JSON file. | 76 """Displays a summary of the results in a JSON file. |
| 83 Returns True if the results are free of any significant failures. | 77 Returns True if the results are free of any significant failures. |
| 84 filepath: (string) path to JSON file""" | 78 filepath: (string) path to JSON file""" |
| 85 | 79 |
| 86 # Map labels within the JSON file to the ResultAccumulator for each label. | 80 # Map labels within the JSON file to the ResultAccumulator for each label. |
| 87 results_map = { | 81 results_map = { |
| 88 JSONKEY_ACTUALRESULTS_FAILED: | 82 gm_json.JSONKEY_ACTUALRESULTS_FAILED: |
| 89 ResultAccumulator(name='ExpectationsMismatch', | 83 ResultAccumulator(name='ExpectationsMismatch', |
| 90 do_list=True, do_fail=True), | 84 do_list=True, do_fail=True), |
| 91 JSONKEY_ACTUALRESULTS_FAILUREIGNORED: | 85 gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED: |
| 92 ResultAccumulator(name='IgnoredExpectationsMismatch', | 86 ResultAccumulator(name='IgnoredExpectationsMismatch', |
| 93 do_list=True, do_fail=False), | 87 do_list=True, do_fail=False), |
| 94 JSONKEY_ACTUALRESULTS_NOCOMPARISON: | 88 gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON: |
| 95 ResultAccumulator(name='MissingExpectations', | 89 ResultAccumulator(name='MissingExpectations', |
| 96 do_list=False, do_fail=False), | 90 do_list=False, do_fail=False), |
| 97 JSONKEY_ACTUALRESULTS_SUCCEEDED: | 91 gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED: |
| 98 ResultAccumulator(name='Passed', | 92 ResultAccumulator(name='Passed', |
| 99 do_list=False, do_fail=False), | 93 do_list=False, do_fail=False), |
| 100 } | 94 } |
| 101 | 95 |
| 102 success = True | 96 success = True |
| 103 json_dict = json.load(open(filepath)) | 97 json_dict = gm_json.Load(filepath) |
| 104 actual_results = json_dict[JSONKEY_ACTUALRESULTS] | 98 actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 105 for label, accumulator in results_map.iteritems(): | 99 for label, accumulator in results_map.iteritems(): |
| 106 results = actual_results[label] | 100 results = actual_results[label] |
| 107 if results: | 101 if results: |
| 108 for result in results: | 102 for result in results: |
| 109 accumulator.AddResult(result) | 103 accumulator.AddResult(result) |
| 110 print accumulator.GetSummaryLine() | 104 print accumulator.GetSummaryLine() |
| 111 if accumulator.ShouldSignalFailure(): | 105 if accumulator.ShouldSignalFailure(): |
| 112 success = False | 106 success = False |
| 113 print '(results marked with [*] will cause nonzero return value)' | 107 print '(results marked with [*] will cause nonzero return value)' |
| 114 return success | 108 return success |
| 115 | 109 |
| 116 | 110 |
| 117 if '__main__' == __name__: | 111 if '__main__' == __name__: |
| 118 if len(sys.argv) != 2: | 112 if len(sys.argv) != 2: |
| 119 raise Exception('usage: %s <input-json-filepath>' % sys.argv[0]) | 113 raise Exception('usage: %s <input-json-filepath>' % sys.argv[0]) |
| 120 sys.exit(0 if Display(sys.argv[1]) else 1) | 114 sys.exit(0 if Display(sys.argv[1]) else 1) |
| OLD | NEW |