| 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 12 matching lines...) Expand all Loading... |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 """A helper class for reading in and dealing with tests expectations | 29 """A helper class for reading in and dealing with tests expectations |
| 30 for layout tests. | 30 for layout tests. |
| 31 """ | 31 """ |
| 32 | 32 |
| 33 from collections import defaultdict |
| 34 |
| 33 import logging | 35 import logging |
| 34 import re | 36 import re |
| 35 | 37 |
| 36 from webkitpy.layout_tests.models.test_configuration import TestConfigurationCon
verter | 38 from webkitpy.layout_tests.models.test_configuration import TestConfigurationCon
verter |
| 37 | 39 |
| 38 _log = logging.getLogger(__name__) | 40 _log = logging.getLogger(__name__) |
| 39 | 41 |
| 40 | 42 |
| 41 # Test expectation and specifier constants. | 43 # Test expectation and specifier constants. |
| 42 # | 44 # |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 new_expectations |= set(self_map[test]) | 557 new_expectations |= set(self_map[test]) |
| 556 self_map[test] = list(new_expectations) if isinstance(other_map[test
], list) else new_expectations | 558 self_map[test] = list(new_expectations) if isinstance(other_map[test
], list) else new_expectations |
| 557 | 559 |
| 558 def _merge_dict_of_sets(self, self_dict, other_dict): | 560 def _merge_dict_of_sets(self, self_dict, other_dict): |
| 559 for key in other_dict: | 561 for key in other_dict: |
| 560 self_dict[key] |= other_dict[key] | 562 self_dict[key] |= other_dict[key] |
| 561 | 563 |
| 562 def merge_model(self, other): | 564 def merge_model(self, other): |
| 563 self._merge_test_map(self._test_to_expectations, other._test_to_expectat
ions) | 565 self._merge_test_map(self._test_to_expectations, other._test_to_expectat
ions) |
| 564 | 566 |
| 565 for test, line in other._test_to_expectation_line.items(): | 567 # merge_expectation_lines is O(tests per line). Therefore, this loop |
| 568 # is O((tests per line)^2) which is really expensive when a line |
| 569 # contains a lot of tests. Cache the output of merge_expectation_lines |
| 570 # so that we only call that n^2 in the number of *lines*. |
| 571 merge_lines_cache = defaultdict(dict) |
| 572 |
| 573 for test, other_line in other._test_to_expectation_line.items(): |
| 574 merged_line = None |
| 566 if test in self._test_to_expectation_line: | 575 if test in self._test_to_expectation_line: |
| 567 line = TestExpectationLine.merge_expectation_lines(self._test_to
_expectation_line[test], line, model_all_expectations=False) | 576 self_line = self._test_to_expectation_line[test] |
| 568 self._test_to_expectation_line[test] = line | 577 |
| 578 if other_line not in merge_lines_cache[self_line]: |
| 579 merge_lines_cache[self_line][other_line] = TestExpectationLi
ne.merge_expectation_lines( |
| 580 self_line, other_line, model_all_expectations=False) |
| 581 |
| 582 merged_line = merge_lines_cache[self_line][other_line] |
| 583 else: |
| 584 merged_line = other_line |
| 585 |
| 586 self._test_to_expectation_line[test] = merged_line |
| 569 | 587 |
| 570 self._merge_dict_of_sets(self._expectation_to_tests, other._expectation_
to_tests) | 588 self._merge_dict_of_sets(self._expectation_to_tests, other._expectation_
to_tests) |
| 571 self._merge_dict_of_sets(self._timeline_to_tests, other._timeline_to_tes
ts) | 589 self._merge_dict_of_sets(self._timeline_to_tests, other._timeline_to_tes
ts) |
| 572 self._merge_dict_of_sets(self._result_type_to_tests, other._result_type_
to_tests) | 590 self._merge_dict_of_sets(self._result_type_to_tests, other._result_type_
to_tests) |
| 573 | 591 |
| 574 def _dict_of_sets(self, strings_to_constants): | 592 def _dict_of_sets(self, strings_to_constants): |
| 575 """Takes a dict of strings->constants and returns a dict mapping | 593 """Takes a dict of strings->constants and returns a dict mapping |
| 576 each constant to an empty set.""" | 594 each constant to an empty set.""" |
| 577 d = {} | 595 d = {} |
| 578 for c in strings_to_constants.values(): | 596 for c in strings_to_constants.values(): |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 # If reconstitute_only_these is an empty list, we want to return ori
ginal_string. | 1138 # If reconstitute_only_these is an empty list, we want to return ori
ginal_string. |
| 1121 # So we need to compare reconstitute_only_these to None, not just ch
eck if it's falsey. | 1139 # So we need to compare reconstitute_only_these to None, not just ch
eck if it's falsey. |
| 1122 if reconstitute_only_these is None or expectation_line in reconstitu
te_only_these: | 1140 if reconstitute_only_these is None or expectation_line in reconstitu
te_only_these: |
| 1123 return expectation_line.to_string(test_configuration_converter) | 1141 return expectation_line.to_string(test_configuration_converter) |
| 1124 return expectation_line.original_string | 1142 return expectation_line.original_string |
| 1125 | 1143 |
| 1126 def nones_out(expectation_line): | 1144 def nones_out(expectation_line): |
| 1127 return expectation_line is not None | 1145 return expectation_line is not None |
| 1128 | 1146 |
| 1129 return "\n".join(filter(nones_out, map(serialize, expectation_lines))) | 1147 return "\n".join(filter(nones_out, map(serialize, expectation_lines))) |
| OLD | NEW |