зеркало из https://github.com/mozilla/moz-skia.git
gm_json.py: add ability to load JSON file from a string, not just a local file
This will make it easier to read JSON files from new sources (HTTP, etc.) R=scroggo@google.com Review URL: https://codereview.chromium.org/15934018 git-svn-id: http://skia.googlecode.com/svn/trunk@9431 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
a9133bbcc6
Коммит
4075fd4851
|
@ -94,7 +94,7 @@ def Display(filepath):
|
||||||
}
|
}
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
json_dict = gm_json.Load(filepath)
|
json_dict = gm_json.LoadFromFile(filepath)
|
||||||
actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
|
actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
|
||||||
for label, accumulator in results_map.iteritems():
|
for label, accumulator in results_map.iteritems():
|
||||||
results = actual_results[label]
|
results = actual_results[label]
|
||||||
|
|
|
@ -23,12 +23,19 @@ JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored'
|
||||||
JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
|
JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
|
||||||
JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
|
JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
|
||||||
|
|
||||||
def Load(filepath):
|
def LoadFromString(file_contents):
|
||||||
"""Loads the JSON summary written out by the GM tool.
|
"""Loads the JSON summary written out by the GM tool.
|
||||||
Returns a dictionary keyed by the values listed as JSONKEY_ constants
|
Returns a dictionary keyed by the values listed as JSONKEY_ constants
|
||||||
above."""
|
above."""
|
||||||
# In the future, we should add a version number to the JSON file to ensure
|
# TODO(epoger): we should add a version number to the JSON file to ensure
|
||||||
# that the writer and reader agree on the schema (raising an exception
|
# that the writer and reader agree on the schema (raising an exception
|
||||||
# otherwise).
|
# otherwise).
|
||||||
json_dict = json.load(open(filepath))
|
json_dict = json.loads(file_contents)
|
||||||
return json_dict
|
return json_dict
|
||||||
|
|
||||||
|
def LoadFromFile(file_path):
|
||||||
|
"""Loads the JSON summary written out by the GM tool.
|
||||||
|
Returns a dictionary keyed by the values listed as JSONKEY_ constants
|
||||||
|
above."""
|
||||||
|
file_contents = open(file_path, 'r').read()
|
||||||
|
return LoadFromString(file_contents)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче