OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import copy | 5 import copy |
6 import math | 6 import math |
7 import pprint | 7 import pprint |
8 | 8 |
9 from common.dependency import DependencyRoll | 9 from common.dependency import DependencyRoll |
10 from common import chrome_dependency_fetcher | 10 from common import chrome_dependency_fetcher |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 class LogLinearChangelistClassifierTest(CrashTestSuite): | 111 class LogLinearChangelistClassifierTest(CrashTestSuite): |
112 | 112 |
113 def setUp(self): | 113 def setUp(self): |
114 super(LogLinearChangelistClassifierTest, self).setUp() | 114 super(LogLinearChangelistClassifierTest, self).setUp() |
115 weights = { | 115 weights = { |
116 'MinDistance': 1., | 116 'MinDistance': 1., |
117 'TopFrameIndex': 1., | 117 'TopFrameIndex': 1., |
118 } | 118 } |
119 | 119 |
120 repository = GitilesRepository(self.GetMockHttpClient()) | 120 def GitilesRepositoryFactory(repo_url): # pragma: no cover |
121 | 121 return GitilesRepository(self.GetMockHttpClient(), repo_url) |
122 # TODO(crbug.com/677224): should replace this with an actual factory. | |
123 def MutateTheRepo(dep_url): # pragma: no cover | |
124 """A factory function for returning ``Repository`` objects. | |
125 | |
126 The current definition captures the functionality of before | |
127 we factored out this factory method. That is, it's not really a | |
128 "factory" but rather mutates the main repo object in place. In | |
129 the future this should be changed to do the right thing instead. | |
130 """ | |
131 repository.repo_url = dep_url | |
132 return repository | |
133 | 122 |
134 self.changelist_classifier = ( | 123 self.changelist_classifier = ( |
135 loglinear_changelist_classifier.LogLinearChangelistClassifier( | 124 loglinear_changelist_classifier.LogLinearChangelistClassifier( |
136 repository, MutateTheRepo, weights)) | 125 GitilesRepositoryFactory, weights)) |
137 | 126 |
138 def testAggregateChangedFilesAggreegates(self): | 127 def testAggregateChangedFilesAggreegates(self): |
139 """Test that ``AggregateChangedFiles`` does aggregate reasons per file. | 128 """Test that ``AggregateChangedFiles`` does aggregate reasons per file. |
140 | 129 |
141 In the main/inner loop of ``AggregateChangedFiles``: if multiple | 130 In the main/inner loop of ``AggregateChangedFiles``: if multiple |
142 features all blame the same file change, we try to aggregate those | 131 features all blame the same file change, we try to aggregate those |
143 reasons so that we only report the file once (with all reasons). None | 132 reasons so that we only report the file once (with all reasons). None |
144 of the other tests here actually check the case where the same file | 133 of the other tests here actually check the case where the same file |
145 is blamed multiple times, so we check that here. | 134 is blamed multiple times, so we check that here. |
146 | 135 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 self.mock(changelist_classifier, 'FindSuspects', _MockFindSuspects) | 393 self.mock(changelist_classifier, 'FindSuspects', _MockFindSuspects) |
405 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher, | 394 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher, |
406 'GetDependencyRollsDict', | 395 'GetDependencyRollsDict', |
407 lambda *_: {'src/': DependencyRoll('src/', 'https://repo', '1', '2')}) | 396 lambda *_: {'src/': DependencyRoll('src/', 'https://repo', '1', '2')}) |
408 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher, | 397 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher, |
409 'GetDependency', lambda *_: {}) | 398 'GetDependency', lambda *_: {}) |
410 | 399 |
411 suspects = self.changelist_classifier(DUMMY_REPORT) | 400 suspects = self.changelist_classifier(DUMMY_REPORT) |
412 self.assertFalse(suspects, 'Expected zero suspects, but found some:\n%s' | 401 self.assertFalse(suspects, 'Expected zero suspects, but found some:\n%s' |
413 % pprint.pformat([suspect.ToDict() for suspect in suspects])) | 402 % pprint.pformat([suspect.ToDict() for suspect in suspects])) |
OLD | NEW |