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 import StringIO | 8 import StringIO |
9 | 9 |
10 # Fixes include path. | 10 # Fixes include path. |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 # Test CheckSvnProperty at the same time. | 1379 # Test CheckSvnProperty at the same time. |
1380 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1380 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1381 'svn:eol-style', 'LF', '', True, | 1381 'svn:eol-style', 'LF', '', True, |
1382 presubmit.OutputApi.PresubmitError, True) | 1382 presubmit.OutputApi.PresubmitError, True) |
1383 | 1383 |
1384 def testCheckChangeSvnEolStyleUpload(self): | 1384 def testCheckChangeSvnEolStyleUpload(self): |
1385 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1385 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1386 'svn:eol-style', 'LF', '', False, | 1386 'svn:eol-style', 'LF', '', False, |
1387 presubmit.OutputApi.PresubmitNotifyResult, True) | 1387 presubmit.OutputApi.PresubmitNotifyResult, True) |
1388 | 1388 |
1389 def _LicenseCheck(self, text, license, committing, expected_result): | 1389 def _LicenseCheck(self, text, license, committing, expected_result, **kwargs): |
1390 change = self.mox.CreateMock(presubmit.SvnChange) | 1390 change = self.mox.CreateMock(presubmit.SvnChange) |
1391 change.scm = 'svn' | 1391 change.scm = 'svn' |
1392 input_api = self.MockInputApi(change, committing) | 1392 input_api = self.MockInputApi(change, committing) |
1393 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1393 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1394 input_api.AffectedSourceFiles(42).AndReturn([affected_file]) | 1394 input_api.AffectedSourceFiles(42).AndReturn([affected_file]) |
1395 input_api.ReadFile(affected_file, 'rb').AndReturn(text) | 1395 input_api.ReadFile(affected_file, 'rb').AndReturn(text) |
1396 if expected_result: | 1396 if expected_result: |
1397 affected_file.LocalPath().AndReturn('bleh') | 1397 affected_file.LocalPath().AndReturn('bleh') |
1398 | 1398 |
1399 self.mox.ReplayAll() | 1399 self.mox.ReplayAll() |
1400 result = presubmit_canned_checks.CheckLicense( | 1400 result = presubmit_canned_checks.CheckLicense( |
1401 input_api, presubmit.OutputApi, license, 42) | 1401 input_api, presubmit.OutputApi, license, source_file_filter=42, |
| 1402 **kwargs) |
1402 if expected_result: | 1403 if expected_result: |
1403 self.assertEqual(len(result), 1) | 1404 self.assertEqual(len(result), 1) |
1404 self.assertEqual(result[0].__class__, expected_result) | 1405 self.assertEqual(result[0].__class__, expected_result) |
1405 else: | 1406 else: |
1406 self.assertEqual(result, []) | 1407 self.assertEqual(result, []) |
1407 | 1408 |
1408 def testCheckLicenseSuccess(self): | 1409 def testCheckLicenseSuccess(self): |
1409 text = ( | 1410 text = ( |
1410 "#!/bin/python\n" | 1411 "#!/bin/python\n" |
1411 "# Copyright (c) 2037 Nobody.\n" | 1412 "# Copyright (c) 2037 Nobody.\n" |
(...skipping 27 matching lines...) Expand all Loading... |
1439 "# All Rights Reserved.\n" | 1440 "# All Rights Reserved.\n" |
1440 "print 'foo'\n" | 1441 "print 'foo'\n" |
1441 ) | 1442 ) |
1442 license = ( | 1443 license = ( |
1443 r".*? Copyright \(c\) 0007 Nobody." "\n" | 1444 r".*? Copyright \(c\) 0007 Nobody." "\n" |
1444 r".*? All Rights Reserved\." "\n" | 1445 r".*? All Rights Reserved\." "\n" |
1445 ) | 1446 ) |
1446 self._LicenseCheck(text, license, False, | 1447 self._LicenseCheck(text, license, False, |
1447 presubmit.OutputApi.PresubmitNotifyResult) | 1448 presubmit.OutputApi.PresubmitNotifyResult) |
1448 | 1449 |
| 1450 def testCheckLicenseEmptySuccess(self): |
| 1451 text = '' |
| 1452 license = ( |
| 1453 r".*? Copyright \(c\) 2037 Nobody." "\n" |
| 1454 r".*? All Rights Reserved\." "\n" |
| 1455 ) |
| 1456 self._LicenseCheck(text, license, True, None, accept_empty_files=True) |
| 1457 |
1449 def testCannedCheckSvnAccidentalSubmission(self): | 1458 def testCannedCheckSvnAccidentalSubmission(self): |
1450 modified_dir_file = 'foo/' | 1459 modified_dir_file = 'foo/' |
1451 accidental_submssion_file = 'foo/bar.cc' | 1460 accidental_submssion_file = 'foo/bar.cc' |
1452 | 1461 |
1453 change = self.mox.CreateMock(presubmit.SvnChange) | 1462 change = self.mox.CreateMock(presubmit.SvnChange) |
1454 change.scm = 'svn' | 1463 change.scm = 'svn' |
1455 change.GetModifiedFiles().AndReturn([modified_dir_file]) | 1464 change.GetModifiedFiles().AndReturn([modified_dir_file]) |
1456 change.GetAllModifiedFiles().AndReturn([modified_dir_file, | 1465 change.GetAllModifiedFiles().AndReturn([modified_dir_file, |
1457 accidental_submssion_file]) | 1466 accidental_submssion_file]) |
1458 input_api = self.MockInputApi(change, True) | 1467 input_api = self.MockInputApi(change, True) |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 1748 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
1740 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 1749 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
1741 self.assertEquals(len(results), 1) | 1750 self.assertEquals(len(results), 1) |
1742 self.assertEquals(results[0].__class__, | 1751 self.assertEquals(results[0].__class__, |
1743 presubmit.OutputApi.PresubmitNotifyResult) | 1752 presubmit.OutputApi.PresubmitNotifyResult) |
1744 | 1753 |
1745 | 1754 |
1746 if __name__ == '__main__': | 1755 if __name__ == '__main__': |
1747 import unittest | 1756 import unittest |
1748 unittest.main() | 1757 unittest.main() |
OLD | NEW |