| 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 logging | 10 import logging |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 1500 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
| 1501 'CheckChangeHasTestField', | 1501 'CheckChangeHasTestField', |
| 1502 'CheckChangeLintsClean', | 1502 'CheckChangeLintsClean', |
| 1503 'CheckChangeSvnEolStyle', | 1503 'CheckChangeSvnEolStyle', |
| 1504 'CheckChangeWasUploaded', | 1504 'CheckChangeWasUploaded', |
| 1505 'CheckDoNotSubmit', | 1505 'CheckDoNotSubmit', |
| 1506 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 1506 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
| 1507 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', | 1507 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', |
| 1508 'CheckLicense', | 1508 'CheckLicense', |
| 1509 'CheckOwners', | 1509 'CheckOwners', |
| 1510 'CheckIssueNotClosed', |
| 1510 'CheckRietveldTryJobExecution', | 1511 'CheckRietveldTryJobExecution', |
| 1511 'CheckSingletonInHeaders', | 1512 'CheckSingletonInHeaders', |
| 1512 'CheckSvnModifiedDirectories', | 1513 'CheckSvnModifiedDirectories', |
| 1513 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', | 1514 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', |
| 1514 'RunPythonUnitTests', 'RunPylint', | 1515 'RunPythonUnitTests', 'RunPylint', |
| 1515 'RunUnitTests', 'RunUnitTestsInDirectory', | 1516 'RunUnitTests', 'RunUnitTestsInDirectory', |
| 1516 ] | 1517 ] |
| 1517 # If this test fails, you should add the relevant test. | 1518 # If this test fails, you should add the relevant test. |
| 1518 self.compareMembers(presubmit_canned_checks, members) | 1519 self.compareMembers(presubmit_canned_checks, members) |
| 1519 | 1520 |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2245 ], | 2246 ], |
| 2246 "reviewers": reviewers | 2247 "reviewers": reviewers |
| 2247 } | 2248 } |
| 2248 | 2249 |
| 2249 if is_committing: | 2250 if is_committing: |
| 2250 people = approvers | 2251 people = approvers |
| 2251 else: | 2252 else: |
| 2252 people = reviewers | 2253 people = reviewers |
| 2253 | 2254 |
| 2254 if issue: | 2255 if issue: |
| 2255 input_api.rietveld.get_issue_properties( | |
| 2256 int(input_api.change.issue), True).AndReturn(rietveld_response) | |
| 2257 people.add(owner_email) | 2256 people.add(owner_email) |
| 2258 | |
| 2259 fake_db.directories_not_covered_by(set(['foo/xyz.cc']), | 2257 fake_db.directories_not_covered_by(set(['foo/xyz.cc']), |
| 2260 people).AndReturn(uncovered_dirs) | 2258 people).AndReturn(uncovered_dirs) |
| 2261 if not is_committing and uncovered_dirs: | 2259 if not is_committing and uncovered_dirs: |
| 2262 fake_db.reviewers_for(set(['foo/xyz.cc'])).AndReturn(owner_email) | 2260 fake_db.reviewers_for(set(['foo/xyz.cc'])).AndReturn(owner_email) |
| 2263 | 2261 |
| 2264 self.mox.ReplayAll() | 2262 self.mox.ReplayAll() |
| 2265 output = presubmit.PresubmitOutput() | 2263 output = presubmit.PresubmitOutput() |
| 2264 if issue: |
| 2265 issue_props = rietveld_response |
| 2266 else: |
| 2267 issue_props = None |
| 2266 results = presubmit_canned_checks.CheckOwners(input_api, | 2268 results = presubmit_canned_checks.CheckOwners(input_api, |
| 2267 presubmit.OutputApi) | 2269 presubmit.OutputApi, issue_props) |
| 2268 if results: | 2270 if results: |
| 2269 results[0].handle(output) | 2271 results[0].handle(output) |
| 2270 self.assertEquals(output.getvalue(), expected_output) | 2272 self.assertEquals(output.getvalue(), expected_output) |
| 2271 | 2273 |
| 2272 def testCannedCheckOwners_Approved(self): | 2274 def testCannedCheckOwners_Approved(self): |
| 2273 response = { | 2275 response = { |
| 2274 "owner_email": "john@example.com", | 2276 "owner_email": "john@example.com", |
| 2275 "messages": [ | 2277 "messages": [ |
| 2276 { | 2278 { |
| 2277 "sender": "ben@example.com", "text": "foo", "approval": True, | 2279 "sender": "ben@example.com", "text": "foo", "approval": True, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 'directories:\n' | 2389 'directories:\n' |
| 2388 ' foo\n') | 2390 ' foo\n') |
| 2389 | 2391 |
| 2390 def testCannedCheckOwners_WithLGTMs(self): | 2392 def testCannedCheckOwners_WithLGTMs(self): |
| 2391 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2393 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
| 2392 uncovered_dirs=set()) | 2394 uncovered_dirs=set()) |
| 2393 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2395 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
| 2394 is_committing=False, | 2396 is_committing=False, |
| 2395 uncovered_dirs=set()) | 2397 uncovered_dirs=set()) |
| 2396 | 2398 |
| 2399 def testIssueOpen(self): |
| 2400 results = presubmit_canned_checks.CheckIssueNotClosed( |
| 2401 {'closed': False, 'issue': 0}, |
| 2402 presubmit.OutputApi) |
| 2403 self.assertEqual([], results) |
| 2404 |
| 2405 def testIssueClosed(self): |
| 2406 results = presubmit_canned_checks.CheckIssueNotClosed( |
| 2407 {'closed': True, 'issue': 0}, |
| 2408 presubmit.OutputApi) |
| 2409 self.assertEqual(len(results), 1) |
| 2410 self.assertTrue(results[0].fatal) |
| 2411 |
| 2397 def testCannedRunUnitTests(self): | 2412 def testCannedRunUnitTests(self): |
| 2398 change = presubmit.Change( | 2413 change = presubmit.Change( |
| 2399 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) | 2414 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) |
| 2400 input_api = self.MockInputApi(change, False) | 2415 input_api = self.MockInputApi(change, False) |
| 2401 input_api.verbose = True | 2416 input_api.verbose = True |
| 2402 unit_tests = ['allo', 'bar.py'] | 2417 unit_tests = ['allo', 'bar.py'] |
| 2403 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2418 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
| 2404 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2419 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
| 2405 input_api.subprocess.check_call( | 2420 input_api.subprocess.check_call( |
| 2406 ['allo', '--verbose'], cwd=self.fake_root_dir) | 2421 ['allo', '--verbose'], cwd=self.fake_root_dir) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 owners_check=False) | 2499 owners_check=False) |
| 2485 self.assertEqual(1, len(results)) | 2500 self.assertEqual(1, len(results)) |
| 2486 self.assertEqual( | 2501 self.assertEqual( |
| 2487 'Found line ending with white spaces in:', results[0]._message) | 2502 'Found line ending with white spaces in:', results[0]._message) |
| 2488 self.checkstdout('') | 2503 self.checkstdout('') |
| 2489 | 2504 |
| 2490 | 2505 |
| 2491 if __name__ == '__main__': | 2506 if __name__ == '__main__': |
| 2492 import unittest | 2507 import unittest |
| 2493 unittest.main() | 2508 unittest.main() |
| OLD | NEW |