Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: tests/presubmit_unittest.py

Issue 6736018: improve logging slightly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fix baseline of patchset Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # pylint is too confused. 8 # pylint is too confused.
9 # pylint: disable=E1101,E1103,W0212,W0403 9 # pylint: disable=E1101,E1103,W0212,W0403
10 10
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 presubmit.random.randint(0, 4).AndReturn(1) 413 presubmit.random.randint(0, 4).AndReturn(1)
414 self.mox.ReplayAll() 414 self.mox.ReplayAll()
415 415
416 input_buf = StringIO.StringIO('y\n') 416 input_buf = StringIO.StringIO('y\n')
417 change = presubmit.Change('mychange', '\n'.join(description_lines), 417 change = presubmit.Change('mychange', '\n'.join(description_lines),
418 self.fake_root_dir, files, 0, 0) 418 self.fake_root_dir, files, 0, 0)
419 output = presubmit.DoPresubmitChecks( 419 output = presubmit.DoPresubmitChecks(
420 change, False, True, None, input_buf, None, False) 420 change, False, True, None, input_buf, None, False)
421 self.failIf(output.should_continue()) 421 self.failIf(output.should_continue())
422 self.assertEqual(output.getvalue().count('!!'), 2) 422 self.assertEqual(output.getvalue().count('!!'), 2)
423 self.assertEqual(output.getvalue().count('Running presubmit hooks...\n'), 1) 423 self.assertEqual(output.getvalue().count(
424 'Running presubmit upload checks ...\n'), 1)
424 425
425 def testDoPresubmitChecksPromptsAfterWarnings(self): 426 def testDoPresubmitChecksPromptsAfterWarnings(self):
426 join = presubmit.os.path.join 427 join = presubmit.os.path.join
427 description_lines = ('Hello there', 428 description_lines = ('Hello there',
428 'this is a change', 429 'this is a change',
429 'NOSUCHKEY=http://tracker/123') 430 'NOSUCHKEY=http://tracker/123')
430 files = [ 431 files = [
431 ['A', join('haspresubmit', 'blat.cc')], 432 ['A', join('haspresubmit', 'blat.cc')],
432 ] 433 ]
433 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') 434 presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py')
(...skipping 18 matching lines...) Expand all
452 output = presubmit.DoPresubmitChecks( 453 output = presubmit.DoPresubmitChecks(
453 change, False, True, None, input_buf, None, True) 454 change, False, True, None, input_buf, None, True)
454 self.failIf(output.should_continue()) 455 self.failIf(output.should_continue())
455 self.assertEqual(output.getvalue().count('??'), 2) 456 self.assertEqual(output.getvalue().count('??'), 2)
456 457
457 input_buf = StringIO.StringIO('y\n') # say yes to the warning 458 input_buf = StringIO.StringIO('y\n') # say yes to the warning
458 output = presubmit.DoPresubmitChecks( 459 output = presubmit.DoPresubmitChecks(
459 change, False, True, None, input_buf, None, True) 460 change, False, True, None, input_buf, None, True)
460 self.failUnless(output.should_continue()) 461 self.failUnless(output.should_continue())
461 self.assertEquals(output.getvalue().count('??'), 2) 462 self.assertEquals(output.getvalue().count('??'), 2)
462 self.assertEqual(output.getvalue().count('Running presubmit hooks...\n'), 1) 463 self.assertEqual(output.getvalue().count(
464 'Running presubmit upload checks ...\n'), 1)
463 465
464 def testDoPresubmitChecksNoWarningPromptIfErrors(self): 466 def testDoPresubmitChecksNoWarningPromptIfErrors(self):
465 join = presubmit.os.path.join 467 join = presubmit.os.path.join
466 description_lines = ('Hello there', 468 description_lines = ('Hello there',
467 'this is a change', 469 'this is a change',
468 'NOSUCHKEY=http://tracker/123', 470 'NOSUCHKEY=http://tracker/123',
469 'REALLYNOSUCHKEY=http://tracker/123') 471 'REALLYNOSUCHKEY=http://tracker/123')
470 files = [ 472 files = [
471 ['A', join('haspresubmit', 'blat.cc')], 473 ['A', join('haspresubmit', 'blat.cc')],
472 ] 474 ]
(...skipping 12 matching lines...) Expand all
485 presubmit.random.randint(0, 4).AndReturn(1) 487 presubmit.random.randint(0, 4).AndReturn(1)
486 self.mox.ReplayAll() 488 self.mox.ReplayAll()
487 489
488 change = presubmit.Change('mychange', '\n'.join(description_lines), 490 change = presubmit.Change('mychange', '\n'.join(description_lines),
489 self.fake_root_dir, files, 0, 0) 491 self.fake_root_dir, files, 0, 0)
490 output = presubmit.DoPresubmitChecks(change, False, True, None, None, 492 output = presubmit.DoPresubmitChecks(change, False, True, None, None,
491 None, False) 493 None, False)
492 self.assertEqual(output.getvalue().count('??'), 2) 494 self.assertEqual(output.getvalue().count('??'), 2)
493 self.assertEqual(output.getvalue().count('XX!!XX'), 2) 495 self.assertEqual(output.getvalue().count('XX!!XX'), 2)
494 self.assertEqual(output.getvalue().count('(y/N)'), 0) 496 self.assertEqual(output.getvalue().count('(y/N)'), 0)
495 self.assertEqual(output.getvalue().count('Running presubmit hooks...\n'), 1) 497 self.assertEqual(output.getvalue().count(
498 'Running presubmit upload checks ...\n'), 1)
496 499
497 def testDoDefaultPresubmitChecksAndFeedback(self): 500 def testDoDefaultPresubmitChecksAndFeedback(self):
498 join = presubmit.os.path.join 501 join = presubmit.os.path.join
499 description_lines = ('Hello there', 502 description_lines = ('Hello there',
500 'this is a change', 503 'this is a change',
501 'STORY=http://tracker/123') 504 'STORY=http://tracker/123')
502 files = [ 505 files = [
503 ['A', join('haspresubmit', 'blat.cc')], 506 ['A', join('haspresubmit', 'blat.cc')],
504 ] 507 ]
505 DEFAULT_SCRIPT = """ 508 DEFAULT_SCRIPT = """
(...skipping 13 matching lines...) Expand all
519 presubmit.random.randint(0, 4).AndReturn(0) 522 presubmit.random.randint(0, 4).AndReturn(0)
520 self.mox.ReplayAll() 523 self.mox.ReplayAll()
521 524
522 input_buf = StringIO.StringIO('y\n') 525 input_buf = StringIO.StringIO('y\n')
523 # Always fail. 526 # Always fail.
524 change = presubmit.Change('mychange', '\n'.join(description_lines), 527 change = presubmit.Change('mychange', '\n'.join(description_lines),
525 self.fake_root_dir, files, 0, 0) 528 self.fake_root_dir, files, 0, 0)
526 output = presubmit.DoPresubmitChecks( 529 output = presubmit.DoPresubmitChecks(
527 change, False, True, None, input_buf, DEFAULT_SCRIPT, False) 530 change, False, True, None, input_buf, DEFAULT_SCRIPT, False)
528 self.failIf(output.should_continue()) 531 self.failIf(output.should_continue())
529 text = ('Running presubmit hooks...\n' 532 text = ('Running presubmit upload checks ...\n'
530 'Warning, no presubmit.py found.\n' 533 'Warning, no presubmit.py found.\n'
531 'Running default presubmit script.\n' 534 'Running default presubmit script.\n'
535 '\n'
532 '** Presubmit ERRORS **\n!!\n\n' 536 '** Presubmit ERRORS **\n!!\n\n'
533 'Was the presubmit check useful? Please send feedback & hate mail ' 537 'Was the presubmit check useful? Please send feedback & hate mail '
534 'to maruel@chromium.org!\n') 538 'to maruel@chromium.org!\n')
535 self.assertEquals(output.getvalue(), text) 539 self.assertEquals(output.getvalue(), text)
536 540
537 def testDirectoryHandling(self): 541 def testDirectoryHandling(self):
538 files = [ 542 files = [
539 ['A', 'isdir'], 543 ['A', 'isdir'],
540 ['A', presubmit.os.path.join('isdir', 'blat.cc')], 544 ['A', presubmit.os.path.join('isdir', 'blat.cc')],
541 ] 545 ]
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 self.mox.ReplayAll() 597 self.mox.ReplayAll()
594 598
595 output = StringIO.StringIO() 599 output = StringIO.StringIO()
596 input_buf = StringIO.StringIO('y\n') 600 input_buf = StringIO.StringIO('y\n')
597 change = presubmit.Change( 601 change = presubmit.Change(
598 'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", 602 'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
599 self.fake_root_dir, None, 0, 0) 603 self.fake_root_dir, None, 0, 0)
600 self.failUnless(presubmit.DoPresubmitChecks( 604 self.failUnless(presubmit.DoPresubmitChecks(
601 change, False, True, output, input_buf, DEFAULT_SCRIPT, False)) 605 change, False, True, output, input_buf, DEFAULT_SCRIPT, False))
602 self.assertEquals(output.getvalue(), 606 self.assertEquals(output.getvalue(),
603 ('Running presubmit hooks...\n' 607 ('Running presubmit upload checks ...\n'
604 'Warning, no presubmit.py found.\n' 608 'Warning, no presubmit.py found.\n'
605 'Running default presubmit script.\n' 609 'Running default presubmit script.\n'
610 '\n'
606 '** Presubmit Messages **\n' 611 '** Presubmit Messages **\n'
607 'http://tracker.com/42\n\n')) 612 'http://tracker.com/42\n'
613 '\n'
614 'Presubmit checks passed.\n'))
608 615
609 def testGetTrySlavesExecuter(self): 616 def testGetTrySlavesExecuter(self):
610 self.mox.ReplayAll() 617 self.mox.ReplayAll()
611 618
612 executer = presubmit.GetTrySlavesExecuter() 619 executer = presubmit.GetTrySlavesExecuter()
613 self.assertEqual([], executer.ExecPresubmitScript('')) 620 self.assertEqual([], executer.ExecPresubmitScript(''))
614 self.assertEqual([], executer.ExecPresubmitScript('def foo():\n return\n')) 621 self.assertEqual([], executer.ExecPresubmitScript('def foo():\n return\n'))
615 622
616 # bad results 623 # bad results
617 starts_with_space_result = [' starts_with_space'] 624 starts_with_space_result = [' starts_with_space']
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 def testCannedCheckOwners_HTTPS_HostURL(self): 1971 def testCannedCheckOwners_HTTPS_HostURL(self):
1965 self.AssertOwnersWorks(approvers=set(['ben@example.com']), 1972 self.AssertOwnersWorks(approvers=set(['ben@example.com']),
1966 host_url='https://localhost') 1973 host_url='https://localhost')
1967 1974
1968 def testCannedCheckOwners_MissingSchemeInHostURL(self): 1975 def testCannedCheckOwners_MissingSchemeInHostURL(self):
1969 self.AssertOwnersWorks(approvers=set(['ben@example.com']), 1976 self.AssertOwnersWorks(approvers=set(['ben@example.com']),
1970 host_url='localhost') 1977 host_url='localhost')
1971 1978
1972 def testCannedCheckOwners_NoIssue(self): 1979 def testCannedCheckOwners_NoIssue(self):
1973 self.AssertOwnersWorks(issue=None, 1980 self.AssertOwnersWorks(issue=None,
1974 expected_output='Change not uploaded for review\n') 1981 expected_output="OWNERS check failed: this change has no Rietveld "
1982 "issue number, so we can't check it for approvals.\n")
1975 1983
1976 def testCannedCheckOwners_NoLGTM(self): 1984 def testCannedCheckOwners_NoLGTM(self):
1977 self.AssertOwnersWorks(expected_output='Missing LGTM from someone ' 1985 self.AssertOwnersWorks(expected_output='Missing LGTM from someone '
1978 'other than john@example.com\n') 1986 'other than john@example.com\n')
1979 1987
1980 def testCannedCheckOwners_OnlyOwnerLGTM(self): 1988 def testCannedCheckOwners_OnlyOwnerLGTM(self):
1981 self.AssertOwnersWorks(approvers=set(['john@example.com']), 1989 self.AssertOwnersWorks(approvers=set(['john@example.com']),
1982 expected_output='Missing LGTM from someone ' 1990 expected_output='Missing LGTM from someone '
1983 'other than john@example.com\n') 1991 'other than john@example.com\n')
1984 1992
(...skipping 15 matching lines...) Expand all
2000 2008
2001 def testCannedCheckOwners_WithLGTMs(self): 2009 def testCannedCheckOwners_WithLGTMs(self):
2002 self.AssertOwnersWorks(approvers=set(['ben@example.com']), 2010 self.AssertOwnersWorks(approvers=set(['ben@example.com']),
2003 uncovered_files=set()) 2011 uncovered_files=set())
2004 2012
2005 2013
2006 2014
2007 if __name__ == '__main__': 2015 if __name__ == '__main__':
2008 import unittest 2016 import unittest
2009 unittest.main() 2017 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698