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

Side by Side Diff: tests/presubmit_unittest.py

Issue 6657028: Actually check Rietveld for LGTMs in CheckOwners() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rename is_tbr to tbr, remove optional email_regexp param from CheckOwners() Created 9 years, 9 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_support.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/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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 def testMembersChanged(self): 693 def testMembersChanged(self):
694 self.mox.ReplayAll() 694 self.mox.ReplayAll()
695 members = [ 695 members = [
696 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', 696 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles',
697 'AffectedTextFiles', 697 'AffectedTextFiles',
698 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', 698 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST',
699 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 699 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths',
700 'LocalToDepotPath', 700 'LocalToDepotPath',
701 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', 701 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths',
702 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', 702 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ',
703 'is_committing', 'json', 'marshal', 'os_path', 'owners_db', 'pickle', 703 'host_url', 'is_committing', 'json', 'marshal', 'os_path',
704 'platform', 'python_executable', 're', 'subprocess', 'tempfile', 704 'owners_db', 'pickle', 'platform', 'python_executable', 're',
705 'traceback', 'unittest', 'urllib2', 'version', 705 'subprocess', 'tbr', 'tempfile', 'traceback', 'unittest', 'urllib2',
706 'version',
706 ] 707 ]
707 # If this test fails, you should add the relevant test. 708 # If this test fails, you should add the relevant test.
708 self.compareMembers(presubmit.InputApi(self.fake_change, './.', False), 709 self.compareMembers(presubmit.InputApi(self.fake_change, './.', False),
709 members) 710 members)
710 711
711 def testDepotToLocalPath(self): 712 def testDepotToLocalPath(self):
712 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( 713 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn(
713 {'Path': 'prout'}) 714 {'Path': 'prout'})
714 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) 715 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({})
715 self.mox.ReplayAll() 716 self.mox.ReplayAll()
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 self.failUnless(len(output) == 1) 1181 self.failUnless(len(output) == 1)
1181 self.failUnless(files[0] == output[0]) 1182 self.failUnless(files[0] == output[0])
1182 1183
1183 1184
1184 class GclChangeUnittest(PresubmitTestsBase): 1185 class GclChangeUnittest(PresubmitTestsBase):
1185 def testMembersChanged(self): 1186 def testMembersChanged(self):
1186 members = [ 1187 members = [
1187 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 1188 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
1188 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', 1189 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
1189 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 1190 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
1190 'approvers', 'issue', 'patchset', 'scm', 'tags', 1191 'issue', 'patchset', 'scm', 'tags',
1191 ] 1192 ]
1192 # If this test fails, you should add the relevant test. 1193 # If this test fails, you should add the relevant test.
1193 self.mox.ReplayAll() 1194 self.mox.ReplayAll()
1194 1195
1195 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1196 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
1196 0, 0) 1197 0, 0)
1197 self.compareMembers(change, members) 1198 self.compareMembers(change, members)
1198 1199
1199 1200
1200 class CannedChecksUnittest(PresubmitTestsBase): 1201 class CannedChecksUnittest(PresubmitTestsBase):
1201 """Tests presubmit_canned_checks.py.""" 1202 """Tests presubmit_canned_checks.py."""
1202 1203
1203 def setUp(self): 1204 def setUp(self):
1204 PresubmitTestsBase.setUp(self) 1205 PresubmitTestsBase.setUp(self)
1205 1206
1206 def MockInputApi(self, change, committing): 1207 def MockInputApi(self, change, committing):
1207 input_api = self.mox.CreateMock(presubmit.InputApi) 1208 input_api = self.mox.CreateMock(presubmit.InputApi)
1208 input_api.cStringIO = presubmit.cStringIO 1209 input_api.cStringIO = presubmit.cStringIO
1209 input_api.os_path = presubmit.os.path 1210 input_api.os_path = presubmit.os.path
1210 input_api.re = presubmit.re 1211 input_api.re = presubmit.re
1211 input_api.traceback = presubmit.traceback 1212 input_api.traceback = presubmit.traceback
1212 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) 1213 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2)
1213 input_api.unittest = unittest 1214 input_api.unittest = unittest
1214 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess) 1215 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess)
1215 1216
1216 input_api.change = change 1217 input_api.change = change
1218 input_api.host_url = 'http://localhost'
1217 input_api.is_committing = committing 1219 input_api.is_committing = committing
1220 input_api.tbr = False
1218 input_api.python_executable = 'pyyyyython' 1221 input_api.python_executable = 'pyyyyython'
1219 return input_api 1222 return input_api
1220 1223
1221 def testMembersChanged(self): 1224 def testMembersChanged(self):
1222 self.mox.ReplayAll() 1225 self.mox.ReplayAll()
1223 members = [ 1226 members = [
1224 'CheckChangeHasBugField', 'CheckChangeHasDescription', 1227 'CheckChangeHasBugField', 'CheckChangeHasDescription',
1225 'CheckChangeHasNoStrayWhitespace', 1228 'CheckChangeHasNoStrayWhitespace',
1226 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', 1229 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
1227 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', 1230 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 }""") 1853 }""")
1851 connection.close() 1854 connection.close()
1852 self.mox.ReplayAll() 1855 self.mox.ReplayAll()
1853 1856
1854 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 1857 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
1855 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 1858 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
1856 self.assertEquals(len(results), 1) 1859 self.assertEquals(len(results), 1)
1857 self.assertEquals(results[0].__class__, 1860 self.assertEquals(results[0].__class__,
1858 presubmit.OutputApi.PresubmitNotifyResult) 1861 presubmit.OutputApi.PresubmitNotifyResult)
1859 1862
1860 def OwnersTest(self, is_committing, change_tags=None, 1863 def OwnersTest(self, is_committing, tbr=False, change_tags=None,
1861 suggested_reviewers=None, approvers=None, 1864 suggested_reviewers=None, approvers=None,
1862 uncovered_files=None, expected_results=None): 1865 uncovered_files=None, expected_results=None):
1863 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 1866 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
1864 affected_file.LocalPath().AndReturn('foo.cc') 1867 affected_file.LocalPath().AndReturn('foo.cc')
1865 change = self.mox.CreateMock(presubmit.Change) 1868 change = self.mox.CreateMock(presubmit.Change)
1866 change.AffectedFiles(None).AndReturn([affected_file]) 1869 change.AffectedFiles(None).AndReturn([affected_file])
1867 1870
1868 input_api = self.MockInputApi(change, False) 1871 input_api = self.MockInputApi(change, False)
1869 fake_db = self.mox.CreateMock(owners.Database) 1872 fake_db = self.mox.CreateMock(owners.Database)
1873 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
1870 input_api.owners_db = fake_db 1874 input_api.owners_db = fake_db
1871 input_api.is_committing = is_committing 1875 input_api.is_committing = is_committing
1876 input_api.tbr = tbr
1872 1877
1873 if is_committing: 1878 if is_committing and not tbr:
1874 change.approvers = approvers 1879 change.issue = '1'
1880 messages = list('{"sender": "' + a + '","text": "lgtm"}' for
1881 a in approvers)
1882 rietveld_response = ('{"owner": "john@example.com",'
1883 '"messages": [' + ','.join(messages) + ']}')
1884 input_api.urllib2.urlopen(
1885 input_api.host_url + '/api/1?messages=true').AndReturn(
1886 StringIO.StringIO(rietveld_response))
1887 input_api.json = presubmit.json
1875 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( 1888 fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn(
1876 uncovered_files) 1889 uncovered_files)
1877 else: 1890 elif not is_committing:
1878 change.tags = change_tags 1891 change.tags = change_tags
1879 if not change_tags.get('R'): 1892 if not change_tags.get('R'):
1880 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers) 1893 fake_db.reviewers_for(set(['foo.cc'])).AndReturn(suggested_reviewers)
1881 1894
1882 self.mox.ReplayAll() 1895 self.mox.ReplayAll()
1883 results = presubmit_canned_checks.CheckOwners(input_api, 1896 results = presubmit_canned_checks.CheckOwners(input_api,
1884 presubmit.OutputApi, None) 1897 presubmit.OutputApi)
1885 self.assertEquals(len(results), len(expected_results)) 1898 self.assertEquals(len(results), len(expected_results))
1886 if results and expected_results: 1899 if results and expected_results:
1887 output = StringIO.StringIO() 1900 output = StringIO.StringIO()
1888 unused_input = StringIO.StringIO() 1901 unused_input = StringIO.StringIO()
1889 results[0]._Handle(output, unused_input) 1902 results[0]._Handle(output, unused_input)
1890 self.assertEquals(output.getvalue(), expected_results[0]) 1903 self.assertEquals(output.getvalue(), expected_results[0])
1891 1904
1892 def testCannedCheckOwners_WithReviewer(self): 1905 def testCannedCheckOwners_WithReviewer(self):
1893 self.OwnersTest(is_committing=False, change_tags={'R': 'ben@example.com'}, 1906 self.OwnersTest(is_committing=False, change_tags={'R': 'ben@example.com'},
1894 expected_results=[]) 1907 expected_results=[])
1908 self.OwnersTest(is_committing=False, tbr=True,
1909 change_tags={'R': 'ben@example.com'}, expected_results=[])
1895 1910
1896 def testCannedCheckOwners_NoReviewer(self): 1911 def testCannedCheckOwners_NoReviewer(self):
1897 self.OwnersTest(is_committing=False, change_tags={}, 1912 self.OwnersTest(is_committing=False, change_tags={},
1898 suggested_reviewers=['ben@example.com'], 1913 suggested_reviewers=['ben@example.com'],
1899 expected_results=['ADD: R=ben@example.com\n']) 1914 expected_results=['ADD: R=ben@example.com\n'])
1915 self.OwnersTest(is_committing=False, tbr=True, change_tags={},
1916 suggested_reviewers=['ben@example.com'],
1917 expected_results=['ADD: R=ben@example.com\n'])
1900 1918
1901 def testCannedCheckOwners_CommittingWithoutOwnerLGTM(self): 1919 def testCannedCheckOwners_CommittingWithoutOwnerLGTM(self):
1902 self.OwnersTest(is_committing=True, 1920 self.OwnersTest(is_committing=True,
1903 approvers=set(), 1921 approvers=set(),
1904 uncovered_files=set(['foo.cc']), 1922 uncovered_files=set(['foo.cc']),
1905 expected_results=['Missing owner LGTM for: foo.cc\n']) 1923 expected_results=['Missing LGTM from an OWNER for: foo.cc\n'])
1906 1924
1907 def testCannedCheckOwners_CommittingWithLGTMs(self): 1925 def testCannedCheckOwners_CommittingWithLGTMs(self):
1908 self.OwnersTest(is_committing=True, 1926 self.OwnersTest(is_committing=True,
1909 approvers=set('ben@example.com'), 1927 approvers=set(['ben@example.com']),
1910 uncovered_files=set(), 1928 uncovered_files=set(),
1911 expected_results=[]) 1929 expected_results=[])
1912 1930
1931 def testCannedCheckOwners_TBR(self):
1932 self.OwnersTest(is_committing=True, tbr=True,
1933 approvers=set(),
1934 uncovered_files=set(),
1935 expected_results=['--tbr was specified, skipping OWNERS check\n'])
1913 1936
1914 if __name__ == '__main__': 1937 if __name__ == '__main__':
1915 import unittest 1938 import unittest
1916 unittest.main() 1939 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698