| 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 StringIO |
| 10 import functools | 11 import functools |
| 11 import itertools | 12 import itertools |
| 12 import logging | 13 import logging |
| 14 import multiprocessing |
| 13 import os | 15 import os |
| 14 import StringIO | |
| 15 import sys | 16 import sys |
| 16 import time | 17 import time |
| 17 import unittest | 18 import unittest |
| 18 | 19 |
| 19 _ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 20 _ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 20 sys.path.insert(0, _ROOT) | 21 sys.path.insert(0, _ROOT) |
| 21 | 22 |
| 22 from testing_support.super_mox import mox, SuperMoxTestBase | 23 from testing_support.super_mox import mox, SuperMoxTestBase |
| 23 | 24 |
| 24 import owners | 25 import owners |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 presubmit.os.getcwd = self.RootDir | 150 presubmit.os.getcwd = self.RootDir |
| 150 presubmit.os.chdir = MockChdir | 151 presubmit.os.chdir = MockChdir |
| 151 self.mox.StubOutWithMock(presubmit.scm, 'determine_scm') | 152 self.mox.StubOutWithMock(presubmit.scm, 'determine_scm') |
| 152 self.mox.StubOutWithMock(presubmit.scm.SVN, '_CaptureInfo') | 153 self.mox.StubOutWithMock(presubmit.scm.SVN, '_CaptureInfo') |
| 153 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty') | 154 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty') |
| 154 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead') | 155 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead') |
| 155 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite') | 156 self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite') |
| 156 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GenerateDiff') | 157 self.mox.StubOutWithMock(presubmit.scm.SVN, 'GenerateDiff') |
| 157 self.mox.StubOutWithMock(presubmit.scm.GIT, 'GenerateDiff') | 158 self.mox.StubOutWithMock(presubmit.scm.GIT, 'GenerateDiff') |
| 158 | 159 |
| 160 # On some platforms this does all sorts of undesirable system calls, so |
| 161 # just permanently mock it with a lambda that returns 2 |
| 162 multiprocessing.cpu_count = lambda: 2 |
| 163 |
| 159 | 164 |
| 160 class PresubmitUnittest(PresubmitTestsBase): | 165 class PresubmitUnittest(PresubmitTestsBase): |
| 161 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 166 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
| 162 | 167 |
| 163 _INHERIT_SETTINGS = 'inherit-review-settings-ok' | 168 _INHERIT_SETTINGS = 'inherit-review-settings-ok' |
| 164 | 169 |
| 165 def testMembersChanged(self): | 170 def testMembersChanged(self): |
| 166 self.mox.ReplayAll() | 171 self.mox.ReplayAll() |
| 167 members = [ | 172 members = [ |
| 168 'AffectedFile', 'Change', 'DoGetTrySlaves', | 173 'AffectedFile', 'Change', 'DoGetTrySlaves', |
| (...skipping 2725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 owners_check=False) | 2899 owners_check=False) |
| 2895 self.assertEqual(1, len(results)) | 2900 self.assertEqual(1, len(results)) |
| 2896 self.assertEqual( | 2901 self.assertEqual( |
| 2897 'Found line ending with white spaces in:', results[0]._message) | 2902 'Found line ending with white spaces in:', results[0]._message) |
| 2898 self.checkstdout('') | 2903 self.checkstdout('') |
| 2899 | 2904 |
| 2900 | 2905 |
| 2901 if __name__ == '__main__': | 2906 if __name__ == '__main__': |
| 2902 import unittest | 2907 import unittest |
| 2903 unittest.main() | 2908 unittest.main() |
| OLD | NEW |