Chromium Code Reviews| Index: tools/jsondiff.py |
| diff --git a/tools/jsondiff.py b/tools/jsondiff.py |
| index dd89c6d8dc7d54f6a37ff872d7d0d9bba37e8c57..34808b1cbc0dc351ba8d771f21ad1706909262ae 100755 |
| --- a/tools/jsondiff.py |
| +++ b/tools/jsondiff.py |
| @@ -54,8 +54,8 @@ class GMDiffer(object): |
| else: |
| return open(filepath, 'r').read() |
| - def _GetExpectedResults(self, filepath): |
| - """Returns the dictionary of expected results from a JSON file, |
| + def _GetExpectedResults(self, contents): |
| + """Returns the dictionary of expected results from a JSON string, |
| in this form: |
| { |
| @@ -75,7 +75,6 @@ class GMDiffer(object): |
| returned dictionary. |
| """ |
| result_dict = {} |
| - contents = self._GetFileContentsAsString(filepath) |
| json_dict = gm_json.LoadFromString(contents) |
| all_expectations = json_dict[gm_json.JSONKEY_EXPECTEDRESULTS] |
| for test_name in all_expectations.keys(): |
| @@ -96,8 +95,8 @@ class GMDiffer(object): |
| result_dict[test_name] = digest_pair[1] |
| return result_dict |
| - def _GetActualResults(self, filepath): |
| - """Returns the dictionary of actual results from a JSON file, |
| + def _GetActualResults(self, contents): |
| + """Returns the dictionary of actual results from a JSON string, |
| in this form: |
| { |
| @@ -116,7 +115,6 @@ class GMDiffer(object): |
| returned dictionary. |
| """ |
| result_dict = {} |
| - contents = self._GetFileContentsAsString(filepath) |
| json_dict = gm_json.LoadFromString(contents) |
| all_result_types = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| for result_type in all_result_types.keys(): |
| @@ -152,11 +150,26 @@ class GMDiffer(object): |
| If newfile is not specified, then 'new' is the actual results within |
| oldfile. |
| """ |
| - old_results = self._GetExpectedResults(oldfile) |
| + old_results = self._GetExpectedResults(self._GetFileContentsAsString(oldfile)) |
|
epoger
2013/08/02 14:33:06
I think it would be a bit cleaner to have this met
Zach Reizner
2013/08/02 21:30:58
Done.
|
| if newfile: |
| - new_results = self._GetExpectedResults(newfile) |
| + new_results = self._GetExpectedResults(self._GetFileContentsAsString(newfile)) |
| else: |
| - new_results = self._GetActualResults(oldfile) |
| + new_results = self._GetActualResults(self._GetFileContentsAsString(oldfile)) |
| + return self._DictionaryDiff(old_results, new_results) |
| + |
| + def GenerateDiffDictFromStrings(self, oldjson, newjson=None): |
| + """Generate a dictionary showing the diffs: |
| + old = expectations within oldjson |
| + new = expectations within newjson |
| + |
| + If newfile is not specified, then 'new' is the actual results within |
| + oldfile. |
| + """ |
| + old_results = self._GetExpectedResults(oldjson) |
| + if newjson: |
| + new_results = self._GetExpectedResults(newjson) |
| + else: |
| + new_results = self._GetActualResults(oldjson) |
| return self._DictionaryDiff(old_results, new_results) |