| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 is too confused. | 8 # pylint is too confused. |
| 9 # pylint: disable=E1101,E1103,W0212,W0403 | 9 # pylint: disable=E1101,E1103,W0212,W0403 |
| 10 | 10 |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 self.failUnless(len(output) == 1) | 1174 self.failUnless(len(output) == 1) |
| 1175 self.failUnless(files[0] == output[0]) | 1175 self.failUnless(files[0] == output[0]) |
| 1176 | 1176 |
| 1177 | 1177 |
| 1178 class GclChangeUnittest(PresubmitTestsBase): | 1178 class GclChangeUnittest(PresubmitTestsBase): |
| 1179 def testMembersChanged(self): | 1179 def testMembersChanged(self): |
| 1180 members = [ | 1180 members = [ |
| 1181 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 1181 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', |
| 1182 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', | 1182 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', |
| 1183 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', | 1183 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', |
| 1184 'approvers', 'issue', 'patchset', 'scm', 'tags', | 1184 'issue', 'patchset', 'scm', 'tags', |
| 1185 ] | 1185 ] |
| 1186 # If this test fails, you should add the relevant test. | 1186 # If this test fails, you should add the relevant test. |
| 1187 self.mox.ReplayAll() | 1187 self.mox.ReplayAll() |
| 1188 | 1188 |
| 1189 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 1189 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
| 1190 0, 0) | 1190 0, 0) |
| 1191 self.compareMembers(change, members) | 1191 self.compareMembers(change, members) |
| 1192 | 1192 |
| 1193 | 1193 |
| 1194 class CannedChecksUnittest(PresubmitTestsBase): | 1194 class CannedChecksUnittest(PresubmitTestsBase): |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 uncovered_files=None, expected_results=None): | 1856 uncovered_files=None, expected_results=None): |
| 1857 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1857 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1858 affected_file.LocalPath().AndReturn('foo.cc') | 1858 affected_file.LocalPath().AndReturn('foo.cc') |
| 1859 change = self.mox.CreateMock(presubmit.Change) | 1859 change = self.mox.CreateMock(presubmit.Change) |
| 1860 change.AffectedFiles(None).AndReturn([affected_file]) | 1860 change.AffectedFiles(None).AndReturn([affected_file]) |
| 1861 | 1861 |
| 1862 input_api = self.MockInputApi(change, False) | 1862 input_api = self.MockInputApi(change, False) |
| 1863 fake_db = self.mox.CreateMock(owners.Database) | 1863 fake_db = self.mox.CreateMock(owners.Database) |
| 1864 input_api.owners_db = fake_db | 1864 input_api.owners_db = fake_db |
| 1865 input_api.is_committing = is_committing | 1865 input_api.is_committing = is_committing |
| 1866 codereview_server = None |
| 1867 owners_email_regexp = owners.BASIC_EMAIL_REGEXP |
| 1866 | 1868 |
| 1867 if is_committing: | 1869 if is_committing: |
| 1868 change.approvers = approvers | 1870 change.issue = '1' |
| 1871 codereview_server = 'http://localhost' |
| 1872 messages = list('{"sender": "' + a + '","text": "lgtm"}' for |
| 1873 a in approvers) |
| 1874 rietveld_response = ('{"owner": "john@example.com",' |
| 1875 '"messages": [' + ','.join(messages) + ']}') |
| 1876 input_api.urllib2.urlopen( |
| 1877 'http://localhost/api/1?messages=true').AndReturn( |
| 1878 StringIO.StringIO(rietveld_response)) |
| 1879 input_api.json = presubmit.json |
| 1869 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( | 1880 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( |
| 1870 uncovered_files) | 1881 uncovered_files) |
| 1871 else: | 1882 else: |
| 1872 change.tags = change_tags | 1883 change.tags = change_tags |
| 1873 if not change_tags.get('R'): | 1884 if not change_tags.get('R'): |
| 1874 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers) | 1885 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers) |
| 1875 | 1886 |
| 1876 self.mox.ReplayAll() | 1887 self.mox.ReplayAll() |
| 1877 results = presubmit_canned_checks.CheckOwners(input_api, | 1888 results = presubmit_canned_checks.CheckOwners(input_api, |
| 1878 presubmit.OutputApi, None) | 1889 presubmit.OutputApi, codereview_server, owners_email_regexp, None) |
| 1879 self.assertEquals(len(results), len(expected_results)) | 1890 self.assertEquals(len(results), len(expected_results)) |
| 1880 if results and expected_results: | 1891 if results and expected_results: |
| 1881 output = StringIO.StringIO() | 1892 output = StringIO.StringIO() |
| 1882 unused_input = StringIO.StringIO() | 1893 unused_input = StringIO.StringIO() |
| 1883 results[0]._Handle(output, unused_input) | 1894 results[0]._Handle(output, unused_input) |
| 1884 self.assertEquals(output.getvalue(), expected_results[0]) | 1895 self.assertEquals(output.getvalue(), expected_results[0]) |
| 1885 | 1896 |
| 1886 def testCannedCheckOwners_WithReviewer(self): | 1897 def testCannedCheckOwners_WithReviewer(self): |
| 1887 self.OwnersTest(is_committing=False, change_tags={'R': 'ben@example.com'}, | 1898 self.OwnersTest(is_committing=False, change_tags={'R': 'ben@example.com'}, |
| 1888 expected_results=[]) | 1899 expected_results=[]) |
| 1889 | 1900 |
| 1890 def testCannedCheckOwners_NoReviewer(self): | 1901 def testCannedCheckOwners_NoReviewer(self): |
| 1891 self.OwnersTest(is_committing=False, change_tags={}, | 1902 self.OwnersTest(is_committing=False, change_tags={}, |
| 1892 suggested_reviewers=['ben@example.com'], | 1903 suggested_reviewers=['ben@example.com'], |
| 1893 expected_results=['ADD: R=ben@example.com\n']) | 1904 expected_results=['ADD: R=ben@example.com\n']) |
| 1894 | 1905 |
| 1895 def testCannedCheckOwners_CommittingWithoutOwnerLGTM(self): | 1906 def testCannedCheckOwners_CommittingWithoutOwnerLGTM(self): |
| 1896 self.OwnersTest(is_committing=True, | 1907 self.OwnersTest(is_committing=True, |
| 1897 approvers=set(), | 1908 approvers=set(), |
| 1898 uncovered_files=set(['foo.cc']), | 1909 uncovered_files=set(['foo.cc']), |
| 1899 expected_results=['Missing owner LGTM for: foo.cc\n']) | 1910 expected_results=['Missing LGTM from an OWNER for: foo.cc\n']) |
| 1900 | 1911 |
| 1901 def testCannedCheckOwners_CommittingWithLGTMs(self): | 1912 def testCannedCheckOwners_CommittingWithLGTMs(self): |
| 1902 self.OwnersTest(is_committing=True, | 1913 self.OwnersTest(is_committing=True, |
| 1903 approvers=set('ben@example.com'), | 1914 approvers=set(['ben@example.com']), |
| 1904 uncovered_files=set(), | 1915 uncovered_files=set(), |
| 1905 expected_results=[]) | 1916 expected_results=[]) |
| 1906 | 1917 |
| 1907 | 1918 |
| 1908 if __name__ == '__main__': | 1919 if __name__ == '__main__': |
| 1909 import unittest | 1920 import unittest |
| 1910 unittest.main() | 1921 unittest.main() |
| OLD | NEW |