| OLD | NEW |
| 1 # Copyright (c) 2010, Google Inc. All rights reserved. | 1 # Copyright (c) 2010, Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import logging | 30 import logging |
| 31 | 31 |
| 32 from webkitpy.common.memoized import memoized | 32 from webkitpy.common.memoized import memoized |
| 33 from webkitpy.layout_tests.layout_package import json_results_generator | 33 from webkitpy.layout_tests.layout_package import json_results_generator |
| 34 from webkitpy.layout_tests.models import test_expectations | 34 from webkitpy.layout_tests.models import test_expectations |
| 35 from webkitpy.layout_tests.models.test_expectations import TestExpectations | 35 from webkitpy.layout_tests.models.test_expectations import TestExpectations |
| 36 | 36 |
| 37 _log = logging.getLogger(__name__) | 37 _log = logging.getLogger(__name__) |
| 38 | 38 |
| 39 | 39 |
| 40 # These are helper functions for navigating the results json structure. | 40 class LayoutTestResult(object): |
| 41 def for_each_test(tree, handler, prefix=''): | |
| 42 for key in tree: | |
| 43 new_prefix = (prefix + '/' + key) if prefix else key | |
| 44 if 'actual' not in tree[key]: | |
| 45 for_each_test(tree[key], handler, new_prefix) | |
| 46 else: | |
| 47 handler(new_prefix, tree[key]) | |
| 48 | |
| 49 | |
| 50 def result_for_test(tree, test): | |
| 51 parts = test.split('/') | |
| 52 for part in parts: | |
| 53 if part not in tree: | |
| 54 return None | |
| 55 tree = tree[part] | |
| 56 return tree | |
| 57 | |
| 58 | |
| 59 class JSONTestResult(object): | |
| 60 | 41 |
| 61 def __init__(self, test_name, result_dict): | 42 def __init__(self, test_name, result_dict): |
| 62 self._test_name = test_name | 43 self._test_name = test_name |
| 63 self._result_dict = result_dict | 44 self._result_dict = result_dict |
| 64 | 45 |
| 46 def result_dict(self): |
| 47 return self._result_dict |
| 48 |
| 49 def test_name(self): |
| 50 return self._test_name |
| 51 |
| 65 def did_pass_or_run_as_expected(self): | 52 def did_pass_or_run_as_expected(self): |
| 66 return self.did_pass() or self.did_run_as_expected() | 53 return self.did_pass() or self.did_run_as_expected() |
| 67 | 54 |
| 68 def did_pass(self): | 55 def did_pass(self): |
| 69 return test_expectations.PASS in self._actual_as_tokens() | 56 return 'PASS' in self.actual_results() |
| 70 | 57 |
| 71 def did_run_as_expected(self): | 58 def did_run_as_expected(self): |
| 72 return 'is_unexpected' not in self._result_dict | 59 return 'is_unexpected' not in self._result_dict |
| 73 | 60 |
| 74 def _tokenize(self, results_string): | 61 def is_missing_image(self): |
| 75 tokens = map(TestExpectations.expectation_from_string, results_string.sp
lit(' ')) | 62 return 'is_missing_image' in self._result_dict |
| 76 if None in tokens: | |
| 77 _log.warning("Unrecognized result in %s" % results_string) | |
| 78 return set(tokens) | |
| 79 | 63 |
| 80 @memoized | 64 def is_missing_text(self): |
| 81 def _actual_as_tokens(self): | 65 return 'is_missing_text' in self._result_dict |
| 82 actual_results = self._result_dict['actual'] | 66 |
| 83 return self._tokenize(actual_results) | 67 def is_missing_audio(self): |
| 68 return 'is_missing_audio' in self._result_dict |
| 69 |
| 70 def actual_results(self): |
| 71 return self._result_dict['actual'] |
| 72 |
| 73 def expected_results(self): |
| 74 return self._result_dict['expected'] |
| 84 | 75 |
| 85 | 76 |
| 86 # FIXME: This should be unified with ResultsSummary or other NRWT layout tests c
ode | 77 # FIXME: This should be unified with ResultsSummary or other NRWT layout tests c
ode |
| 87 # in the layout_tests package. | 78 # in the layout_tests package. |
| 88 # This doesn't belong in common.net, but we don't have a better place for it yet
. | 79 # This doesn't belong in common.net, but we don't have a better place for it yet
. |
| 89 class LayoutTestResults(object): | 80 class LayoutTestResults(object): |
| 90 | 81 |
| 91 @classmethod | 82 @classmethod |
| 92 def results_from_string(cls, string): | 83 def results_from_string(cls, string): |
| 93 if not string: | 84 if not string: |
| 94 return None | 85 return None |
| 95 | 86 |
| 96 content_string = json_results_generator.strip_json_wrapper(string) | 87 content_string = json_results_generator.strip_json_wrapper(string) |
| 97 json_dict = json.loads(content_string) | 88 json_dict = json.loads(content_string) |
| 98 if not json_dict: | 89 if not json_dict: |
| 99 return None | 90 return None |
| 91 |
| 100 return cls(json_dict) | 92 return cls(json_dict) |
| 101 | 93 |
| 102 def __init__(self, parsed_json): | 94 def __init__(self, parsed_json): |
| 103 self._results = parsed_json | 95 self._results = parsed_json |
| 104 | 96 |
| 105 def run_was_interrupted(self): | 97 def run_was_interrupted(self): |
| 106 return self._results["interrupted"] | 98 return self._results["interrupted"] |
| 107 | 99 |
| 108 def builder_name(self): | 100 def builder_name(self): |
| 109 return self._results["builder_name"] | 101 return self._results["builder_name"] |
| 110 | 102 |
| 111 def chromium_revision(self): | 103 def chromium_revision(self): |
| 112 return int(self._results["chromium_revision"]) | 104 return int(self._results["chromium_revision"]) |
| 113 | 105 |
| 114 def actual_results(self, test): | 106 def result_for_test(self, test): |
| 115 result = result_for_test(self._results["tests"], test) | 107 parts = test.split("/") |
| 116 if result: | 108 tree = self._test_result_tree() |
| 117 return result["actual"] | 109 for part in parts: |
| 118 return "" | 110 if part not in tree: |
| 111 return None |
| 112 tree = tree[part] |
| 113 return LayoutTestResult(test, tree) |
| 114 |
| 115 def for_each_test(self, handler): |
| 116 LayoutTestResults._for_each_test(self._test_result_tree(), handler, '') |
| 117 |
| 118 @staticmethod |
| 119 def _for_each_test(tree, handler, prefix=''): |
| 120 for key in tree: |
| 121 new_prefix = (prefix + '/' + key) if prefix else key |
| 122 if 'actual' not in tree[key]: |
| 123 LayoutTestResults._for_each_test(tree[key], handler, new_prefix) |
| 124 else: |
| 125 handler(LayoutTestResult(new_prefix, tree[key])) |
| 126 |
| 127 def _test_result_tree(self): |
| 128 return self._results['tests'] |
| OLD | NEW |