Chromium Code Reviews| 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 new_expectations |= set(self_map[test]) | 558 new_expectations |= set(self_map[test]) |
| 557 self_map[test] = list(new_expectations) if isinstance(other_map[test ], list) else new_expectations | 559 self_map[test] = list(new_expectations) if isinstance(other_map[test ], list) else new_expectations |
| 558 | 560 |
| 559 def _merge_dict_of_sets(self, self_dict, other_dict): | 561 def _merge_dict_of_sets(self, self_dict, other_dict): |
| 560 for key in other_dict: | 562 for key in other_dict: |
| 561 self_dict[key] |= other_dict[key] | 563 self_dict[key] |= other_dict[key] |
| 562 | 564 |
| 563 def merge_model(self, other): | 565 def merge_model(self, other): |
| 564 self._merge_test_map(self._test_to_expectations, other._test_to_expectat ions) | 566 self._merge_test_map(self._test_to_expectations, other._test_to_expectat ions) |
| 565 | 567 |
| 568 # This code is n^2 in the number of tests per line. Cache the output | |
|
Dirk Pranke
2015/06/15 22:50:59
"This code" is a bit ambiguous.
It's merge_expec
ojan
2015/06/17 17:16:53
Done
| |
| 569 # of merge_expectation_lines so that we only call that n^2 in the number | |
| 570 # of *lines*. | |
| 571 merge_lines_cache = defaultdict(dict) | |
| 572 | |
| 566 for test, line in other._test_to_expectation_line.items(): | 573 for test, line in other._test_to_expectation_line.items(): |
| 567 if test in self._test_to_expectation_line: | 574 if test in self._test_to_expectation_line: |
| 568 line = TestExpectationLine.merge_expectation_lines(self._test_to _expectation_line[test], line, model_all_expectations=False) | 575 self_line = self._test_to_expectation_line[test] |
| 576 | |
| 577 cached_line = None | |
| 578 if self_line in merge_lines_cache: | |
| 579 cached_line = merge_lines_cache[self_line].get(line) | |
| 580 | |
| 581 if cached_line: | |
| 582 line = cached_line | |
| 583 else: | |
| 584 new_line = TestExpectationLine.merge_expectation_lines(self_ line, line, model_all_expectations=False) | |
| 585 merge_lines_cache[self_line][line] = new_line | |
| 586 line = new_line | |
|
Dirk Pranke
2015/06/15 22:50:59
Can you rewrite lines 577-586 as:
if line not in
ojan
2015/06/17 17:16:53
That's much better. I didn't do exactly this, but
| |
| 587 | |
| 569 self._test_to_expectation_line[test] = line | 588 self._test_to_expectation_line[test] = line |
| 570 | 589 |
| 571 self._merge_dict_of_sets(self._expectation_to_tests, other._expectation_ to_tests) | 590 self._merge_dict_of_sets(self._expectation_to_tests, other._expectation_ to_tests) |
| 572 self._merge_dict_of_sets(self._timeline_to_tests, other._timeline_to_tes ts) | 591 self._merge_dict_of_sets(self._timeline_to_tests, other._timeline_to_tes ts) |
| 573 self._merge_dict_of_sets(self._result_type_to_tests, other._result_type_ to_tests) | 592 self._merge_dict_of_sets(self._result_type_to_tests, other._result_type_ to_tests) |
| 574 | 593 |
| 575 def _dict_of_sets(self, strings_to_constants): | 594 def _dict_of_sets(self, strings_to_constants): |
| 576 """Takes a dict of strings->constants and returns a dict mapping | 595 """Takes a dict of strings->constants and returns a dict mapping |
| 577 each constant to an empty set.""" | 596 each constant to an empty set.""" |
| 578 d = {} | 597 d = {} |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1121 # If reconstitute_only_these is an empty list, we want to return ori ginal_string. | 1140 # If reconstitute_only_these is an empty list, we want to return ori ginal_string. |
| 1122 # So we need to compare reconstitute_only_these to None, not just ch eck if it's falsey. | 1141 # So we need to compare reconstitute_only_these to None, not just ch eck if it's falsey. |
| 1123 if reconstitute_only_these is None or expectation_line in reconstitu te_only_these: | 1142 if reconstitute_only_these is None or expectation_line in reconstitu te_only_these: |
| 1124 return expectation_line.to_string(test_configuration_converter) | 1143 return expectation_line.to_string(test_configuration_converter) |
| 1125 return expectation_line.original_string | 1144 return expectation_line.original_string |
| 1126 | 1145 |
| 1127 def nones_out(expectation_line): | 1146 def nones_out(expectation_line): |
| 1128 return expectation_line is not None | 1147 return expectation_line is not None |
| 1129 | 1148 |
| 1130 return "\n".join(filter(nones_out, map(serialize, expectation_lines))) | 1149 return "\n".join(filter(nones_out, map(serialize, expectation_lines))) |
| OLD | NEW |