blob: 6ba3a261a535c54529b6fa559622d64c35aea568 [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.com4075fd42013-06-04 17:50:36 +000026def LoadFromString(file_contents):
epoger@google.com9d331542013-05-28 15:25:38 +000027 """Loads the JSON summary written out by the GM tool.
28 Returns a dictionary keyed by the values listed as JSONKEY_ constants
29 above."""
epoger@google.com4075fd42013-06-04 17:50:36 +000030 # TODO(epoger): we should add a version number to the JSON file to ensure
epoger@google.com9d331542013-05-28 15:25:38 +000031 # that the writer and reader agree on the schema (raising an exception
32 # otherwise).
epoger@google.com4075fd42013-06-04 17:50:36 +000033 json_dict = json.loads(file_contents)
epoger@google.com9d331542013-05-28 15:25:38 +000034 return json_dict
epoger@google.com4075fd42013-06-04 17:50:36 +000035
36def LoadFromFile(file_path):
37 """Loads the JSON summary written out by the GM tool.
38 Returns a dictionary keyed by the values listed as JSONKEY_ constants
39 above."""
40 file_contents = open(file_path, 'r').read()
41 return LoadFromString(file_contents)