Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: gm/gm_json.py

Issue 178253010: rebaseline_server: use new intermediate JSON format (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: incorporate Ravi's suggestions Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gm/rebaseline_server/column.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Schema of the JSON summary file written out by the GM tool. 6 """Schema of the JSON summary file written out by the GM tool.
7 7
8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! 8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp !
9 """ 9 """
10 10
11 __author__ = 'Elliot Poger' 11 __author__ = 'Elliot Poger'
12 12
13 13
14 # system-level imports 14 # system-level imports
15 import io 15 import io
16 import json 16 import json
17 import os 17 import os
18 import posixpath
19 import re
18 20
19 21
20 # Key strings used in GM results JSON files (both expected-results.json and 22 # Key strings used in GM results JSON files (both expected-results.json and
21 # actual-results.json). 23 # actual-results.json).
22 # 24 #
23 # These constants must be kept in sync with the kJsonKey_ constants in 25 # NOTE: These constants must be kept in sync with the kJsonKey_ constants in
24 # gm_expectations.cpp ! 26 # gm_expectations.cpp !
25 27
26 28
27 JSONKEY_ACTUALRESULTS = 'actual-results' 29 JSONKEY_ACTUALRESULTS = 'actual-results'
28 30
29 # Tests whose results failed to match expectations. 31 # Tests whose results failed to match expectations.
30 JSONKEY_ACTUALRESULTS_FAILED = 'failed' 32 JSONKEY_ACTUALRESULTS_FAILED = 'failed'
31 33
32 # Tests whose results failed to match expectations, but IGNOREFAILURE causes 34 # Tests whose results failed to match expectations, but IGNOREFAILURE causes
33 # us to take them less seriously. 35 # us to take them less seriously.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 88
87 # Root directory where buildbots store skimage actual results json files. 89 # Root directory where buildbots store skimage actual results json files.
88 SKIMAGE_ACTUALS_BASE_URL = ( 90 SKIMAGE_ACTUALS_BASE_URL = (
89 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals') 91 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals')
90 # Root directory inside trunk where skimage expectations are stored. 92 # Root directory inside trunk where skimage expectations are stored.
91 SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage') 93 SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage')
92 94
93 # Pattern used to assemble each image's filename 95 # Pattern used to assemble each image's filename
94 IMAGE_FILENAME_PATTERN = '(.+)_(.+)\.png' # matches (testname, config) 96 IMAGE_FILENAME_PATTERN = '(.+)_(.+)\.png' # matches (testname, config)
95 97
98 # Pattern used to create image URLs, relative to some base URL.
99 GM_RELATIVE_URL_FORMATTER = '%s/%s/%s.png' # pass in (hash_type, test_name,
100 # hash_digest)
101 GM_RELATIVE_URL_PATTERN = '(.+)/(.+)/(.+).png' # matches (hash_type, test_name,
102 # hash_digest)
103 GM_RELATIVE_URL_RE = re.compile(GM_RELATIVE_URL_PATTERN)
104
105
96 def CreateGmActualUrl(test_name, hash_type, hash_digest, 106 def CreateGmActualUrl(test_name, hash_type, hash_digest,
97 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL): 107 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL):
98 """Return the URL we can use to download a particular version of 108 """Return the URL we can use to download a particular version of
99 the actually-generated image for this particular GM test. 109 the actually-generated image for this particular GM test.
100 110
101 test_name: name of the test, e.g. 'perlinnoise' 111 test_name: name of the test, e.g. 'perlinnoise'
102 hash_type: string indicating the hash type used to generate hash_digest, 112 hash_type: string indicating the hash type used to generate hash_digest,
103 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5 113 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5
104 hash_digest: the hash digest of the image to retrieve 114 hash_digest: the hash digest of the image to retrieve
105 gm_actuals_root_url: root url where actual images are stored 115 gm_actuals_root_url: root url where actual images are stored
106 """ 116 """
107 # TODO(epoger): Maybe use url_or_path.join() so that, for testing, this can 117 return posixpath.join(
108 # return either a URL or a local filepath? 118 gm_actuals_root_url, CreateGmRelativeUrl(
109 return '%s/%s/%s/%s.png' % (gm_actuals_root_url, hash_type, test_name, 119 test_name=test_name, hash_type=hash_type, hash_digest=hash_digest))
110 hash_digest) 120
121
122 def CreateGmRelativeUrl(test_name, hash_type, hash_digest):
123 """Returns a relative URL pointing at a test result's image.
124
125 Returns the URL we can use to download a particular version of
126 the actually-generated image for this particular GM test,
127 relative to the URL root.
128
129 Args:
130 test_name: name of the test, e.g. 'perlinnoise'
131 hash_type: string indicating the hash type used to generate hash_digest,
132 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5
133 hash_digest: the hash digest of the image to retrieve
134 """
135 return GM_RELATIVE_URL_FORMATTER % (hash_type, test_name, hash_digest)
136
137
138 def SplitGmRelativeUrl(url):
139 """Splits the relative URL into (test_name, hash_type, hash_digest) tuple.
140
141 This is the inverse of CreateGmRelativeUrl().
142
143 Args:
144 url: a URL generated with CreateGmRelativeUrl().
145
146 Returns: (test_name, hash_type, hash_digest) tuple.
147 """
148 hash_type, test_name, hash_digest = GM_RELATIVE_URL_RE.match(url).groups()
149 return (test_name, hash_type, hash_digest)
150
111 151
112 def LoadFromString(file_contents): 152 def LoadFromString(file_contents):
113 """Loads the JSON summary written out by the GM tool. 153 """Loads the JSON summary written out by the GM tool.
114 Returns a dictionary keyed by the values listed as JSONKEY_ constants 154 Returns a dictionary keyed by the values listed as JSONKEY_ constants
115 above.""" 155 above."""
116 # TODO(epoger): we should add a version number to the JSON file to ensure 156 # TODO(epoger): we should add a version number to the JSON file to ensure
117 # that the writer and reader agree on the schema (raising an exception 157 # that the writer and reader agree on the schema (raising an exception
118 # otherwise). 158 # otherwise).
119 json_dict = json.loads(file_contents) 159 json_dict = json.loads(file_contents)
120 return json_dict 160 return json_dict
121 161
162
122 def LoadFromFile(file_path): 163 def LoadFromFile(file_path):
123 """Loads the JSON summary written out by the GM tool. 164 """Loads the JSON summary written out by the GM tool.
124 Returns a dictionary keyed by the values listed as JSONKEY_ constants 165 Returns a dictionary keyed by the values listed as JSONKEY_ constants
125 above.""" 166 above."""
126 file_contents = open(file_path, 'r').read() 167 file_contents = open(file_path, 'r').read()
127 return LoadFromString(file_contents) 168 return LoadFromString(file_contents)
128 169
170
129 def WriteToFile(json_dict, file_path): 171 def WriteToFile(json_dict, file_path):
130 """Writes the JSON summary in json_dict out to file_path. 172 """Writes the JSON summary in json_dict out to file_path.
131 173
132 The file is written Unix-style (each line ends with just LF, not CRLF); 174 The file is written Unix-style (each line ends with just LF, not CRLF);
133 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons.""" 175 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons."""
134 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile: 176 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile:
135 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True, 177 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True,
136 indent=2))) 178 indent=2)))
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/column.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698