| epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 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 | """Schema of the JSON summary file written out by the GM tool. |
| 7 | |
| 8 | This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! |
| 9 | """ |
| 10 | |
| 11 | __author__ = 'Elliot Poger' |
| 12 | |
| 13 | |
| 14 | # system-level imports |
| 15 | import json |
| 16 | |
| 17 | |
| 18 | # These constants must be kept in sync with the kJsonKey_ constants in |
| 19 | # gm_expectations.cpp ! |
| 20 | JSONKEY_ACTUALRESULTS = 'actual-results' |
| 21 | JSONKEY_ACTUALRESULTS_FAILED = 'failed' |
| 22 | JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored' |
| 23 | JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison' |
| 24 | JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded' |
| 25 | |
| epoger@google.com | 53953b4 | 2013-07-02 20:22:27 +0000 | [diff] [blame^] | 26 | JSONKEY_EXPECTEDRESULTS = 'expected-results' |
| 27 | JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests' |
| 28 | JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure' |
| 29 | |
| 30 | JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5' |
| 31 | |
| epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 32 | def LoadFromString(file_contents): |
| epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 33 | """Loads the JSON summary written out by the GM tool. |
| 34 | Returns a dictionary keyed by the values listed as JSONKEY_ constants |
| 35 | above.""" |
| epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 36 | # TODO(epoger): we should add a version number to the JSON file to ensure |
| epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 37 | # that the writer and reader agree on the schema (raising an exception |
| 38 | # otherwise). |
| epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 39 | json_dict = json.loads(file_contents) |
| epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 40 | return json_dict |
| epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 41 | |
| 42 | def LoadFromFile(file_path): |
| 43 | """Loads the JSON summary written out by the GM tool. |
| 44 | Returns a dictionary keyed by the values listed as JSONKEY_ constants |
| 45 | above.""" |
| 46 | file_contents = open(file_path, 'r').read() |
| 47 | return LoadFromString(file_contents) |