| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 self.mox.ReplayAll() | 64 self.mox.ReplayAll() |
| 65 members = [ | 65 members = [ |
| 66 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 66 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', |
| 67 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', | 67 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', |
| 68 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 68 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
| 69 'NotImplementedException', 'OutputApi', 'ParseFiles', | 69 'NotImplementedException', 'OutputApi', 'ParseFiles', |
| 70 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', | 70 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', |
| 71 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', | 71 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', |
| 72 'exceptions', 'fnmatch', 'gcl', 'gclient_utils', 'glob', 'json', | 72 'exceptions', 'fnmatch', 'gcl', 'gclient_utils', 'glob', 'json', |
| 73 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', | 73 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', |
| 74 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', 'sys', | 74 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', |
| 75 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 75 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', |
| 76 'warnings', | 76 'warnings', |
| 77 ] | 77 ] |
| 78 # If this test fails, you should add the relevant test. | 78 # If this test fails, you should add the relevant test. |
| 79 self.compareMembers(presubmit, members) | 79 self.compareMembers(presubmit, members) |
| 80 | 80 |
| 81 def testListRelevantPresubmitFiles(self): | 81 def testListRelevantPresubmitFiles(self): |
| 82 join = presubmit.os.path.join | 82 join = presubmit.os.path.join |
| 83 files = [ | 83 files = [ |
| 84 'blat.cc', | 84 'blat.cc', |
| 85 join('foo', 'haspresubmit', 'yodle', 'smart.h'), | 85 join('foo', 'haspresubmit', 'yodle', 'smart.h'), |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 self.mox.ReplayAll() | 609 self.mox.ReplayAll() |
| 610 members = [ | 610 members = [ |
| 611 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', | 611 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', |
| 612 'AffectedTextFiles', | 612 'AffectedTextFiles', |
| 613 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', | 613 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', |
| 614 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', | 614 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', |
| 615 'LocalToDepotPath', | 615 'LocalToDepotPath', |
| 616 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', | 616 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', |
| 617 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', | 617 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', |
| 618 'is_committing', 'json', 'marshal', 'os_path', 'pickle', 'platform', | 618 'is_committing', 'json', 'marshal', 'os_path', 'pickle', 'platform', |
| 619 'python_executable', | 619 'python_executable', 're', 'subprocess', 'tempfile', 'traceback', |
| 620 're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', | 620 'unittest', 'urllib2', 'version', |
| 621 'version', | |
| 622 ] | 621 ] |
| 623 # If this test fails, you should add the relevant test. | 622 # If this test fails, you should add the relevant test. |
| 624 self.compareMembers(presubmit.InputApi(None, './.', False), members) | 623 self.compareMembers(presubmit.InputApi(None, './.', False), members) |
| 625 | 624 |
| 626 def testDepotToLocalPath(self): | 625 def testDepotToLocalPath(self): |
| 627 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( | 626 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( |
| 628 {'Path': 'prout'}) | 627 {'Path': 'prout'}) |
| 629 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) | 628 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) |
| 630 self.mox.ReplayAll() | 629 self.mox.ReplayAll() |
| 631 | 630 |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 self.mox.ReplayAll() | 1499 self.mox.ReplayAll() |
| 1501 | 1500 |
| 1502 results = presubmit_canned_checks.CheckSvnForCommonMimeTypes( | 1501 results = presubmit_canned_checks.CheckSvnForCommonMimeTypes( |
| 1503 input_api, output_api) | 1502 input_api, output_api) |
| 1504 self.assertEquals(results, [1, 2, 3, 4, 5, 6]) | 1503 self.assertEquals(results, [1, 2, 3, 4, 5, 6]) |
| 1505 | 1504 |
| 1506 def testCannedCheckTreeIsOpenOpen(self): | 1505 def testCannedCheckTreeIsOpenOpen(self): |
| 1507 input_api = self.MockInputApi(None, True) | 1506 input_api = self.MockInputApi(None, True) |
| 1508 connection = self.mox.CreateMockAnything() | 1507 connection = self.mox.CreateMockAnything() |
| 1509 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 1508 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
| 1510 connection.read().AndReturn('1') | 1509 connection.read().AndReturn('The tree is open') |
| 1511 connection.close() | 1510 connection.close() |
| 1512 self.mox.ReplayAll() | 1511 self.mox.ReplayAll() |
| 1513 results = presubmit_canned_checks.CheckTreeIsOpen( | 1512 results = presubmit_canned_checks.CheckTreeIsOpen( |
| 1514 input_api, presubmit.OutputApi, url='url_to_open', closed='0') | 1513 input_api, presubmit.OutputApi, url='url_to_open', closed='.*closed.*') |
| 1515 self.assertEquals(results, []) | 1514 self.assertEquals(results, []) |
| 1516 | 1515 |
| 1517 def testCannedCheckTreeIsOpenClosed(self): | 1516 def testCannedCheckTreeIsOpenClosed(self): |
| 1518 input_api = self.MockInputApi(None, True) | 1517 input_api = self.MockInputApi(None, True) |
| 1519 connection = self.mox.CreateMockAnything() | 1518 connection = self.mox.CreateMockAnything() |
| 1520 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) | 1519 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) |
| 1521 connection.read().AndReturn('0') | 1520 connection.read().AndReturn('Tree is closed for maintenance') |
| 1522 connection.close() | 1521 connection.close() |
| 1523 self.mox.ReplayAll() | 1522 self.mox.ReplayAll() |
| 1524 results = presubmit_canned_checks.CheckTreeIsOpen( | 1523 results = presubmit_canned_checks.CheckTreeIsOpen( |
| 1525 input_api, presubmit.OutputApi, url='url_to_closed', closed='0') | 1524 input_api, presubmit.OutputApi, |
| 1525 url='url_to_closed', closed='.*closed.*') |
| 1526 self.assertEquals(len(results), 1) |
| 1527 self.assertEquals(results[0].__class__, |
| 1528 presubmit.OutputApi.PresubmitError) |
| 1529 |
| 1530 def testCannedCheckJsonTreeIsOpenOpen(self): |
| 1531 input_api = self.MockInputApi(None, True) |
| 1532 input_api.json = presubmit.json |
| 1533 connection = self.mox.CreateMockAnything() |
| 1534 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
| 1535 status = { |
| 1536 'can_commit_freely': True, |
| 1537 'general_state': 'open', |
| 1538 'message': 'The tree is open' |
| 1539 } |
| 1540 connection.read().AndReturn(input_api.json.dumps(status)) |
| 1541 connection.close() |
| 1542 self.mox.ReplayAll() |
| 1543 results = presubmit_canned_checks.CheckTreeIsOpen( |
| 1544 input_api, presubmit.OutputApi, json_url='url_to_open') |
| 1545 self.assertEquals(results, []) |
| 1546 |
| 1547 def testCannedCheckJsonTreeIsOpenClosed(self): |
| 1548 input_api = self.MockInputApi(None, True) |
| 1549 input_api.json = presubmit.json |
| 1550 connection = self.mox.CreateMockAnything() |
| 1551 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) |
| 1552 status = { |
| 1553 'can_commit_freely': False, |
| 1554 'general_state': 'closed', |
| 1555 'message': 'The tree is close', |
| 1556 } |
| 1557 connection.read().AndReturn(input_api.json.dumps(status)) |
| 1558 connection.close() |
| 1559 self.mox.ReplayAll() |
| 1560 results = presubmit_canned_checks.CheckTreeIsOpen( |
| 1561 input_api, presubmit.OutputApi, json_url='url_to_closed') |
| 1526 self.assertEquals(len(results), 1) | 1562 self.assertEquals(len(results), 1) |
| 1527 self.assertEquals(results[0].__class__, | 1563 self.assertEquals(results[0].__class__, |
| 1528 presubmit.OutputApi.PresubmitError) | 1564 presubmit.OutputApi.PresubmitError) |
| 1529 | 1565 |
| 1530 def testRunPythonUnitTestsNoTest(self): | 1566 def testRunPythonUnitTestsNoTest(self): |
| 1531 input_api = self.MockInputApi(None, False) | 1567 input_api = self.MockInputApi(None, False) |
| 1532 self.mox.ReplayAll() | 1568 self.mox.ReplayAll() |
| 1533 results = presubmit_canned_checks.RunPythonUnitTests( | 1569 results = presubmit_canned_checks.RunPythonUnitTests( |
| 1534 input_api, presubmit.OutputApi, []) | 1570 input_api, presubmit.OutputApi, []) |
| 1535 self.assertEquals(results, []) | 1571 self.assertEquals(results, []) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 1734 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
| 1699 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 1735 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
| 1700 self.assertEquals(len(results), 1) | 1736 self.assertEquals(len(results), 1) |
| 1701 self.assertEquals(results[0].__class__, | 1737 self.assertEquals(results[0].__class__, |
| 1702 presubmit.OutputApi.PresubmitNotifyResult) | 1738 presubmit.OutputApi.PresubmitNotifyResult) |
| 1703 | 1739 |
| 1704 | 1740 |
| 1705 if __name__ == '__main__': | 1741 if __name__ == '__main__': |
| 1706 import unittest | 1742 import unittest |
| 1707 unittest.main() | 1743 unittest.main() |
| OLD | NEW |