| 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 presubmit.random.randint(0, 4).AndReturn(1) | 334 presubmit.random.randint(0, 4).AndReturn(1) |
| 335 self.mox.ReplayAll() | 335 self.mox.ReplayAll() |
| 336 | 336 |
| 337 output = StringIO.StringIO() | 337 output = StringIO.StringIO() |
| 338 input = StringIO.StringIO('y\n') | 338 input = StringIO.StringIO('y\n') |
| 339 change = presubmit.Change('mychange', '\n'.join(description_lines), | 339 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 340 self.fake_root_dir, files, 0, 0) | 340 self.fake_root_dir, files, 0, 0) |
| 341 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 341 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 342 None, False)) | 342 None, False)) |
| 343 self.assertEqual(output.getvalue().count('!!'), 2) | 343 self.assertEqual(output.getvalue().count('!!'), 2) |
| 344 self.checkstdout('Running presubmit hooks...\n') |
| 344 | 345 |
| 345 def testDoPresubmitChecksPromptsAfterWarnings(self): | 346 def testDoPresubmitChecksPromptsAfterWarnings(self): |
| 346 join = presubmit.os.path.join | 347 join = presubmit.os.path.join |
| 347 description_lines = ('Hello there', | 348 description_lines = ('Hello there', |
| 348 'this is a change', | 349 'this is a change', |
| 349 'NOSUCHKEY=http://tracker/123') | 350 'NOSUCHKEY=http://tracker/123') |
| 350 files = [ | 351 files = [ |
| 351 ['A', join('haspresubmit', 'blat.cc')], | 352 ['A', join('haspresubmit', 'blat.cc')], |
| 352 ] | 353 ] |
| 353 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') | 354 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') |
| (...skipping 18 matching lines...) Expand all Loading... |
| 372 self.fake_root_dir, files, 0, 0) | 373 self.fake_root_dir, files, 0, 0) |
| 373 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 374 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 374 None, True)) | 375 None, True)) |
| 375 self.assertEqual(output.getvalue().count('??'), 2) | 376 self.assertEqual(output.getvalue().count('??'), 2) |
| 376 | 377 |
| 377 output = StringIO.StringIO() | 378 output = StringIO.StringIO() |
| 378 input = StringIO.StringIO('y\n') # say yes to the warning | 379 input = StringIO.StringIO('y\n') # say yes to the warning |
| 379 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, | 380 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, |
| 380 input, None, True)) | 381 input, None, True)) |
| 381 self.assertEquals(output.getvalue().count('??'), 2) | 382 self.assertEquals(output.getvalue().count('??'), 2) |
| 383 self.checkstdout('Running presubmit hooks...\nRunning presubmit hooks...\n') |
| 382 | 384 |
| 383 def testDoPresubmitChecksNoWarningPromptIfErrors(self): | 385 def testDoPresubmitChecksNoWarningPromptIfErrors(self): |
| 384 join = presubmit.os.path.join | 386 join = presubmit.os.path.join |
| 385 description_lines = ('Hello there', | 387 description_lines = ('Hello there', |
| 386 'this is a change', | 388 'this is a change', |
| 387 'NOSUCHKEY=http://tracker/123', | 389 'NOSUCHKEY=http://tracker/123', |
| 388 'REALLYNOSUCHKEY=http://tracker/123') | 390 'REALLYNOSUCHKEY=http://tracker/123') |
| 389 files = [ | 391 files = [ |
| 390 ['A', join('haspresubmit', 'blat.cc')], | 392 ['A', join('haspresubmit', 'blat.cc')], |
| 391 ] | 393 ] |
| (...skipping 14 matching lines...) Expand all Loading... |
| 406 | 408 |
| 407 output = StringIO.StringIO() | 409 output = StringIO.StringIO() |
| 408 input = StringIO.StringIO() # should be unused | 410 input = StringIO.StringIO() # should be unused |
| 409 change = presubmit.Change('mychange', '\n'.join(description_lines), | 411 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 410 self.fake_root_dir, files, 0, 0) | 412 self.fake_root_dir, files, 0, 0) |
| 411 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 413 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 412 None, False)) | 414 None, False)) |
| 413 self.assertEqual(output.getvalue().count('??'), 2) | 415 self.assertEqual(output.getvalue().count('??'), 2) |
| 414 self.assertEqual(output.getvalue().count('XX!!XX'), 2) | 416 self.assertEqual(output.getvalue().count('XX!!XX'), 2) |
| 415 self.assertEqual(output.getvalue().count('(y/N)'), 0) | 417 self.assertEqual(output.getvalue().count('(y/N)'), 0) |
| 418 self.checkstdout('Running presubmit hooks...\n') |
| 416 | 419 |
| 417 def testDoDefaultPresubmitChecksAndFeedback(self): | 420 def testDoDefaultPresubmitChecksAndFeedback(self): |
| 418 join = presubmit.os.path.join | 421 join = presubmit.os.path.join |
| 419 description_lines = ('Hello there', | 422 description_lines = ('Hello there', |
| 420 'this is a change', | 423 'this is a change', |
| 421 'STORY=http://tracker/123') | 424 'STORY=http://tracker/123') |
| 422 files = [ | 425 files = [ |
| 423 ['A', join('haspresubmit', 'blat.cc')], | 426 ['A', join('haspresubmit', 'blat.cc')], |
| 424 ] | 427 ] |
| 425 DEFAULT_SCRIPT = """ | 428 DEFAULT_SCRIPT = """ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 445 change = presubmit.Change('mychange', '\n'.join(description_lines), | 448 change = presubmit.Change('mychange', '\n'.join(description_lines), |
| 446 self.fake_root_dir, files, 0, 0) | 449 self.fake_root_dir, files, 0, 0) |
| 447 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 450 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
| 448 DEFAULT_SCRIPT, False)) | 451 DEFAULT_SCRIPT, False)) |
| 449 text = ('Warning, no presubmit.py found.\n' | 452 text = ('Warning, no presubmit.py found.\n' |
| 450 'Running default presubmit script.\n' | 453 'Running default presubmit script.\n' |
| 451 '** Presubmit ERRORS **\n!!\n\n' | 454 '** Presubmit ERRORS **\n!!\n\n' |
| 452 'Was the presubmit check useful? Please send feedback & hate mail ' | 455 'Was the presubmit check useful? Please send feedback & hate mail ' |
| 453 'to maruel@chromium.org!\n') | 456 'to maruel@chromium.org!\n') |
| 454 self.assertEquals(output.getvalue(), text) | 457 self.assertEquals(output.getvalue(), text) |
| 458 self.checkstdout('Running presubmit hooks...\n') |
| 455 | 459 |
| 456 def testDirectoryHandling(self): | 460 def testDirectoryHandling(self): |
| 457 files = [ | 461 files = [ |
| 458 ['A', 'isdir'], | 462 ['A', 'isdir'], |
| 459 ['A', presubmit.os.path.join('isdir', 'blat.cc')], | 463 ['A', presubmit.os.path.join('isdir', 'blat.cc')], |
| 460 ] | 464 ] |
| 461 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') | 465 isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir') |
| 462 blat = presubmit.os.path.join(isdir, 'blat.cc') | 466 blat = presubmit.os.path.join(isdir, 'blat.cc') |
| 463 presubmit.os.path.exists(isdir).AndReturn(True) | 467 presubmit.os.path.exists(isdir).AndReturn(True) |
| 464 presubmit.os.path.isdir(isdir).AndReturn(True) | 468 presubmit.os.path.isdir(isdir).AndReturn(True) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 change = presubmit.Change( | 520 change = presubmit.Change( |
| 517 'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", | 521 'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", |
| 518 self.fake_root_dir, None, 0, 0) | 522 self.fake_root_dir, None, 0, 0) |
| 519 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, | 523 self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, |
| 520 input, DEFAULT_SCRIPT, False)) | 524 input, DEFAULT_SCRIPT, False)) |
| 521 self.assertEquals(output.getvalue(), | 525 self.assertEquals(output.getvalue(), |
| 522 ('Warning, no presubmit.py found.\n' | 526 ('Warning, no presubmit.py found.\n' |
| 523 'Running default presubmit script.\n' | 527 'Running default presubmit script.\n' |
| 524 '** Presubmit Messages **\n' | 528 '** Presubmit Messages **\n' |
| 525 'http://tracker.com/42\n\n')) | 529 'http://tracker.com/42\n\n')) |
| 530 self.checkstdout('Running presubmit hooks...\n') |
| 526 | 531 |
| 527 def testGetTrySlavesExecuter(self): | 532 def testGetTrySlavesExecuter(self): |
| 528 self.mox.ReplayAll() | 533 self.mox.ReplayAll() |
| 529 | 534 |
| 530 executer = presubmit.GetTrySlavesExecuter() | 535 executer = presubmit.GetTrySlavesExecuter() |
| 531 self.assertEqual([], executer.ExecPresubmitScript('')) | 536 self.assertEqual([], executer.ExecPresubmitScript('')) |
| 532 self.assertEqual([], executer.ExecPresubmitScript('def foo():\n return\n')) | 537 self.assertEqual([], executer.ExecPresubmitScript('def foo():\n return\n')) |
| 533 | 538 |
| 534 # bad results | 539 # bad results |
| 535 starts_with_space_result = [' starts_with_space'] | 540 starts_with_space_result = [' starts_with_space'] |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 1739 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
| 1735 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 1740 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
| 1736 self.assertEquals(len(results), 1) | 1741 self.assertEquals(len(results), 1) |
| 1737 self.assertEquals(results[0].__class__, | 1742 self.assertEquals(results[0].__class__, |
| 1738 presubmit.OutputApi.PresubmitNotifyResult) | 1743 presubmit.OutputApi.PresubmitNotifyResult) |
| 1739 | 1744 |
| 1740 | 1745 |
| 1741 if __name__ == '__main__': | 1746 if __name__ == '__main__': |
| 1742 import unittest | 1747 import unittest |
| 1743 unittest.main() | 1748 unittest.main() |
| OLD | NEW |