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 functools | 10 import functools |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 self.assertEquals(1, len(output)) | 1761 self.assertEquals(1, len(output)) |
1762 self.assertEquals(files[0], output[0]) | 1762 self.assertEquals(files[0], output[0]) |
1763 | 1763 |
1764 | 1764 |
1765 class ChangeUnittest(PresubmitTestsBase): | 1765 class ChangeUnittest(PresubmitTestsBase): |
1766 def testMembersChanged(self): | 1766 def testMembersChanged(self): |
1767 members = [ | 1767 members = [ |
1768 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 1768 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', |
1769 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', | 1769 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', |
1770 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', | 1770 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', |
1771 'TAG_LINE_RE', | 1771 'SetDescriptionText', 'TAG_LINE_RE', |
1772 'author_email', 'issue', 'patchset', 'scm', 'tags', | 1772 'author_email', 'issue', 'patchset', 'scm', 'tags', |
1773 ] | 1773 ] |
1774 # If this test fails, you should add the relevant test. | 1774 # If this test fails, you should add the relevant test. |
1775 self.mox.ReplayAll() | 1775 self.mox.ReplayAll() |
1776 | 1776 |
1777 change = presubmit.Change( | 1777 change = presubmit.Change( |
1778 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, 'foo') | 1778 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, 'foo') |
1779 self.compareMembers(change, members) | 1779 self.compareMembers(change, members) |
1780 | 1780 |
1781 def testMembers(self): | 1781 def testMembers(self): |
1782 change = presubmit.Change( | 1782 change = presubmit.Change( |
1783 'foo1', 'foo2\nDRU=ro', self.fake_root_dir, [('Y', 'AA')], 3, 5, 'foo3') | 1783 'foo1', 'foo2\nDRU=ro', self.fake_root_dir, [('Y', 'AA')], 3, 5, 'foo3') |
1784 self.assertEquals('foo1', change.Name()) | 1784 self.assertEquals('foo1', change.Name()) |
1785 self.assertEquals('foo2', change.DescriptionText()) | 1785 self.assertEquals('foo2', change.DescriptionText()) |
1786 self.assertEquals('foo3', change.author_email) | 1786 self.assertEquals('foo3', change.author_email) |
1787 self.assertEquals('ro', change.DRU) | 1787 self.assertEquals('ro', change.DRU) |
1788 self.assertEquals(3, change.issue) | 1788 self.assertEquals(3, change.issue) |
1789 self.assertEquals(5, change.patchset) | 1789 self.assertEquals(5, change.patchset) |
1790 self.assertEquals(self.fake_root_dir, change.RepositoryRoot()) | 1790 self.assertEquals(self.fake_root_dir, change.RepositoryRoot()) |
1791 self.assertEquals(1, len(change.AffectedFiles(include_dirs=True))) | 1791 self.assertEquals(1, len(change.AffectedFiles(include_dirs=True))) |
1792 self.assertEquals('Y', change.AffectedFiles(include_dirs=True)[0].Action()) | 1792 self.assertEquals('Y', change.AffectedFiles(include_dirs=True)[0].Action()) |
1793 | 1793 |
| 1794 def testSetDescriptionText(self): |
| 1795 change = presubmit.Change( |
| 1796 '', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5, '') |
| 1797 self.assertEquals('foo', change.DescriptionText()) |
| 1798 self.assertEquals('foo\nDRU=ro', change.FullDescriptionText()) |
| 1799 self.assertEquals('ro', change.DRU) |
| 1800 |
| 1801 change.SetDescriptionText('bar\nWHIZ=bang') |
| 1802 self.assertEquals('bar', change.DescriptionText()) |
| 1803 self.assertEquals('bar\nWHIZ=bang', change.FullDescriptionText()) |
| 1804 self.assertEquals('bang', change.WHIZ) |
| 1805 self.assertFalse(change.DRU) |
| 1806 |
1794 | 1807 |
1795 def CommHelper(input_api, cmd, ret=None, **kwargs): | 1808 def CommHelper(input_api, cmd, ret=None, **kwargs): |
1796 ret = ret or (('', None), 0) | 1809 ret = ret or (('', None), 0) |
1797 input_api.subprocess.communicate( | 1810 input_api.subprocess.communicate( |
1798 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs | 1811 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs |
1799 ).AndReturn(ret) | 1812 ).AndReturn(ret) |
1800 | 1813 |
1801 | 1814 |
1802 class CannedChecksUnittest(PresubmitTestsBase): | 1815 class CannedChecksUnittest(PresubmitTestsBase): |
1803 """Tests presubmit_canned_checks.py.""" | 1816 """Tests presubmit_canned_checks.py.""" |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 # The set of people needed to lgtm a change. We default to | 2580 # The set of people needed to lgtm a change. We default to |
2568 # the same list as the people who approved it. We use 'reviewers' | 2581 # the same list as the people who approved it. We use 'reviewers' |
2569 # to avoid a name collision w/ owners.py. | 2582 # to avoid a name collision w/ owners.py. |
2570 reviewers = approvers | 2583 reviewers = approvers |
2571 if uncovered_files is None: | 2584 if uncovered_files is None: |
2572 uncovered_files = set() | 2585 uncovered_files = set() |
2573 | 2586 |
2574 change = self.mox.CreateMock(presubmit.Change) | 2587 change = self.mox.CreateMock(presubmit.Change) |
2575 change.issue = issue | 2588 change.issue = issue |
2576 change.author_email = 'john@example.com' | 2589 change.author_email = 'john@example.com' |
| 2590 change.R = '' |
| 2591 change.TBR = '' |
2577 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 2592 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
2578 input_api = self.MockInputApi(change, False) | 2593 input_api = self.MockInputApi(change, False) |
2579 fake_db = self.mox.CreateMock(owners.Database) | 2594 fake_db = self.mox.CreateMock(owners.Database) |
2580 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) |
2581 input_api.owners_db = fake_db | 2596 input_api.owners_db = fake_db |
2582 input_api.is_committing = is_committing | 2597 input_api.is_committing = is_committing |
2583 input_api.tbr = tbr | 2598 input_api.tbr = tbr |
2584 | 2599 |
2585 if not is_committing or (not tbr and issue): | 2600 if not is_committing or (not tbr and issue): |
2586 affected_file.LocalPath().AndReturn('foo/xyz.cc') | 2601 affected_file.LocalPath().AndReturn('foo/xyz.cc') |
2587 change.AffectedFiles(file_filter=None).AndReturn([affected_file]) | 2602 change.AffectedFiles(file_filter=None).AndReturn([affected_file]) |
2588 if not rietveld_response: | 2603 if issue and not rietveld_response: |
2589 rietveld_response = { | 2604 rietveld_response = { |
2590 "owner_email": change.author_email, | 2605 "owner_email": change.author_email, |
2591 "messages": [ | 2606 "messages": [ |
2592 {"sender": a, "text": "I approve", "approval": True} | 2607 {"sender": a, "text": "I approve", "approval": True} |
2593 for a in approvers | 2608 for a in approvers |
2594 ], | 2609 ], |
2595 "reviewers": reviewers | 2610 "reviewers": reviewers |
2596 } | 2611 } |
2597 | 2612 |
2598 if is_committing: | 2613 if is_committing: |
2599 people = approvers | 2614 people = approvers |
2600 else: | 2615 else: |
2601 people = reviewers | 2616 people = reviewers |
| 2617 change.R = ','.join(reviewers) |
2602 | 2618 |
2603 if issue: | 2619 if issue: |
2604 input_api.rietveld.get_issue_properties( | 2620 input_api.rietveld.get_issue_properties( |
2605 issue=int(input_api.change.issue), messages=True).AndReturn( | 2621 issue=int(input_api.change.issue), messages=True).AndReturn( |
2606 rietveld_response) | 2622 rietveld_response) |
2607 | 2623 |
2608 if author_counts_as_owner: | 2624 if author_counts_as_owner: |
2609 people.add(change.author_email) | 2625 people.add(change.author_email) |
2610 fake_db.files_not_covered_by(set(['foo/xyz.cc']), | 2626 fake_db.files_not_covered_by(set(['foo/xyz.cc']), |
2611 people).AndReturn(uncovered_files) | 2627 people).AndReturn(uncovered_files) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2703 self.AssertOwnersWorks(issue=None, | 2719 self.AssertOwnersWorks(issue=None, |
2704 uncovered_files=set(['foo']), | 2720 uncovered_files=set(['foo']), |
2705 expected_output="OWNERS check failed: this change has no Rietveld " | 2721 expected_output="OWNERS check failed: this change has no Rietveld " |
2706 "issue number, so we can't check it for approvals.\n") | 2722 "issue number, so we can't check it for approvals.\n") |
2707 self.AssertOwnersWorks(issue=None, | 2723 self.AssertOwnersWorks(issue=None, |
2708 is_committing=False, | 2724 is_committing=False, |
2709 uncovered_files=set(['foo']), | 2725 uncovered_files=set(['foo']), |
2710 expected_output='Missing OWNER reviewers for these files:\n' | 2726 expected_output='Missing OWNER reviewers for these files:\n' |
2711 ' foo\n') | 2727 ' foo\n') |
2712 | 2728 |
| 2729 def testCannedCheckOwners_NoIssueLocalReviewers(self): |
| 2730 self.AssertOwnersWorks(issue=None, |
| 2731 reviewers=set(['jane@example.com']), |
| 2732 expected_output="OWNERS check failed: this change has no Rietveld " |
| 2733 "issue number, so we can't check it for approvals.\n") |
| 2734 self.AssertOwnersWorks(issue=None, |
| 2735 reviewers=set(['jane@example.com']), |
| 2736 is_committing=False, |
| 2737 expected_output='') |
| 2738 |
2713 def testCannedCheckOwners_NoLGTM(self): | 2739 def testCannedCheckOwners_NoLGTM(self): |
2714 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' | 2740 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' |
2715 'other than john@example.com\n') | 2741 'other than john@example.com\n') |
2716 self.AssertOwnersWorks(is_committing=False, expected_output='') | 2742 self.AssertOwnersWorks(is_committing=False, expected_output='') |
2717 | 2743 |
2718 def testCannedCheckOwners_OnlyOwnerLGTM(self): | 2744 def testCannedCheckOwners_OnlyOwnerLGTM(self): |
2719 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2745 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
2720 expected_output='Missing LGTM from someone ' | 2746 expected_output='Missing LGTM from someone ' |
2721 'other than john@example.com\n') | 2747 'other than john@example.com\n') |
2722 self.AssertOwnersWorks(approvers=set(['john@example.com']), | 2748 self.AssertOwnersWorks(approvers=set(['john@example.com']), |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2847 owners_check=False) | 2873 owners_check=False) |
2848 self.assertEqual(1, len(results)) | 2874 self.assertEqual(1, len(results)) |
2849 self.assertEqual( | 2875 self.assertEqual( |
2850 'Found line ending with white spaces in:', results[0]._message) | 2876 'Found line ending with white spaces in:', results[0]._message) |
2851 self.checkstdout('') | 2877 self.checkstdout('') |
2852 | 2878 |
2853 | 2879 |
2854 if __name__ == '__main__': | 2880 if __name__ == '__main__': |
2855 import unittest | 2881 import unittest |
2856 unittest.main() | 2882 unittest.main() |
OLD | NEW |