Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: tests/presubmit_unittest.py

Issue 1090943003: Skip OWNERS checks for CQ dry runs (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Cleanup Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 functools 10 import functools
(...skipping 2552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 2563
2564 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 2564 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
2565 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 2565 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
2566 self.assertEquals(len(results), 1) 2566 self.assertEquals(len(results), 1)
2567 self.assertEquals(results[0].__class__, 2567 self.assertEquals(results[0].__class__,
2568 presubmit.OutputApi.PresubmitNotifyResult) 2568 presubmit.OutputApi.PresubmitNotifyResult)
2569 2569
2570 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, 2570 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None,
2571 reviewers=None, is_committing=True, rietveld_response=None, 2571 reviewers=None, is_committing=True, rietveld_response=None,
2572 uncovered_files=None, expected_output='', 2572 uncovered_files=None, expected_output='',
2573 manually_specified_reviewers=None): 2573 manually_specified_reviewers=None, cq_dry_run=False):
2574 if approvers is None: 2574 if approvers is None:
2575 # The set of people who lgtm'ed a change. 2575 # The set of people who lgtm'ed a change.
2576 approvers = set() 2576 approvers = set()
2577 if reviewers is None: 2577 if reviewers is None:
2578 # The set of people needed to lgtm a change. We default to 2578 # The set of people needed to lgtm a change. We default to
2579 # the same list as the people who approved it. We use 'reviewers' 2579 # the same list as the people who approved it. We use 'reviewers'
2580 # to avoid a name collision w/ owners.py. 2580 # to avoid a name collision w/ owners.py.
2581 reviewers = approvers 2581 reviewers = approvers
2582 if uncovered_files is None: 2582 if uncovered_files is None:
2583 uncovered_files = set() 2583 uncovered_files = set()
2584 if manually_specified_reviewers is None: 2584 if manually_specified_reviewers is None:
2585 manually_specified_reviewers = [] 2585 manually_specified_reviewers = []
2586 2586
2587 change = self.mox.CreateMock(presubmit.Change) 2587 change = self.mox.CreateMock(presubmit.Change)
2588 change.issue = issue 2588 change.issue = issue
2589 change.author_email = 'john@example.com' 2589 change.author_email = 'john@example.com'
2590 change.R = ','.join(manually_specified_reviewers) 2590 change.R = ','.join(manually_specified_reviewers)
2591 change.TBR = '' 2591 change.TBR = ''
2592 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 2592 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
2593 input_api = self.MockInputApi(change, False) 2593 input_api = self.MockInputApi(change, False)
2594 fake_db = self.mox.CreateMock(owners.Database) 2594 fake_db = self.mox.CreateMock(owners.Database)
2595 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) 2595 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
2596 input_api.owners_db = fake_db 2596 input_api.owners_db = fake_db
2597 input_api.is_committing = is_committing 2597 input_api.is_committing = is_committing
2598 input_api.tbr = tbr 2598 input_api.tbr = tbr
2599 2599
2600 if not is_committing or (not tbr and issue): 2600 if not is_committing or (not tbr and issue):
2601 affected_file.LocalPath().AndReturn('foo/xyz.cc') 2601 if not cq_dry_run:
2602 change.AffectedFiles(file_filter=None).AndReturn([affected_file]) 2602 affected_file.LocalPath().AndReturn('foo/xyz.cc')
2603 change.AffectedFiles(file_filter=None).AndReturn([affected_file])
2603 if issue and not rietveld_response: 2604 if issue and not rietveld_response:
2604 rietveld_response = { 2605 rietveld_response = {
2605 "owner_email": change.author_email, 2606 "owner_email": change.author_email,
2606 "messages": [ 2607 "messages": [
2607 {"sender": a, "text": "I approve", "approval": True} 2608 {"sender": a, "text": "I approve", "approval": True}
2608 for a in approvers 2609 for a in approvers
2609 ], 2610 ],
2610 "reviewers": reviewers 2611 "reviewers": reviewers
2611 } 2612 }
2612 2613
2613 if is_committing: 2614 if is_committing:
2614 people = approvers 2615 people = approvers
2616 if issue:
2617 input_api.rietveld.get_issue_properties(
2618 issue=int(input_api.change.issue), messages=None).AndReturn(
2619 rietveld_response)
2615 else: 2620 else:
2616 people = reviewers 2621 people = reviewers
2617 2622
2618 if issue: 2623 if not cq_dry_run:
2619 input_api.rietveld.get_issue_properties( 2624 if issue:
2620 issue=int(input_api.change.issue), messages=True).AndReturn( 2625 input_api.rietveld.get_issue_properties(
2621 rietveld_response) 2626 issue=int(input_api.change.issue), messages=True).AndReturn(
2627 rietveld_response)
2622 2628
2623 people.add(change.author_email) 2629 people.add(change.author_email)
2624 fake_db.files_not_covered_by(set(['foo/xyz.cc']), 2630 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2625 people).AndReturn(uncovered_files) 2631 people).AndReturn(uncovered_files)
2626 if not is_committing and uncovered_files: 2632 if not is_committing and uncovered_files:
2627 fake_db.reviewers_for(set(['foo']), 2633 fake_db.reviewers_for(set(['foo']),
2628 change.author_email).AndReturn(change.author_email) 2634 change.author_email).AndReturn(change.author_email)
2629 2635
2630 self.mox.ReplayAll() 2636 self.mox.ReplayAll()
2631 output = presubmit.PresubmitOutput() 2637 output = presubmit.PresubmitOutput()
2632 results = presubmit_canned_checks.CheckOwners(input_api, 2638 results = presubmit_canned_checks.CheckOwners(input_api,
2633 presubmit.OutputApi) 2639 presubmit.OutputApi)
2634 if results: 2640 if results:
2635 results[0].handle(output) 2641 results[0].handle(output)
2636 self.assertEquals(output.getvalue(), expected_output) 2642 self.assertEquals(output.getvalue(), expected_output)
2637 2643
2644 def testCannedCheckOwners_DryRun(self):
2645 response = {
2646 "owner_email": "john@example.com",
2647 "cq_dry_run": True,
2648 "reviewers": ["ben@example.com"],
2649 }
2650 self.AssertOwnersWorks(approvers=set(),
2651 cq_dry_run=True,
2652 rietveld_response=response,
2653 reviewers=set(["ben@example.com"]),
2654 expected_output='This is a CQ dry run, skipping OWNERS check\n')
2655
2656 self.AssertOwnersWorks(approvers=set(['ben@example.com']),
2657 is_committing=False,
2658 rietveld_response=response,
2659 expected_output='')
2660
2638 def testCannedCheckOwners_Approved(self): 2661 def testCannedCheckOwners_Approved(self):
2639 response = { 2662 response = {
2640 "owner_email": "john@example.com", 2663 "owner_email": "john@example.com",
2641 "messages": [ 2664 "messages": [
2642 { 2665 {
2643 "sender": "ben@example.com", "text": "foo", "approval": True, 2666 "sender": "ben@example.com", "text": "foo", "approval": True,
2644 }, 2667 },
2645 ], 2668 ],
2646 "reviewers": ["ben@example.com"], 2669 "reviewers": ["ben@example.com"],
2647 } 2670 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 owners_check=False) 2890 owners_check=False)
2868 self.assertEqual(1, len(results)) 2891 self.assertEqual(1, len(results))
2869 self.assertEqual( 2892 self.assertEqual(
2870 'Found line ending with white spaces in:', results[0]._message) 2893 'Found line ending with white spaces in:', results[0]._message)
2871 self.checkstdout('') 2894 self.checkstdout('')
2872 2895
2873 2896
2874 if __name__ == '__main__': 2897 if __name__ == '__main__':
2875 import unittest 2898 import unittest
2876 unittest.main() 2899 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698