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

Side by Side Diff: tests/presubmit_unittest.py

Issue 851103004: Remove the 'author_counts_as_owner' option from CheckOwners(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
« 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 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 self.mox.ReplayAll() 2596 self.mox.ReplayAll()
2597 2597
2598 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 2598 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
2599 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 2599 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
2600 self.assertEquals(len(results), 1) 2600 self.assertEquals(len(results), 1)
2601 self.assertEquals(results[0].__class__, 2601 self.assertEquals(results[0].__class__,
2602 presubmit.OutputApi.PresubmitNotifyResult) 2602 presubmit.OutputApi.PresubmitNotifyResult)
2603 2603
2604 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, 2604 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None,
2605 reviewers=None, is_committing=True, rietveld_response=None, 2605 reviewers=None, is_committing=True, rietveld_response=None,
2606 uncovered_files=None, expected_output='', author_counts_as_owner=True, 2606 uncovered_files=None, expected_output='',
2607 manually_specified_reviewers=None): 2607 manually_specified_reviewers=None):
2608 if approvers is None: 2608 if approvers is None:
2609 # The set of people who lgtm'ed a change. 2609 # The set of people who lgtm'ed a change.
2610 approvers = set() 2610 approvers = set()
2611 if reviewers is None: 2611 if reviewers is None:
2612 # The set of people needed to lgtm a change. We default to 2612 # The set of people needed to lgtm a change. We default to
2613 # the same list as the people who approved it. We use 'reviewers' 2613 # the same list as the people who approved it. We use 'reviewers'
2614 # to avoid a name collision w/ owners.py. 2614 # to avoid a name collision w/ owners.py.
2615 reviewers = approvers 2615 reviewers = approvers
2616 if uncovered_files is None: 2616 if uncovered_files is None:
(...skipping 30 matching lines...) Expand all
2647 if is_committing: 2647 if is_committing:
2648 people = approvers 2648 people = approvers
2649 else: 2649 else:
2650 people = reviewers 2650 people = reviewers
2651 2651
2652 if issue: 2652 if issue:
2653 input_api.rietveld.get_issue_properties( 2653 input_api.rietveld.get_issue_properties(
2654 issue=int(input_api.change.issue), messages=True).AndReturn( 2654 issue=int(input_api.change.issue), messages=True).AndReturn(
2655 rietveld_response) 2655 rietveld_response)
2656 2656
2657 if author_counts_as_owner: 2657 people.add(change.author_email)
2658 people.add(change.author_email) 2658 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2659 fake_db.files_not_covered_by(set(['foo/xyz.cc']), 2659 people).AndReturn(uncovered_files)
2660 people).AndReturn(uncovered_files)
2661 else:
2662 people.discard(change.author_email)
2663 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2664 people).AndReturn(uncovered_files)
2665 if not is_committing and uncovered_files: 2660 if not is_committing and uncovered_files:
2666 fake_db.reviewers_for(set(['foo']), 2661 fake_db.reviewers_for(set(['foo']),
2667 change.author_email).AndReturn(change.author_email) 2662 change.author_email).AndReturn(change.author_email)
2668 2663
2669 self.mox.ReplayAll() 2664 self.mox.ReplayAll()
2670 output = presubmit.PresubmitOutput() 2665 output = presubmit.PresubmitOutput()
2671 results = presubmit_canned_checks.CheckOwners(input_api, 2666 results = presubmit_canned_checks.CheckOwners(input_api,
2672 presubmit.OutputApi, author_counts_as_owner=author_counts_as_owner) 2667 presubmit.OutputApi)
2673 if results: 2668 if results:
2674 results[0].handle(output) 2669 results[0].handle(output)
2675 self.assertEquals(output.getvalue(), expected_output) 2670 self.assertEquals(output.getvalue(), expected_output)
2676 2671
2677 def testCannedCheckOwners_Approved(self): 2672 def testCannedCheckOwners_Approved(self):
2678 response = { 2673 response = {
2679 "owner_email": "john@example.com", 2674 "owner_email": "john@example.com",
2680 "messages": [ 2675 "messages": [
2681 { 2676 {
2682 "sender": "ben@example.com", "text": "foo", "approval": True, 2677 "sender": "ben@example.com", "text": "foo", "approval": True,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 self.AssertOwnersWorks(is_committing=False, expected_output='') 2785 self.AssertOwnersWorks(is_committing=False, expected_output='')
2791 2786
2792 def testCannedCheckOwners_OnlyOwnerLGTM(self): 2787 def testCannedCheckOwners_OnlyOwnerLGTM(self):
2793 self.AssertOwnersWorks(approvers=set(['john@example.com']), 2788 self.AssertOwnersWorks(approvers=set(['john@example.com']),
2794 expected_output='Missing LGTM from someone ' 2789 expected_output='Missing LGTM from someone '
2795 'other than john@example.com\n') 2790 'other than john@example.com\n')
2796 self.AssertOwnersWorks(approvers=set(['john@example.com']), 2791 self.AssertOwnersWorks(approvers=set(['john@example.com']),
2797 is_committing=False, 2792 is_committing=False,
2798 expected_output='') 2793 expected_output='')
2799 2794
2800 def testCannedCheckOwners_AuthorCountsAsOwner(self):
2801 self.AssertOwnersWorks(approvers=set(['john@example.com',
2802 'brett@example.com']),
2803 reviewers=set(['john@example.com',
2804 'ben@example.com']),
2805 uncovered_files=set(['foo/xyz.cc', 'foo/bar.cc']),
2806 expected_output='Missing LGTM from an OWNER '
2807 'for these files:\n'
2808 ' foo/bar.cc\n'
2809 ' foo/xyz.cc\n',
2810 author_counts_as_owner=False)
2811
2812 def testCannedCheckOwners_TBR(self): 2795 def testCannedCheckOwners_TBR(self):
2813 self.AssertOwnersWorks(tbr=True, 2796 self.AssertOwnersWorks(tbr=True,
2814 expected_output='--tbr was specified, skipping OWNERS check\n') 2797 expected_output='--tbr was specified, skipping OWNERS check\n')
2815 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='') 2798 self.AssertOwnersWorks(tbr=True, is_committing=False, expected_output='')
2816 2799
2817 def testCannedCheckOwners_WithoutOwnerLGTM(self): 2800 def testCannedCheckOwners_WithoutOwnerLGTM(self):
2818 self.AssertOwnersWorks(uncovered_files=set(['foo']), 2801 self.AssertOwnersWorks(uncovered_files=set(['foo']),
2819 expected_output='Missing LGTM from an OWNER for these files:\n' 2802 expected_output='Missing LGTM from an OWNER for these files:\n'
2820 ' foo\n') 2803 ' foo\n')
2821 self.AssertOwnersWorks(uncovered_files=set(['foo']), 2804 self.AssertOwnersWorks(uncovered_files=set(['foo']),
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2921 owners_check=False) 2904 owners_check=False)
2922 self.assertEqual(1, len(results)) 2905 self.assertEqual(1, len(results))
2923 self.assertEqual( 2906 self.assertEqual(
2924 'Found line ending with white spaces in:', results[0]._message) 2907 'Found line ending with white spaces in:', results[0]._message)
2925 self.checkstdout('') 2908 self.checkstdout('')
2926 2909
2927 2910
2928 if __name__ == '__main__': 2911 if __name__ == '__main__':
2929 import unittest 2912 import unittest
2930 unittest.main() 2913 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