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

Side by Side Diff: tests/presubmit_unittest.py

Issue 119252: Add InputApi.is_committing to be able to return a failure or notification, depending on the check. (Closed)
Patch Set: merged to trunk Created 11 years, 6 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
« 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) 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 random 9 import random
10 import string 10 import string
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 class PresubmitUnittest(PresubmitTestsBase): 98 class PresubmitUnittest(PresubmitTestsBase):
99 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" 99 """General presubmit_support.py tests (excluding InputApi and OutputApi)."""
100 def testMembersChanged(self): 100 def testMembersChanged(self):
101 self.mox.ReplayAll() 101 self.mox.ReplayAll()
102 members = [ 102 members = [
103 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', 103 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi',
104 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', 104 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException',
105 'OutputApi', 'ParseFiles', 'PresubmitExecuter', 105 'OutputApi', 'ParseFiles', 'PresubmitExecuter',
106 'ScanSubDirs', 'SvnAffectedFile', 106 'ScanSubDirs', 'SvnAffectedFile',
107 'cPickle', 'cStringIO', 'deprecated', 'exceptions', 107 'cPickle', 'cStringIO', 'exceptions',
108 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', 108 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse',
109 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', 109 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys',
110 'tempfile', 'types', 'unittest', 'urllib2', 'warnings', 110 'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings',
111 ] 111 ]
112 # If this test fails, you should add the relevant test. 112 # If this test fails, you should add the relevant test.
113 self.compareMembers(presubmit, members) 113 self.compareMembers(presubmit, members)
114 114
115 def testListRelevantPresubmitFiles(self): 115 def testListRelevantPresubmitFiles(self):
116 join = presubmit.os.path.join 116 join = presubmit.os.path.join
117 files = [ 117 files = [
118 'blat.cc', 118 'blat.cc',
119 join('foo', 'haspresubmit', 'yodle', 'smart.h'), 119 join('foo', 'haspresubmit', 'yodle', 'smart.h'),
120 join('moo', 'mat', 'gat', 'yo.h'), 120 join('moo', 'mat', 'gat', 'yo.h'),
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) 469 affected_files_and_dirs = change.AffectedFiles(include_dirs=True)
470 self.failUnless(len(affected_files_and_dirs) == 2) 470 self.failUnless(len(affected_files_and_dirs) == 2)
471 471
472 def testTags(self): 472 def testTags(self):
473 DEFAULT_SCRIPT = """ 473 DEFAULT_SCRIPT = """
474 def CheckChangeOnUpload(input_api, output_api): 474 def CheckChangeOnUpload(input_api, output_api):
475 if input_api.change.tags['BUG'] != 'boo': 475 if input_api.change.tags['BUG'] != 'boo':
476 return [output_api.PresubmitError('Tag parsing failed. 1')] 476 return [output_api.PresubmitError('Tag parsing failed. 1')]
477 if input_api.change.tags['STORY'] != 'http://tracker.com/42': 477 if input_api.change.tags['STORY'] != 'http://tracker.com/42':
478 return [output_api.PresubmitError('Tag parsing failed. 2')] 478 return [output_api.PresubmitError('Tag parsing failed. 2')]
479 if input_api.change.BUG != 'boo':
480 return [output_api.PresubmitError('Tag parsing failed. 6')]
481 if input_api.change.STORY != 'http://tracker.com/42':
482 return [output_api.PresubmitError('Tag parsing failed. 7')]
479 if 'TEST' in input_api.change.tags: 483 if 'TEST' in input_api.change.tags:
480 return [output_api.PresubmitError('Tag parsing failed. 3')] 484 return [output_api.PresubmitError('Tag parsing failed. 3')]
481 if input_api.change.DescriptionText() != 'Blah Blah': 485 if input_api.change.DescriptionText() != 'Blah Blah':
482 return [output_api.PresubmitError('Tag parsing failed. 4 ' + 486 return [output_api.PresubmitError('Tag parsing failed. 4 ' +
483 input_api.change.DescriptionText())] 487 input_api.change.DescriptionText())]
484 if (input_api.change.FullDescriptionText() != 488 if (input_api.change.FullDescriptionText() !=
485 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): 489 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'):
486 return [output_api.PresubmitError('Tag parsing failed. 5 ' + 490 return [output_api.PresubmitError('Tag parsing failed. 5 ' +
487 input_api.change.FullDescriptionText())] 491 input_api.change.FullDescriptionText())]
488 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] 492 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])]
(...skipping 21 matching lines...) Expand all
510 514
511 class InputApiUnittest(PresubmitTestsBase): 515 class InputApiUnittest(PresubmitTestsBase):
512 """Tests presubmit.InputApi.""" 516 """Tests presubmit.InputApi."""
513 def testMembersChanged(self): 517 def testMembersChanged(self):
514 self.mox.ReplayAll() 518 self.mox.ReplayAll()
515 members = [ 519 members = [
516 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 520 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
517 'DepotToLocalPath', 'LocalPaths', 'LocalToDepotPath', 521 'DepotToLocalPath', 'LocalPaths', 'LocalToDepotPath',
518 'PresubmitLocalPath', 'RightHandSideLines', 'ServerPaths', 522 'PresubmitLocalPath', 'RightHandSideLines', 'ServerPaths',
519 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 523 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change',
520 'marshal', 'os_path', 'pickle', 'platform', 524 'is_committing', 'marshal', 'os_path', 'pickle', 'platform',
521 're', 'subprocess', 'tempfile', 'unittest', 'urllib2', 'version', 525 're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2',
526 'version',
522 ] 527 ]
523 # If this test fails, you should add the relevant test. 528 # If this test fails, you should add the relevant test.
524 self.compareMembers(presubmit.InputApi(None, './.'), members) 529 self.compareMembers(presubmit.InputApi(None, './.', False), members)
525 530
526 def testDepotToLocalPath(self): 531 def testDepotToLocalPath(self):
527 presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn( 532 presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn(
528 {'Path': 'prout'}) 533 {'Path': 'prout'})
529 presubmit.gclient.CaptureSVNInfo('svn:/foo/notfound/burp').AndReturn({}) 534 presubmit.gclient.CaptureSVNInfo('svn:/foo/notfound/burp').AndReturn({})
530 self.mox.ReplayAll() 535 self.mox.ReplayAll()
531 536
532 path = presubmit.InputApi(None, './p').DepotToLocalPath('svn://foo/smurf') 537 path = presubmit.InputApi(None, './p', False).DepotToLocalPath(
538 'svn://foo/smurf')
533 self.failUnless(path == 'prout') 539 self.failUnless(path == 'prout')
534 path = presubmit.InputApi(None, './p').DepotToLocalPath( 540 path = presubmit.InputApi(None, './p', False).DepotToLocalPath(
535 'svn:/foo/notfound/burp') 541 'svn:/foo/notfound/burp')
536 self.failUnless(path == None) 542 self.failUnless(path == None)
537 543
538 def testLocalToDepotPath(self): 544 def testLocalToDepotPath(self):
539 presubmit.gclient.CaptureSVNInfo('smurf').AndReturn({'URL': 'svn://foo'}) 545 presubmit.gclient.CaptureSVNInfo('smurf').AndReturn({'URL': 'svn://foo'})
540 presubmit.gclient.CaptureSVNInfo('notfound-food').AndReturn({}) 546 presubmit.gclient.CaptureSVNInfo('notfound-food').AndReturn({})
541 self.mox.ReplayAll() 547 self.mox.ReplayAll()
542 548
543 path = presubmit.InputApi(None, './p').LocalToDepotPath('smurf') 549 path = presubmit.InputApi(None, './p', False).LocalToDepotPath('smurf')
544 self.assertEqual(path, 'svn://foo') 550 self.assertEqual(path, 'svn://foo')
545 path = presubmit.InputApi(None, './p').LocalToDepotPath('notfound-food') 551 path = presubmit.InputApi(None, './p', False).LocalToDepotPath(
552 'notfound-food')
546 self.failUnless(path == None) 553 self.failUnless(path == None)
547 554
548 def testInputApiConstruction(self): 555 def testInputApiConstruction(self):
549 self.mox.ReplayAll() 556 self.mox.ReplayAll()
550 # Fudge the change object, it's not used during construction anyway 557 # Fudge the change object, it's not used during construction anyway
551 api = presubmit.InputApi(change=42, presubmit_path='foo/path/PRESUBMIT.py') 558 api = presubmit.InputApi(change=42, presubmit_path='foo/path/PRESUBMIT.py',
559 is_committing=False)
552 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') 560 self.assertEquals(api.PresubmitLocalPath(), 'foo/path')
553 self.assertEquals(api.change, 42) 561 self.assertEquals(api.change, 42)
554 562
555 def testInputApiPresubmitScriptFiltering(self): 563 def testInputApiPresubmitScriptFiltering(self):
556 join = presubmit.os.path.join 564 join = presubmit.os.path.join
557 description_lines = ('Hello there', 565 description_lines = ('Hello there',
558 'this is a change', 566 'this is a change',
559 'BUG=123', 567 'BUG=123',
560 ' STORY =http://foo/ \t', 568 ' STORY =http://foo/ \t',
561 'and some more regular text') 569 'and some more regular text')
(...skipping 24 matching lines...) Expand all
586 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) 594 presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None)
587 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( 595 presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn(
588 'application/octet-stream') 596 'application/octet-stream')
589 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') 597 presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie')
590 self.mox.ReplayAll() 598 self.mox.ReplayAll()
591 599
592 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, 600 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0,
593 description='\n'.join(description_lines), 601 description='\n'.join(description_lines),
594 files=files) 602 files=files)
595 change = presubmit.GclChange(ci) 603 change = presubmit.GclChange(ci)
596 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') 604 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py', False)
597 affected_files = api.AffectedFiles() 605 affected_files = api.AffectedFiles()
598 self.assertEquals(len(affected_files), 3) 606 self.assertEquals(len(affected_files), 3)
599 self.assertEquals(affected_files[0].LocalPath(), 607 self.assertEquals(affected_files[0].LocalPath(),
600 presubmit.normpath('foo/blat.cc')) 608 presubmit.normpath('foo/blat.cc'))
601 self.assertEquals(affected_files[1].LocalPath(), 609 self.assertEquals(affected_files[1].LocalPath(),
602 presubmit.normpath('foo/blat/binary.dll')) 610 presubmit.normpath('foo/blat/binary.dll'))
603 self.assertEquals(affected_files[2].LocalPath(), 611 self.assertEquals(affected_files[2].LocalPath(),
604 presubmit.normpath('foo/mat/beingdeleted.txt')) 612 presubmit.normpath('foo/mat/beingdeleted.txt'))
605 rhs_lines = [] 613 rhs_lines = []
606 for line in api.RightHandSideLines(): 614 for line in api.RightHandSideLines():
(...skipping 29 matching lines...) Expand all
636 # Absolute paths should be prefixed 644 # Absolute paths should be prefixed
637 self.assertEquals(affected_files[0].AbsoluteLocalPath(), 645 self.assertEquals(affected_files[0].AbsoluteLocalPath(),
638 normpath(join(self.fake_root_dir, 'isdir'))) 646 normpath(join(self.fake_root_dir, 'isdir')))
639 self.assertEquals(affected_files[1].AbsoluteLocalPath(), 647 self.assertEquals(affected_files[1].AbsoluteLocalPath(),
640 normpath(join(self.fake_root_dir, 'isdir/blat.cc'))) 648 normpath(join(self.fake_root_dir, 'isdir/blat.cc')))
641 649
642 # New helper functions need to work 650 # New helper functions need to work
643 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True) 651 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True)
644 self.assertEqual(len(paths_from_change), 3) 652 self.assertEqual(len(paths_from_change), 3)
645 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py') 653 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py')
646 api = presubmit.InputApi(change=change, presubmit_path=presubmit_path) 654 api = presubmit.InputApi(change=change,
655 presubmit_path=presubmit_path,
656 is_committing=True)
647 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) 657 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True)
648 self.assertEqual(len(paths_from_api), 2) 658 self.assertEqual(len(paths_from_api), 2)
649 for absolute_paths in [paths_from_change, paths_from_api]: 659 for absolute_paths in [paths_from_change, paths_from_api]:
650 self.assertEqual(absolute_paths[0], 660 self.assertEqual(absolute_paths[0],
651 normpath(join(self.fake_root_dir, 'isdir'))) 661 normpath(join(self.fake_root_dir, 'isdir')))
652 self.assertEqual(absolute_paths[1], 662 self.assertEqual(absolute_paths[1],
653 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) 663 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc')))
654 664
655 def testDeprecated(self): 665 def testDeprecated(self):
656 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), 666 presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(),
657 stacklevel=2) 667 stacklevel=2)
658 self.mox.ReplayAll() 668 self.mox.ReplayAll()
659 change = presubmit.GclChange( 669 change = presubmit.GclChange(
660 presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, 670 presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0,
661 description='Bleh\n', files=None)) 671 description='Bleh\n', files=None))
662 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py') 672 api = presubmit.InputApi(change, 'foo/PRESUBMIT.py', True)
663 api.AffectedTextFiles(include_deletes=False) 673 api.AffectedTextFiles(include_deletes=False)
664 674
665 675
666 class OuputApiUnittest(PresubmitTestsBase): 676 class OuputApiUnittest(PresubmitTestsBase):
667 """Tests presubmit.OutputApi.""" 677 """Tests presubmit.OutputApi."""
668 def testMembersChanged(self): 678 def testMembersChanged(self):
669 self.mox.ReplayAll() 679 self.mox.ReplayAll()
670 members = [ 680 members = [
671 'MailTextResult', 'PresubmitError', 'PresubmitNotifyResult', 681 'MailTextResult', 'PresubmitError', 'PresubmitNotifyResult',
672 'PresubmitPromptWarning', 'PresubmitResult', 682 'PresubmitPromptWarning', 'PresubmitResult',
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 """Tests presubmit_canned_checks.py.""" 824 """Tests presubmit_canned_checks.py."""
815 825
816 def setUp(self): 826 def setUp(self):
817 PresubmitTestsBase.setUp(self) 827 PresubmitTestsBase.setUp(self)
818 self.mox.StubOutWithMock(presubmit_canned_checks, 828 self.mox.StubOutWithMock(presubmit_canned_checks,
819 '_RunPythonUnitTests_LoadTests') 829 '_RunPythonUnitTests_LoadTests')
820 830
821 def MockInputApi(self): 831 def MockInputApi(self):
822 input_api = self.mox.CreateMock(presubmit.InputApi) 832 input_api = self.mox.CreateMock(presubmit.InputApi)
823 input_api.re = presubmit.re 833 input_api.re = presubmit.re
834 input_api.traceback = presubmit.traceback
824 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) 835 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2)
825 input_api.unittest = unittest 836 input_api.unittest = unittest
826 return input_api 837 return input_api
827 838
828 def MakeBasicChange(self, name, description): 839 def MakeBasicChange(self, name, description):
829 ci = presubmit.gcl.ChangeInfo(name, 0, 0, description, None) 840 ci = presubmit.gcl.ChangeInfo(name, 0, 0, description, None)
830 return presubmit.GclChange(ci, self.fake_root_dir) 841 return presubmit.GclChange(ci, self.fake_root_dir)
831 842
832 def testMembersChanged(self): 843 def testMembersChanged(self):
833 self.mox.ReplayAll() 844 self.mox.ReplayAll()
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) 949 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection)
939 connection.read().AndReturn('0') 950 connection.read().AndReturn('0')
940 connection.close() 951 connection.close()
941 self.mox.ReplayAll() 952 self.mox.ReplayAll()
942 results = presubmit_canned_checks.CheckTreeIsOpen( 953 results = presubmit_canned_checks.CheckTreeIsOpen(
943 input_api, presubmit.OutputApi, url='url_to_closed', closed='0') 954 input_api, presubmit.OutputApi, url='url_to_closed', closed='0')
944 self.assertEquals(len(results), 1) 955 self.assertEquals(len(results), 1)
945 self.assertEquals(results[0].__class__, 956 self.assertEquals(results[0].__class__,
946 presubmit.OutputApi.PresubmitError) 957 presubmit.OutputApi.PresubmitError)
947 958
948 def testRunPythonUnitTests1(self): 959 def testRunPythonUnitTestsNoTest(self):
949 input_api = self.MockInputApi() 960 input_api = self.MockInputApi()
961 input_api.is_committing = False
950 self.mox.ReplayAll() 962 self.mox.ReplayAll()
951 results = presubmit_canned_checks.RunPythonUnitTests( 963 results = presubmit_canned_checks.RunPythonUnitTests(
952 input_api, presubmit.OutputApi, []) 964 input_api, presubmit.OutputApi, [])
953 self.assertEquals(results, []) 965 self.assertEquals(results, [])
954 966
955 def testRunPythonUnitTests2(self): 967 def testRunPythonUnitTestsNonExistent1(self):
956 input_api = self.MockInputApi() 968 input_api = self.MockInputApi()
969 input_api.is_committing = False
957 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module' 970 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module'
958 ).AndRaise(exceptions.ImportError('Blehh')) 971 ).AndRaise(exceptions.ImportError('Blehh'))
959 self.mox.ReplayAll() 972 self.mox.ReplayAll()
973 results = presubmit_canned_checks.RunPythonUnitTests(
974 input_api, presubmit.OutputApi, ['_non_existent_module'])
975 self.assertEquals(len(results), 1)
976 self.assertEquals(results[0].__class__,
977 presubmit.OutputApi.PresubmitNotifyResult)
978
979 def testRunPythonUnitTestsNonExistent2(self):
980 input_api = self.MockInputApi()
981 input_api.is_committing = True
982 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module'
983 ).AndRaise(exceptions.ImportError('Blehh'))
984 self.mox.ReplayAll()
960 results = presubmit_canned_checks.RunPythonUnitTests( 985 results = presubmit_canned_checks.RunPythonUnitTests(
961 input_api, presubmit.OutputApi, ['_non_existent_module']) 986 input_api, presubmit.OutputApi, ['_non_existent_module'])
962 self.assertEquals(len(results), 1) 987 self.assertEquals(len(results), 1)
963 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 988 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
964 989
965 def testRunPythonUnitTests3(self): 990 def testRunPythonUnitTestsEmpty1(self):
966 input_api = self.MockInputApi() 991 input_api = self.MockInputApi()
992 input_api.is_committing = False
967 test_module = self.mox.CreateMockAnything() 993 test_module = self.mox.CreateMockAnything()
968 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 994 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module'
969 ).AndReturn([]) 995 ).AndReturn([])
996 self.mox.ReplayAll()
997
998 results = presubmit_canned_checks.RunPythonUnitTests(
999 input_api, presubmit.OutputApi, ['test_module'])
1000 self.assertEquals(results, [])
1001
1002 def testRunPythonUnitTestsEmpty2(self):
1003 input_api = self.MockInputApi()
1004 input_api.is_committing = True
1005 test_module = self.mox.CreateMockAnything()
1006 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module'
1007 ).AndReturn([])
970 self.mox.ReplayAll() 1008 self.mox.ReplayAll()
971 1009
972 results = presubmit_canned_checks.RunPythonUnitTests( 1010 results = presubmit_canned_checks.RunPythonUnitTests(
973 input_api, presubmit.OutputApi, ['test_module']) 1011 input_api, presubmit.OutputApi, ['test_module'])
974 self.assertEquals(results, []) 1012 self.assertEquals(results, [])
975 1013
976 def testRunPythonUnitTests4(self): 1014 def testRunPythonUnitTestsFailure1(self):
977 input_api = self.MockInputApi() 1015 input_api = self.MockInputApi()
1016 input_api.is_committing = False
978 input_api.unittest = self.mox.CreateMock(unittest) 1017 input_api.unittest = self.mox.CreateMock(unittest)
979 test = self.mox.CreateMockAnything() 1018 test = self.mox.CreateMockAnything()
980 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1019 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module'
1020 ).AndReturn([test])
1021 runner = self.mox.CreateMockAnything()
1022 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
1023 suite = self.mox.CreateMockAnything()
1024 input_api.unittest.TestSuite([test]).AndReturn(suite)
1025 test_result = self.mox.CreateMockAnything()
1026 runner.run(suite).AndReturn(test_result)
1027 test_result.wasSuccessful().AndReturn(False)
1028 test_result.failures = 2
1029 test_result.errors = 3
1030 self.mox.ReplayAll()
1031
1032 results = presubmit_canned_checks.RunPythonUnitTests(
1033 input_api, presubmit.OutputApi, ['test_module'])
1034 self.assertEquals(len(results), 1)
1035 self.assertEquals(results[0].__class__,
1036 presubmit.OutputApi.PresubmitNotifyResult)
1037
1038 def testRunPythonUnitTestsFailure2(self):
1039 input_api = self.MockInputApi()
1040 input_api.is_committing = True
1041 input_api.unittest = self.mox.CreateMock(unittest)
1042 test = self.mox.CreateMockAnything()
1043 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module'
981 ).AndReturn([test]) 1044 ).AndReturn([test])
982 runner = self.mox.CreateMockAnything() 1045 runner = self.mox.CreateMockAnything()
983 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1046 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
984 suite = self.mox.CreateMockAnything() 1047 suite = self.mox.CreateMockAnything()
985 input_api.unittest.TestSuite([test]).AndReturn(suite) 1048 input_api.unittest.TestSuite([test]).AndReturn(suite)
986 test_result = self.mox.CreateMockAnything() 1049 test_result = self.mox.CreateMockAnything()
987 runner.run(suite).AndReturn(test_result) 1050 runner.run(suite).AndReturn(test_result)
988 test_result.wasSuccessful().AndReturn(False) 1051 test_result.wasSuccessful().AndReturn(False)
989 test_result.failures = 2 1052 test_result.failures = 2
990 test_result.errors = 3 1053 test_result.errors = 3
991 self.mox.ReplayAll() 1054 self.mox.ReplayAll()
992 1055
993 results = presubmit_canned_checks.RunPythonUnitTests( 1056 results = presubmit_canned_checks.RunPythonUnitTests(
994 input_api, presubmit.OutputApi, ['test_module']) 1057 input_api, presubmit.OutputApi, ['test_module'])
995 self.assertEquals(len(results), 1) 1058 self.assertEquals(len(results), 1)
996 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 1059 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
997 1060
998 def testRunPythonUnitTests5(self): 1061 def testRunPythonUnitTestsSuccess(self):
999 input_api = self.MockInputApi() 1062 input_api = self.MockInputApi()
1063 input_api.is_committing = False
1000 input_api.unittest = self.mox.CreateMock(unittest) 1064 input_api.unittest = self.mox.CreateMock(unittest)
1001 test = self.mox.CreateMockAnything() 1065 test = self.mox.CreateMockAnything()
1002 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1066 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module'
1003 ).AndReturn([test]) 1067 ).AndReturn([test])
1004 runner = self.mox.CreateMockAnything() 1068 runner = self.mox.CreateMockAnything()
1005 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1069 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
1006 suite = self.mox.CreateMockAnything() 1070 suite = self.mox.CreateMockAnything()
1007 input_api.unittest.TestSuite([test]).AndReturn(suite) 1071 input_api.unittest.TestSuite([test]).AndReturn(suite)
1008 test_result = self.mox.CreateMockAnything() 1072 test_result = self.mox.CreateMockAnything()
1009 runner.run(suite).AndReturn(test_result) 1073 runner.run(suite).AndReturn(test_result)
1010 test_result.wasSuccessful().AndReturn(True) 1074 test_result.wasSuccessful().AndReturn(True)
1011 test_result.failures = 0 1075 test_result.failures = 0
1012 test_result.errors = 0 1076 test_result.errors = 0
1013 self.mox.ReplayAll() 1077 self.mox.ReplayAll()
1014 1078
1015 results = presubmit_canned_checks.RunPythonUnitTests( 1079 results = presubmit_canned_checks.RunPythonUnitTests(
1016 input_api, presubmit.OutputApi, ['test_module']) 1080 input_api, presubmit.OutputApi, ['test_module'])
1017 self.assertEquals(len(results), 0) 1081 self.assertEquals(len(results), 0)
1018 1082
1019 1083
1020 if __name__ == '__main__': 1084 if __name__ == '__main__':
1021 unittest.main() 1085 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