OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 is too confused. | 8 # pylint is too confused. |
9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 | 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 |
10 | 10 |
11 import StringIO | 11 import StringIO |
12 import sys | 12 import sys |
| 13 import time |
13 | 14 |
14 # Fixes include path. | 15 # Fixes include path. |
15 from super_mox import mox, SuperMoxTestBase | 16 from super_mox import mox, SuperMoxTestBase |
16 | 17 |
17 import owners | 18 import owners |
18 import presubmit_support as presubmit | 19 import presubmit_support as presubmit |
19 import rietveld | 20 import rietveld |
20 # Shortcut. | 21 # Shortcut. |
21 presubmit_canned_checks = presubmit.presubmit_canned_checks | 22 presubmit_canned_checks = presubmit.presubmit_canned_checks |
22 | 23 |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 def __str__(self): | 1355 def __str__(self): |
1355 return 'foo' | 1356 return 'foo' |
1356 input_api.subprocess.CalledProcessError = fake_CalledProcessError | 1357 input_api.subprocess.CalledProcessError = fake_CalledProcessError |
1357 | 1358 |
1358 input_api.change = change | 1359 input_api.change = change |
1359 input_api.host_url = 'http://localhost' | 1360 input_api.host_url = 'http://localhost' |
1360 input_api.is_committing = committing | 1361 input_api.is_committing = committing |
1361 input_api.tbr = False | 1362 input_api.tbr = False |
1362 input_api.python_executable = 'pyyyyython' | 1363 input_api.python_executable = 'pyyyyython' |
1363 input_api.platform = sys.platform | 1364 input_api.platform = sys.platform |
| 1365 input_api.time = time |
| 1366 input_api.canned_checks = presubmit_canned_checks |
1364 return input_api | 1367 return input_api |
1365 | 1368 |
1366 def testMembersChanged(self): | 1369 def testMembersChanged(self): |
1367 self.mox.ReplayAll() | 1370 self.mox.ReplayAll() |
1368 members = [ | 1371 members = [ |
1369 'CheckBuildbotPendingBuilds', | 1372 'CheckBuildbotPendingBuilds', |
1370 'CheckChangeHasBugField', 'CheckChangeHasDescription', | 1373 'CheckChangeHasBugField', 'CheckChangeHasDescription', |
1371 'CheckChangeHasNoStrayWhitespace', | 1374 'CheckChangeHasNoStrayWhitespace', |
1372 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', | 1375 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', |
1373 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', | 1376 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 results = presubmit_canned_checks.RunUnitTestsInDirectory( | 2153 results = presubmit_canned_checks.RunUnitTestsInDirectory( |
2151 input_api, | 2154 input_api, |
2152 presubmit.OutputApi, | 2155 presubmit.OutputApi, |
2153 'random_directory', | 2156 'random_directory', |
2154 whitelist=['^a$', '^b$'], | 2157 whitelist=['^a$', '^b$'], |
2155 blacklist=['a']) | 2158 blacklist=['a']) |
2156 self.assertEqual(results, []) | 2159 self.assertEqual(results, []) |
2157 self.checkstdout( | 2160 self.checkstdout( |
2158 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) | 2161 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) |
2159 | 2162 |
| 2163 def testPanProjectChecks(self): |
| 2164 # Make sure it accepts both list and tuples. |
| 2165 change = presubmit.Change( |
| 2166 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) |
| 2167 input_api = self.MockInputApi(change, False) |
| 2168 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 2169 for _ in range(3): |
| 2170 input_api.AffectedFiles(file_filter=mox.IgnoreArg(), include_deletes=False |
| 2171 ).AndReturn([affected_file]) |
| 2172 affected_file.NewContents().AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') |
| 2173 affected_file.ChangedContents().AndReturn([ |
| 2174 (0, 'Hey!\n'), |
| 2175 (1, 'Ho!\n'), |
| 2176 (2, 'Hey!\n'), |
| 2177 (3, 'Ho!\n'), |
| 2178 (4, '\n')]) |
| 2179 for _ in range(5): |
| 2180 affected_file.LocalPath().AndReturn('hello.py') |
| 2181 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) |
| 2182 input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') |
| 2183 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) |
| 2184 for _ in range(4): |
| 2185 affected_file.LocalPath().AndReturn('hello.py') |
| 2186 |
| 2187 self.mox.ReplayAll() |
| 2188 results = presubmit_canned_checks.PanProjectChecks( |
| 2189 input_api, |
| 2190 presubmit.OutputApi, |
| 2191 excluded_paths=None, |
| 2192 text_files=None, |
| 2193 license_header=None, |
| 2194 project_name=None, |
| 2195 owners_check=True) |
| 2196 self.assertEqual(1, len(results)) |
| 2197 self.assertEqual( |
| 2198 'Found line ending with white spaces in:', results[0]._message) |
| 2199 self.checkstdout('') |
| 2200 |
2160 | 2201 |
2161 if __name__ == '__main__': | 2202 if __name__ == '__main__': |
2162 import unittest | 2203 import unittest |
2163 unittest.main() | 2204 unittest.main() |
OLD | NEW |