| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 exceptions | 8 import exceptions |
| 9 import os |
| 9 import StringIO | 10 import StringIO |
| 10 import unittest | 11 import unittest |
| 11 | 12 |
| 12 # Local imports | 13 # Local imports |
| 13 import presubmit_support as presubmit | 14 import presubmit_support as presubmit |
| 14 import presubmit_canned_checks | 15 import presubmit_canned_checks |
| 15 import super_mox | 16 import super_mox |
| 16 from super_mox import mox | 17 from super_mox import mox |
| 17 | 18 |
| 18 | 19 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 # Always fail. | 393 # Always fail. |
| 393 change = presubmit.Change('mychange', '\n'.join(description_lines), | 394 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 394 self.fake_root_dir, files, 0, 0) | 395 self.fake_root_dir, files, 0, 0) |
| 395 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 396 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 396 DEFAULT_SCRIPT, False)) | 397 DEFAULT_SCRIPT, False)) |
| 397 self.assertEquals(output.getvalue().count('!!'), 1) | 398 self.assertEquals(output.getvalue().count('!!'), 1) |
| 398 | 399 |
| 399 def testDirectoryHandling(self): | 400 def testDirectoryHandling(self): |
| 400 files = [ | 401 files = [ |
| 401 ['A', 'isdir'], | 402 ['A', 'isdir'], |
| 402 ['A', 'isdir\\blat.cc'], | 403 ['A', os.path.join('isdir', 'blat.cc')], |
| 403 ] | 404 ] |
| 404 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') | 405 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') |
| 405 blat = presubmit.os.path.join(isdir, 'blat.cc') | 406 blat = presubmit.os.path.join(isdir, 'blat.cc') |
| 406 presubmit.os.path.exists(isdir).AndReturn(True) | 407 presubmit.os.path.exists(isdir).AndReturn(True) |
| 407 presubmit.os.path.isdir(isdir).AndReturn(True) | 408 presubmit.os.path.isdir(isdir).AndReturn(True) |
| 408 presubmit.os.path.exists(blat).AndReturn(True) | 409 presubmit.os.path.exists(blat).AndReturn(True) |
| 409 presubmit.os.path.isdir(blat).AndReturn(False) | 410 presubmit.os.path.isdir(blat).AndReturn(False) |
| 410 self.mox.ReplayAll() | 411 self.mox.ReplayAll() |
| 411 | 412 |
| 412 change = presubmit.Change('mychange', 'foo', self.fake_root_dir, files, | 413 change = presubmit.Change('mychange', 'foo', self.fake_root_dir, files, |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 test_result.errors = 0 | 1354 test_result.errors = 0 |
| 1354 self.mox.ReplayAll() | 1355 self.mox.ReplayAll() |
| 1355 | 1356 |
| 1356 results = presubmit_canned_checks.RunPythonUnitTests( | 1357 results = presubmit_canned_checks.RunPythonUnitTests( |
| 1357 input_api, presubmit.OutputApi, ['test_module']) | 1358 input_api, presubmit.OutputApi, ['test_module']) |
| 1358 self.assertEquals(len(results), 0) | 1359 self.assertEquals(len(results), 0) |
| 1359 | 1360 |
| 1360 | 1361 |
| 1361 if __name__ == '__main__': | 1362 if __name__ == '__main__': |
| 1362 unittest.main() | 1363 unittest.main() |
| OLD | NEW |