| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
| 7 | 7 |
| 8 # pylint: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 |
| 9 | 9 |
| 10 import logging | 10 import logging |
| (...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 self.mox.ReplayAll() | 2212 self.mox.ReplayAll() |
| 2213 | 2213 |
| 2214 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 2214 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
| 2215 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 2215 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
| 2216 self.assertEquals(len(results), 1) | 2216 self.assertEquals(len(results), 1) |
| 2217 self.assertEquals(results[0].__class__, | 2217 self.assertEquals(results[0].__class__, |
| 2218 presubmit.OutputApi.PresubmitNotifyResult) | 2218 presubmit.OutputApi.PresubmitNotifyResult) |
| 2219 | 2219 |
| 2220 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, | 2220 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, |
| 2221 reviewers=None, is_committing=True, rietveld_response=None, | 2221 reviewers=None, is_committing=True, rietveld_response=None, |
| 2222 uncovered_files=None, expected_output=''): | 2222 uncovered_files=None, expected_output='', author_counts_as_owner=True): |
| 2223 if approvers is None: | 2223 if approvers is None: |
| 2224 # The set of people who lgtm'ed a change. |
| 2224 approvers = set() | 2225 approvers = set() |
| 2225 if reviewers is None: | 2226 if reviewers is None: |
| 2226 reviewers = set() | 2227 # The set of people needed to lgtm a change. We default to |
| 2227 reviewers = reviewers.union(approvers) | 2228 # the same list as the people who approved it. We use 'reviewers' |
| 2229 # to avoid a name collision w/ owners.py. |
| 2230 reviewers = approvers |
| 2228 if uncovered_files is None: | 2231 if uncovered_files is None: |
| 2229 uncovered_files = set() | 2232 uncovered_files = set() |
| 2230 | 2233 |
| 2231 change = self.mox.CreateMock(presubmit.Change) | 2234 change = self.mox.CreateMock(presubmit.Change) |
| 2232 change.issue = issue | 2235 change.issue = issue |
| 2233 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 2236 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 2234 input_api = self.MockInputApi(change, False) | 2237 input_api = self.MockInputApi(change, False) |
| 2235 fake_db = self.mox.CreateMock(owners.Database) | 2238 fake_db = self.mox.CreateMock(owners.Database) |
| 2236 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) | 2239 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) |
| 2237 input_api.owners_db = fake_db | 2240 input_api.owners_db = fake_db |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2256 people = approvers | 2259 people = approvers |
| 2257 else: | 2260 else: |
| 2258 people = reviewers | 2261 people = reviewers |
| 2259 | 2262 |
| 2260 if issue: | 2263 if issue: |
| 2261 input_api.rietveld.get_issue_properties( | 2264 input_api.rietveld.get_issue_properties( |
| 2262 issue=int(input_api.change.issue), messages=True).AndReturn( | 2265 issue=int(input_api.change.issue), messages=True).AndReturn( |
| 2263 rietveld_response) | 2266 rietveld_response) |
| 2264 people.add(owner_email) | 2267 people.add(owner_email) |
| 2265 | 2268 |
| 2266 fake_db.files_not_covered_by(set(['foo/xyz.cc']), | 2269 if author_counts_as_owner: |
| 2267 people).AndReturn(uncovered_files) | 2270 fake_db.files_not_covered_by(set(['foo/xyz.cc']), |
| 2271 people).AndReturn(uncovered_files) |
| 2272 else: |
| 2273 fake_db.files_not_covered_by(set(['foo/xyz.cc']), |
| 2274 people.difference(set([owner_email]))).AndReturn(uncovered_files) |
| 2268 if not is_committing and uncovered_files: | 2275 if not is_committing and uncovered_files: |
| 2269 fake_db.reviewers_for(set(['foo/xyz.cc'])).AndReturn(owner_email) | 2276 fake_db.reviewers_for(set(['foo/xyz.cc']), |
| 2277 owner_email if issue else '').AndReturn(owner_email) |
| 2270 | 2278 |
| 2271 self.mox.ReplayAll() | 2279 self.mox.ReplayAll() |
| 2272 output = presubmit.PresubmitOutput() | 2280 output = presubmit.PresubmitOutput() |
| 2273 results = presubmit_canned_checks.CheckOwners(input_api, | 2281 results = presubmit_canned_checks.CheckOwners(input_api, |
| 2274 presubmit.OutputApi) | 2282 presubmit.OutputApi, author_counts_as_owner=author_counts_as_owner) |
| 2275 if results: | 2283 if results: |
| 2276 results[0].handle(output) | 2284 results[0].handle(output) |
| 2277 self.assertEquals(output.getvalue(), expected_output) | 2285 self.assertEquals(output.getvalue(), expected_output) |
| 2278 | 2286 |
| 2279 def testCannedCheckOwners_Approved(self): | 2287 def testCannedCheckOwners_Approved(self): |
| 2280 response = { | 2288 response = { |
| 2281 "owner_email": "john@example.com", | 2289 "owner_email": "john@example.com", |
| 2282 "messages": [ | 2290 "messages": [ |
| 2283 { | 2291 { |
| 2284 "sender": "ben@example.com", "text": "foo", "approval": True, | 2292 "sender": "ben@example.com", "text": "foo", "approval": True, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2369 self.AssertOwnersWorks(is_committing=False, expected_output='') | 2377 self.AssertOwnersWorks(is_committing=False, expected_output='') |
| 2370 | 2378 |
| 2371 def testCannedCheckOwners_OnlyOwnerLGTM(self): | 2379 def testCannedCheckOwners_OnlyOwnerLGTM(self): |
| 2372 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2380 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
| 2373 expected_output='Missing LGTM from someone ' | 2381 expected_output='Missing LGTM from someone ' |
| 2374 'other than john@example.com\n') | 2382 'other than john@example.com\n') |
| 2375 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2383 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
| 2376 is_committing=False, | 2384 is_committing=False, |
| 2377 expected_output='') | 2385 expected_output='') |
| 2378 | 2386 |
| 2387 def testCannedCheckOwners_AuthorCountsAsOwner(self): |
| 2388 self.AssertOwnersWorks(approvers=set(['john@example.com', |
| 2389 'brett@example.com']), |
| 2390 reviewers=set(['john@example.com', |
| 2391 'ben@example.com']), |
| 2392 uncovered_files=set(['foo/xyz.cc']), |
| 2393 expected_output='Missing LGTM from an OWNER ' |
| 2394 'for these files:\n foo/xyz.cc\n', |
| 2395 author_counts_as_owner=False) |
| 2396 |
| 2379 def testCannedCheckOwners_TBR(self): | 2397 def testCannedCheckOwners_TBR(self): |
| 2380 self.AssertOwnersWorks(tbr=True, | 2398 self.AssertOwnersWorks(tbr=True, |
| 2381 expected_output='--tbr was specified, skipping OWNERS check\n') | 2399 expected_output='--tbr was specified, skipping OWNERS check\n') |
| 2382 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='') | 2400 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='') |
| 2383 | 2401 |
| 2384 def testCannedCheckOwners_WithoutOwnerLGTM(self): | 2402 def testCannedCheckOwners_WithoutOwnerLGTM(self): |
| 2385 self.AssertOwnersWorks(uncovered_files=set(['foo']), | 2403 self.AssertOwnersWorks(uncovered_files=set(['foo']), |
| 2386 expected_output='Missing LGTM from an OWNER for these files:\n' | 2404 expected_output='Missing LGTM from an OWNER for these files:\n' |
| 2387 ' foo\n') | 2405 ' foo\n') |
| 2388 self.AssertOwnersWorks(uncovered_files=set(['foo']), | 2406 self.AssertOwnersWorks(uncovered_files=set(['foo']), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 owners_check=False) | 2505 owners_check=False) |
| 2488 self.assertEqual(1, len(results)) | 2506 self.assertEqual(1, len(results)) |
| 2489 self.assertEqual( | 2507 self.assertEqual( |
| 2490 'Found line ending with white spaces in:', results[0]._message) | 2508 'Found line ending with white spaces in:', results[0]._message) |
| 2491 self.checkstdout('') | 2509 self.checkstdout('') |
| 2492 | 2510 |
| 2493 | 2511 |
| 2494 if __name__ == '__main__': | 2512 if __name__ == '__main__': |
| 2495 import unittest | 2513 import unittest |
| 2496 unittest.main() | 2514 unittest.main() |
| OLD | NEW |