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

Side by Side Diff: tests/presubmit_unittest.py

Issue 12377023: Use author as determined from scm if we can not get it from rietveld (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: update w/ review feedback Created 7 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_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 logging 10 import logging
(...skipping 2215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 if reviewers is None: 2226 if reviewers is None:
2227 # The set of people needed to lgtm a change. We default to 2227 # The set of people needed to lgtm a change. We default to
2228 # the same list as the people who approved it. We use 'reviewers' 2228 # the same list as the people who approved it. We use 'reviewers'
2229 # to avoid a name collision w/ owners.py. 2229 # to avoid a name collision w/ owners.py.
2230 reviewers = approvers 2230 reviewers = approvers
2231 if uncovered_files is None: 2231 if uncovered_files is None:
2232 uncovered_files = set() 2232 uncovered_files = set()
2233 2233
2234 change = self.mox.CreateMock(presubmit.Change) 2234 change = self.mox.CreateMock(presubmit.Change)
2235 change.issue = issue 2235 change.issue = issue
2236 change.author_email = 'john@example.com'
2236 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 2237 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
2237 input_api = self.MockInputApi(change, False) 2238 input_api = self.MockInputApi(change, False)
2238 fake_db = self.mox.CreateMock(owners.Database) 2239 fake_db = self.mox.CreateMock(owners.Database)
2239 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) 2240 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
2240 input_api.owners_db = fake_db 2241 input_api.owners_db = fake_db
2241 input_api.is_committing = is_committing 2242 input_api.is_committing = is_committing
2242 input_api.tbr = tbr 2243 input_api.tbr = tbr
2243 2244
2244 if not is_committing or (not tbr and issue): 2245 if not is_committing or (not tbr and issue):
2245 affected_file.LocalPath().AndReturn('foo/xyz.cc') 2246 affected_file.LocalPath().AndReturn('foo/xyz.cc')
2246 change.AffectedFiles(file_filter=None).AndReturn([affected_file]) 2247 change.AffectedFiles(file_filter=None).AndReturn([affected_file])
2247 owner_email = 'john@example.com'
2248 if not rietveld_response: 2248 if not rietveld_response:
2249 rietveld_response = { 2249 rietveld_response = {
2250 "owner_email": owner_email, 2250 "owner_email": change.author_email,
2251 "messages": [ 2251 "messages": [
2252 {"sender": a, "text": "I approve", "approval": True} 2252 {"sender": a, "text": "I approve", "approval": True}
2253 for a in approvers 2253 for a in approvers
2254 ], 2254 ],
2255 "reviewers": reviewers 2255 "reviewers": reviewers
2256 } 2256 }
2257 2257
2258 if is_committing: 2258 if is_committing:
2259 people = approvers 2259 people = approvers
2260 else: 2260 else:
2261 people = reviewers 2261 people = reviewers
2262 2262
2263 if issue: 2263 if issue:
2264 input_api.rietveld.get_issue_properties( 2264 input_api.rietveld.get_issue_properties(
2265 issue=int(input_api.change.issue), messages=True).AndReturn( 2265 issue=int(input_api.change.issue), messages=True).AndReturn(
2266 rietveld_response) 2266 rietveld_response)
2267 people.add(owner_email)
2268 2267
2269 if author_counts_as_owner: 2268 if author_counts_as_owner:
2269 people.add(change.author_email)
2270 fake_db.files_not_covered_by(set(['foo/xyz.cc']), 2270 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2271 people).AndReturn(uncovered_files) 2271 people).AndReturn(uncovered_files)
2272 else: 2272 else:
2273 people.discard(change.author_email)
2273 fake_db.files_not_covered_by(set(['foo/xyz.cc']), 2274 fake_db.files_not_covered_by(set(['foo/xyz.cc']),
2274 people.difference(set([owner_email]))).AndReturn(uncovered_files) 2275 people).AndReturn(uncovered_files)
2275 if not is_committing and uncovered_files: 2276 if not is_committing and uncovered_files:
2276 fake_db.reviewers_for(set(['foo/xyz.cc']), 2277 fake_db.reviewers_for(set(['foo/xyz.cc']),
2277 owner_email if issue else '').AndReturn(owner_email) 2278 change.author_email).AndReturn(change.author_email)
2278 2279
2279 self.mox.ReplayAll() 2280 self.mox.ReplayAll()
2280 output = presubmit.PresubmitOutput() 2281 output = presubmit.PresubmitOutput()
2281 results = presubmit_canned_checks.CheckOwners(input_api, 2282 results = presubmit_canned_checks.CheckOwners(input_api,
2282 presubmit.OutputApi, author_counts_as_owner=author_counts_as_owner) 2283 presubmit.OutputApi, author_counts_as_owner=author_counts_as_owner)
2283 if results: 2284 if results:
2284 results[0].handle(output) 2285 results[0].handle(output)
2285 self.assertEquals(output.getvalue(), expected_output) 2286 self.assertEquals(output.getvalue(), expected_output)
2286 2287
2287 def testCannedCheckOwners_Approved(self): 2288 def testCannedCheckOwners_Approved(self):
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 2361
2361 def testCannedCheckOwners_NoIssue(self): 2362 def testCannedCheckOwners_NoIssue(self):
2362 self.AssertOwnersWorks(issue=None, 2363 self.AssertOwnersWorks(issue=None,
2363 uncovered_files=set(['foo']), 2364 uncovered_files=set(['foo']),
2364 expected_output="OWNERS check failed: this change has no Rietveld " 2365 expected_output="OWNERS check failed: this change has no Rietveld "
2365 "issue number, so we can't check it for approvals.\n") 2366 "issue number, so we can't check it for approvals.\n")
2366 self.AssertOwnersWorks(issue=None, 2367 self.AssertOwnersWorks(issue=None,
2367 is_committing=False, 2368 is_committing=False,
2368 uncovered_files=set(['foo']), 2369 uncovered_files=set(['foo']),
2369 expected_output='Missing OWNER reviewers for these files:\n' 2370 expected_output='Missing OWNER reviewers for these files:\n'
2370 ' foo\n' 2371 ' foo\n')
2371 'Until the issue is uploaded, this list will include '
2372 'files for which you are an OWNER.\n')
2373 2372
2374 def testCannedCheckOwners_NoLGTM(self): 2373 def testCannedCheckOwners_NoLGTM(self):
2375 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' 2374 self.AssertOwnersWorks(expected_output='Missing LGTM from someone '
2376 'other than john@example.com\n') 2375 'other than john@example.com\n')
2377 self.AssertOwnersWorks(is_committing=False, expected_output='') 2376 self.AssertOwnersWorks(is_committing=False, expected_output='')
2378 2377
2379 def testCannedCheckOwners_OnlyOwnerLGTM(self): 2378 def testCannedCheckOwners_OnlyOwnerLGTM(self):
2380 self.AssertOwnersWorks(approvers=set(['john@example.com']), 2379 self.AssertOwnersWorks(approvers=set(['john@example.com']),
2381 expected_output='Missing LGTM from someone ' 2380 expected_output='Missing LGTM from someone '
2382 'other than john@example.com\n') 2381 'other than john@example.com\n')
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 owners_check=False) 2504 owners_check=False)
2506 self.assertEqual(1, len(results)) 2505 self.assertEqual(1, len(results))
2507 self.assertEqual( 2506 self.assertEqual(
2508 'Found line ending with white spaces in:', results[0]._message) 2507 'Found line ending with white spaces in:', results[0]._message)
2509 self.checkstdout('') 2508 self.checkstdout('')
2510 2509
2511 2510
2512 if __name__ == '__main__': 2511 if __name__ == '__main__':
2513 import unittest 2512 import unittest
2514 unittest.main() 2513 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