blob: cd4198415c550ba4ebf374e7d6c94f3188723616 [file] [log] [blame]
epoger@google.com9d331542013-05-28 15:25:38 +00001#!/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
8This 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
15import json
16
17
18# These constants must be kept in sync with the kJsonKey_ constants in
19# gm_expectations.cpp !
20JSONKEY_ACTUALRESULTS = 'actual-results'
21JSONKEY_ACTUALRESULTS_FAILED = 'failed'
22JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored'
23JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
24JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
25
epoger@google.com53953b42013-07-02 20:22:27 +000026JSONKEY_EXPECTEDRESULTS = 'expected-results'
27JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests'
28JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure'
29
30JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5'
31
epoger@google.com4075fd42013-06-04 17:50:36 +000032def LoadFromString(file_contents):
epoger@google.com9d331542013-05-28 15:25:38 +000033 """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.com4075fd42013-06-04 17:50:36 +000036 # TODO(epoger): we should add a version number to the JSON file to ensure
epoger@google.com9d331542013-05-28 15:25:38 +000037 # that the writer and reader agree on the schema (raising an exception
38 # otherwise).
epoger@google.com4075fd42013-06-04 17:50:36 +000039 json_dict = json.loads(file_contents)
epoger@google.com9d331542013-05-28 15:25:38 +000040 return json_dict
epoger@google.com4075fd42013-06-04 17:50:36 +000041
42def 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)