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

Side by Side Diff: tests/presubmit_unittest.py

Issue 215153004: For determining OWNERS, drop reviewers specified via '-r' that aren't in email address format. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Drop non-email addresses instead Created 6 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 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2565 self.mox.ReplayAll() 2565 self.mox.ReplayAll()
2566 2566
2567 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 2567 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
2568 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 2568 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
2569 self.assertEquals(len(results), 1) 2569 self.assertEquals(len(results), 1)
2570 self.assertEquals(results[0].__class__, 2570 self.assertEquals(results[0].__class__,
2571 presubmit.OutputApi.PresubmitNotifyResult) 2571 presubmit.OutputApi.PresubmitNotifyResult)
2572 2572
2573 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None, 2573 def AssertOwnersWorks(self, tbr=False, issue='1', approvers=None,
2574 reviewers=None, is_committing=True, rietveld_response=None, 2574 reviewers=None, is_committing=True, rietveld_response=None,
2575 uncovered_files=None, expected_output='', author_counts_as_owner=True): 2575 uncovered_files=None, expected_output='', author_counts_as_owner=True,
2576 manually_specified_reviewers=None):
2576 if approvers is None: 2577 if approvers is None:
2577 # The set of people who lgtm'ed a change. 2578 # The set of people who lgtm'ed a change.
2578 approvers = set() 2579 approvers = set()
2579 if reviewers is None: 2580 if reviewers is None:
2580 # The set of people needed to lgtm a change. We default to 2581 # The set of people needed to lgtm a change. We default to
2581 # the same list as the people who approved it. We use 'reviewers' 2582 # the same list as the people who approved it. We use 'reviewers'
2582 # to avoid a name collision w/ owners.py. 2583 # to avoid a name collision w/ owners.py.
2583 reviewers = approvers 2584 reviewers = approvers
2584 if uncovered_files is None: 2585 if uncovered_files is None:
2585 uncovered_files = set() 2586 uncovered_files = set()
2587 if manually_specified_reviewers is None:
2588 manually_specified_reviewers = []
2586 2589
2587 change = self.mox.CreateMock(presubmit.Change) 2590 change = self.mox.CreateMock(presubmit.Change)
2588 change.issue = issue 2591 change.issue = issue
2589 change.author_email = 'john@example.com' 2592 change.author_email = 'john@example.com'
2590 change.R = '' 2593 change.R = ','.join(manually_specified_reviewers)
2591 change.TBR = '' 2594 change.TBR = ''
2592 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 2595 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
2593 input_api = self.MockInputApi(change, False) 2596 input_api = self.MockInputApi(change, False)
2594 fake_db = self.mox.CreateMock(owners.Database) 2597 fake_db = self.mox.CreateMock(owners.Database)
2595 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) 2598 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
2596 input_api.owners_db = fake_db 2599 input_api.owners_db = fake_db
2597 input_api.is_committing = is_committing 2600 input_api.is_committing = is_committing
2598 input_api.tbr = tbr 2601 input_api.tbr = tbr
2599 2602
2600 if not is_committing or (not tbr and issue): 2603 if not is_committing or (not tbr and issue):
2601 affected_file.LocalPath().AndReturn('foo/xyz.cc') 2604 affected_file.LocalPath().AndReturn('foo/xyz.cc')
2602 change.AffectedFiles(file_filter=None).AndReturn([affected_file]) 2605 change.AffectedFiles(file_filter=None).AndReturn([affected_file])
2603 if issue and not rietveld_response: 2606 if issue and not rietveld_response:
2604 rietveld_response = { 2607 rietveld_response = {
2605 "owner_email": change.author_email, 2608 "owner_email": change.author_email,
2606 "messages": [ 2609 "messages": [
2607 {"sender": a, "text": "I approve", "approval": True} 2610 {"sender": a, "text": "I approve", "approval": True}
2608 for a in approvers 2611 for a in approvers
2609 ], 2612 ],
2610 "reviewers": reviewers 2613 "reviewers": reviewers
2611 } 2614 }
2612 2615
2613 if is_committing: 2616 if is_committing:
2614 people = approvers 2617 people = approvers
2615 else: 2618 else:
2616 people = reviewers 2619 people = reviewers
2617 change.R = ','.join(reviewers)
2618 2620
2619 if issue: 2621 if issue:
2620 input_api.rietveld.get_issue_properties( 2622 input_api.rietveld.get_issue_properties(
2621 issue=int(input_api.change.issue), messages=True).AndReturn( 2623 issue=int(input_api.change.issue), messages=True).AndReturn(
2622 rietveld_response) 2624 rietveld_response)
2623 2625
2624 if author_counts_as_owner: 2626 if author_counts_as_owner:
2625 people.add(change.author_email) 2627 people.add(change.author_email)
2626 fake_db.files_not_covered_by(set(['foo/xyz.cc']), 2628 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2627 people).AndReturn(uncovered_files) 2629 people).AndReturn(uncovered_files)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 "issue number, so we can't check it for approvals.\n") 2724 "issue number, so we can't check it for approvals.\n")
2723 self.AssertOwnersWorks(issue=None, 2725 self.AssertOwnersWorks(issue=None,
2724 is_committing=False, 2726 is_committing=False,
2725 uncovered_files=set(['foo']), 2727 uncovered_files=set(['foo']),
2726 expected_output='Missing OWNER reviewers for these files:\n' 2728 expected_output='Missing OWNER reviewers for these files:\n'
2727 ' foo\n') 2729 ' foo\n')
2728 2730
2729 def testCannedCheckOwners_NoIssueLocalReviewers(self): 2731 def testCannedCheckOwners_NoIssueLocalReviewers(self):
2730 self.AssertOwnersWorks(issue=None, 2732 self.AssertOwnersWorks(issue=None,
2731 reviewers=set(['jane@example.com']), 2733 reviewers=set(['jane@example.com']),
2734 manually_specified_reviewers=['jane@example.com'],
2732 expected_output="OWNERS check failed: this change has no Rietveld " 2735 expected_output="OWNERS check failed: this change has no Rietveld "
2733 "issue number, so we can't check it for approvals.\n") 2736 "issue number, so we can't check it for approvals.\n")
2734 self.AssertOwnersWorks(issue=None, 2737 self.AssertOwnersWorks(issue=None,
2735 reviewers=set(['jane@example.com']), 2738 reviewers=set(['jane@example.com']),
2739 manually_specified_reviewers=['jane@example.com'],
2736 is_committing=False, 2740 is_committing=False,
2737 expected_output='') 2741 expected_output='')
2738 2742
2743 def testCannedCheckOwners_NoIssueLocalReviewersDontInferEmailDomain(self):
2744 self.AssertOwnersWorks(issue=None,
2745 reviewers=set(['jane']),
2746 manually_specified_reviewers=['jane@example.com'],
2747 expected_output="OWNERS check failed: this change has no Rietveld "
2748 "issue number, so we can't check it for approvals.\n")
2749 self.AssertOwnersWorks(issue=None,
2750 uncovered_files=set(['foo']),
2751 manually_specified_reviewers=['jane'],
2752 is_committing=False,
2753 expected_output='Missing OWNER reviewers for these files:\n'
2754 ' foo\n')
2755
2739 def testCannedCheckOwners_NoLGTM(self): 2756 def testCannedCheckOwners_NoLGTM(self):
2740 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' 2757 self.AssertOwnersWorks(expected_output='Missing LGTM from someone '
2741 'other than john@example.com\n') 2758 'other than john@example.com\n')
2742 self.AssertOwnersWorks(is_committing=False, expected_output='') 2759 self.AssertOwnersWorks(is_committing=False, expected_output='')
2743 2760
2744 def testCannedCheckOwners_OnlyOwnerLGTM(self): 2761 def testCannedCheckOwners_OnlyOwnerLGTM(self):
2745 self.AssertOwnersWorks(approvers=set(['john@example.com']), 2762 self.AssertOwnersWorks(approvers=set(['john@example.com']),
2746 expected_output='Missing LGTM from someone ' 2763 expected_output='Missing LGTM from someone '
2747 'other than john@example.com\n') 2764 'other than john@example.com\n')
2748 self.AssertOwnersWorks(approvers=set(['john@example.com']), 2765 self.AssertOwnersWorks(approvers=set(['john@example.com']),
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 owners_check=False) 2890 owners_check=False)
2874 self.assertEqual(1, len(results)) 2891 self.assertEqual(1, len(results))
2875 self.assertEqual( 2892 self.assertEqual(
2876 'Found line ending with white spaces in:', results[0]._message) 2893 'Found line ending with white spaces in:', results[0]._message)
2877 self.checkstdout('') 2894 self.checkstdout('')
2878 2895
2879 2896
2880 if __name__ == '__main__': 2897 if __name__ == '__main__':
2881 import unittest 2898 import unittest
2882 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