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_dirs=None, expected_output=''): | 2222 uncovered_files=None, expected_output=''): |
2223 if approvers is None: | 2223 if approvers is None: |
2224 approvers = set() | 2224 approvers = set() |
2225 if reviewers is None: | 2225 if reviewers is None: |
2226 reviewers = set() | 2226 reviewers = set() |
2227 reviewers = reviewers.union(approvers) | 2227 reviewers = reviewers.union(approvers) |
2228 if uncovered_dirs is None: | 2228 if uncovered_files is None: |
2229 uncovered_dirs = set() | 2229 uncovered_files = set() |
2230 | 2230 |
2231 change = self.mox.CreateMock(presubmit.Change) | 2231 change = self.mox.CreateMock(presubmit.Change) |
2232 change.issue = issue | 2232 change.issue = issue |
2233 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 2233 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
2234 input_api = self.MockInputApi(change, False) | 2234 input_api = self.MockInputApi(change, False) |
2235 fake_db = self.mox.CreateMock(owners.Database) | 2235 fake_db = self.mox.CreateMock(owners.Database) |
2236 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) | 2236 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) |
2237 input_api.owners_db = fake_db | 2237 input_api.owners_db = fake_db |
2238 input_api.is_committing = is_committing | 2238 input_api.is_committing = is_committing |
2239 input_api.tbr = tbr | 2239 input_api.tbr = tbr |
(...skipping 16 matching lines...) Expand all Loading... |
2256 people = approvers | 2256 people = approvers |
2257 else: | 2257 else: |
2258 people = reviewers | 2258 people = reviewers |
2259 | 2259 |
2260 if issue: | 2260 if issue: |
2261 input_api.rietveld.get_issue_properties( | 2261 input_api.rietveld.get_issue_properties( |
2262 issue=int(input_api.change.issue), messages=True).AndReturn( | 2262 issue=int(input_api.change.issue), messages=True).AndReturn( |
2263 rietveld_response) | 2263 rietveld_response) |
2264 people.add(owner_email) | 2264 people.add(owner_email) |
2265 | 2265 |
2266 fake_db.directories_not_covered_by(set(['foo/xyz.cc']), | 2266 fake_db.files_not_covered_by(set(['foo/xyz.cc']), |
2267 people).AndReturn(uncovered_dirs) | 2267 people).AndReturn(uncovered_files) |
2268 if not is_committing and uncovered_dirs: | 2268 if not is_committing and uncovered_files: |
2269 fake_db.reviewers_for(set(['foo/xyz.cc'])).AndReturn(owner_email) | 2269 fake_db.reviewers_for(set(['foo/xyz.cc'])).AndReturn(owner_email) |
2270 | 2270 |
2271 self.mox.ReplayAll() | 2271 self.mox.ReplayAll() |
2272 output = presubmit.PresubmitOutput() | 2272 output = presubmit.PresubmitOutput() |
2273 results = presubmit_canned_checks.CheckOwners(input_api, | 2273 results = presubmit_canned_checks.CheckOwners(input_api, |
2274 presubmit.OutputApi) | 2274 presubmit.OutputApi) |
2275 if results: | 2275 if results: |
2276 results[0].handle(output) | 2276 results[0].handle(output) |
2277 self.assertEquals(output.getvalue(), expected_output) | 2277 self.assertEquals(output.getvalue(), expected_output) |
2278 | 2278 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 | 2345 |
2346 def testCannedCheckOwners_NoIssueNoFiles(self): | 2346 def testCannedCheckOwners_NoIssueNoFiles(self): |
2347 self.AssertOwnersWorks(issue=None, | 2347 self.AssertOwnersWorks(issue=None, |
2348 expected_output="OWNERS check failed: this change has no Rietveld " | 2348 expected_output="OWNERS check failed: this change has no Rietveld " |
2349 "issue number, so we can't check it for approvals.\n") | 2349 "issue number, so we can't check it for approvals.\n") |
2350 self.AssertOwnersWorks(issue=None, is_committing=False, | 2350 self.AssertOwnersWorks(issue=None, is_committing=False, |
2351 expected_output="") | 2351 expected_output="") |
2352 | 2352 |
2353 def testCannedCheckOwners_NoIssue(self): | 2353 def testCannedCheckOwners_NoIssue(self): |
2354 self.AssertOwnersWorks(issue=None, | 2354 self.AssertOwnersWorks(issue=None, |
2355 uncovered_dirs=set(['foo']), | 2355 uncovered_files=set(['foo']), |
2356 expected_output="OWNERS check failed: this change has no Rietveld " | 2356 expected_output="OWNERS check failed: this change has no Rietveld " |
2357 "issue number, so we can't check it for approvals.\n") | 2357 "issue number, so we can't check it for approvals.\n") |
2358 self.AssertOwnersWorks(issue=None, | 2358 self.AssertOwnersWorks(issue=None, |
2359 is_committing=False, | 2359 is_committing=False, |
2360 uncovered_dirs=set(['foo']), | 2360 uncovered_files=set(['foo']), |
2361 expected_output='Missing OWNER reviewers for files in these ' | 2361 expected_output='Missing OWNER reviewers for these files:\n' |
2362 'directories:\n' | |
2363 ' foo\n' | 2362 ' foo\n' |
2364 'Until the issue is uploaded, this list will include ' | 2363 'Until the issue is uploaded, this list will include ' |
2365 'directories for which you \n' | 2364 'files for which you are an OWNER.\n') |
2366 'are an OWNER.\n') | |
2367 | 2365 |
2368 def testCannedCheckOwners_NoLGTM(self): | 2366 def testCannedCheckOwners_NoLGTM(self): |
2369 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' | 2367 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' |
2370 'other than john@example.com\n') | 2368 'other than john@example.com\n') |
2371 self.AssertOwnersWorks(is_committing=False, expected_output='') | 2369 self.AssertOwnersWorks(is_committing=False, expected_output='') |
2372 | 2370 |
2373 def testCannedCheckOwners_OnlyOwnerLGTM(self): | 2371 def testCannedCheckOwners_OnlyOwnerLGTM(self): |
2374 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2372 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
2375 expected_output='Missing LGTM from someone ' | 2373 expected_output='Missing LGTM from someone ' |
2376 'other than john@example.com\n') | 2374 'other than john@example.com\n') |
2377 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2375 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
2378 is_committing=False, | 2376 is_committing=False, |
2379 expected_output='') | 2377 expected_output='') |
2380 | 2378 |
2381 def testCannedCheckOwners_TBR(self): | 2379 def testCannedCheckOwners_TBR(self): |
2382 self.AssertOwnersWorks(tbr=True, | 2380 self.AssertOwnersWorks(tbr=True, |
2383 expected_output='--tbr was specified, skipping OWNERS check\n') | 2381 expected_output='--tbr was specified, skipping OWNERS check\n') |
2384 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='') | 2382 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='') |
2385 | 2383 |
2386 def testCannedCheckOwners_WithoutOwnerLGTM(self): | 2384 def testCannedCheckOwners_WithoutOwnerLGTM(self): |
2387 self.AssertOwnersWorks(uncovered_dirs=set(['foo']), | 2385 self.AssertOwnersWorks(uncovered_files=set(['foo']), |
2388 expected_output='Missing LGTM from an OWNER for files in these ' | 2386 expected_output='Missing LGTM from an OWNER for these files:\n' |
2389 'directories:\n' | |
2390 ' foo\n') | 2387 ' foo\n') |
2391 self.AssertOwnersWorks(uncovered_dirs=set(['foo']), | 2388 self.AssertOwnersWorks(uncovered_files=set(['foo']), |
2392 is_committing=False, | 2389 is_committing=False, |
2393 expected_output='Missing OWNER reviewers for files in these ' | 2390 expected_output='Missing OWNER reviewers for these files:\n' |
2394 'directories:\n' | |
2395 ' foo\n') | 2391 ' foo\n') |
2396 | 2392 |
2397 def testCannedCheckOwners_WithLGTMs(self): | 2393 def testCannedCheckOwners_WithLGTMs(self): |
2398 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2394 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2399 uncovered_dirs=set()) | 2395 uncovered_files=set()) |
2400 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2396 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2401 is_committing=False, | 2397 is_committing=False, |
2402 uncovered_dirs=set()) | 2398 uncovered_files=set()) |
2403 | 2399 |
2404 def testCannedRunUnitTests(self): | 2400 def testCannedRunUnitTests(self): |
2405 change = presubmit.Change( | 2401 change = presubmit.Change( |
2406 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) | 2402 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) |
2407 input_api = self.MockInputApi(change, False) | 2403 input_api = self.MockInputApi(change, False) |
2408 input_api.verbose = True | 2404 input_api.verbose = True |
2409 unit_tests = ['allo', 'bar.py'] | 2405 unit_tests = ['allo', 'bar.py'] |
2410 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2406 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2411 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2407 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2412 input_api.subprocess.check_call( | 2408 input_api.subprocess.check_call( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 owners_check=False) | 2487 owners_check=False) |
2492 self.assertEqual(1, len(results)) | 2488 self.assertEqual(1, len(results)) |
2493 self.assertEqual( | 2489 self.assertEqual( |
2494 'Found line ending with white spaces in:', results[0]._message) | 2490 'Found line ending with white spaces in:', results[0]._message) |
2495 self.checkstdout('') | 2491 self.checkstdout('') |
2496 | 2492 |
2497 | 2493 |
2498 if __name__ == '__main__': | 2494 if __name__ == '__main__': |
2499 import unittest | 2495 import unittest |
2500 unittest.main() | 2496 unittest.main() |
OLD | NEW |