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 random | 9 import random |
10 import string | 10 import string |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 self.mox.StubOutWithMock(presubmit.gcl, 'GetRepositoryRoot') | 79 self.mox.StubOutWithMock(presubmit.gcl, 'GetRepositoryRoot') |
80 fake_root_dir = RootDir() | 80 fake_root_dir = RootDir() |
81 self.fake_root_dir = fake_root_dir | 81 self.fake_root_dir = fake_root_dir |
82 def MockGetRepositoryRoot(): | 82 def MockGetRepositoryRoot(): |
83 return fake_root_dir | 83 return fake_root_dir |
84 presubmit.gcl.GetRepositoryRoot = MockGetRepositoryRoot | 84 presubmit.gcl.GetRepositoryRoot = MockGetRepositoryRoot |
85 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') | 85 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') |
86 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') | 86 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') |
87 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') | 87 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') |
88 | 88 |
89 @staticmethod | |
90 def MakeBasicChange(name, description): | |
91 ci = presubmit.gcl.ChangeInfo(name=name, description=description) | |
92 change = presubmit.GclChange(ci) | |
93 return change | |
94 | |
95 def compareMembers(self, object, members): | 89 def compareMembers(self, object, members): |
96 """If you add a member, be sure to add the relevant test!""" | 90 """If you add a member, be sure to add the relevant test!""" |
97 # Skip over members starting with '_' since they are usually not meant to | 91 # Skip over members starting with '_' since they are usually not meant to |
98 # be for public use. | 92 # be for public use. |
99 actual_members = [x for x in sorted(dir(object)) | 93 actual_members = [x for x in sorted(dir(object)) |
100 if not x.startswith('_')] | 94 if not x.startswith('_')] |
101 self.assertEqual(actual_members, sorted(members)) | 95 self.assertEqual(actual_members, sorted(members)) |
102 | 96 |
103 | 97 |
104 class PresubmitUnittest(PresubmitTestsBase): | 98 class PresubmitUnittest(PresubmitTestsBase): |
105 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 99 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
106 def testMembersChanged(self): | 100 def testMembersChanged(self): |
107 self.mox.ReplayAll() | 101 self.mox.ReplayAll() |
108 members = [ | 102 members = [ |
109 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', | 103 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', |
110 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', | 104 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', |
111 'OutputApi', 'ParseFiles', 'PresubmitExecuter', | 105 'OutputApi', 'ParseFiles', 'PresubmitExecuter', |
112 'ScanSubDirs', 'SvnAffectedFile', | 106 'ScanSubDirs', 'SvnAffectedFile', |
113 'cPickle', 'cStringIO', 'deprecated', 'exceptions', | 107 'cPickle', 'cStringIO', 'deprecated', 'exceptions', |
114 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', | 108 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', |
115 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', | 109 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', |
116 'tempfile', 'types', 'urllib2', 'warnings', | 110 'tempfile', 'types', 'unittest', 'urllib2', 'warnings', |
117 ] | 111 ] |
118 # If this test fails, you should add the relevant test. | 112 # If this test fails, you should add the relevant test. |
119 self.compareMembers(presubmit, members) | 113 self.compareMembers(presubmit, members) |
120 | 114 |
121 def testListRelevantPresubmitFiles(self): | 115 def testListRelevantPresubmitFiles(self): |
122 join = presubmit.os.path.join | 116 join = presubmit.os.path.join |
123 files = [ | 117 files = [ |
124 'blat.cc', | 118 'blat.cc', |
125 join('foo', 'haspresubmit', 'yodle', 'smart.h'), | 119 join('foo', 'haspresubmit', 'yodle', 'smart.h'), |
126 join('moo', 'mat', 'gat', 'yo.h'), | 120 join('moo', 'mat', 'gat', 'yo.h'), |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 class InputApiUnittest(PresubmitTestsBase): | 509 class InputApiUnittest(PresubmitTestsBase): |
516 """Tests presubmit.InputApi.""" | 510 """Tests presubmit.InputApi.""" |
517 def testMembersChanged(self): | 511 def testMembersChanged(self): |
518 self.mox.ReplayAll() | 512 self.mox.ReplayAll() |
519 members = [ | 513 members = [ |
520 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 514 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', |
521 'DepotToLocalPath', 'LocalPaths', 'LocalToDepotPath', | 515 'DepotToLocalPath', 'LocalPaths', 'LocalToDepotPath', |
522 'PresubmitLocalPath', 'RightHandSideLines', 'ServerPaths', | 516 'PresubmitLocalPath', 'RightHandSideLines', 'ServerPaths', |
523 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', | 517 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', |
524 'marshal', 'os_path', 'pickle', 'platform', | 518 'marshal', 'os_path', 'pickle', 'platform', |
525 're', 'subprocess', 'tempfile', 'urllib2', 'version', | 519 're', 'subprocess', 'tempfile', 'unittest', 'urllib2', 'version', |
526 ] | 520 ] |
527 # If this test fails, you should add the relevant test. | 521 # If this test fails, you should add the relevant test. |
528 self.compareMembers(presubmit.InputApi(None, './.'), members) | 522 self.compareMembers(presubmit.InputApi(None, './.'), members) |
529 | 523 |
530 def testDepotToLocalPath(self): | 524 def testDepotToLocalPath(self): |
531 presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn( | 525 presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn( |
532 {'Path': 'prout'}) | 526 {'Path': 'prout'}) |
533 presubmit.gclient.CaptureSVNInfo('svn:/foo/notfound/burp').AndReturn({}) | 527 presubmit.gclient.CaptureSVNInfo('svn:/foo/notfound/burp').AndReturn({}) |
534 self.mox.ReplayAll() | 528 self.mox.ReplayAll() |
535 | 529 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 ).AndReturn('application/octet-stream') | 787 ).AndReturn('application/octet-stream') |
794 self.mox.ReplayAll() | 788 self.mox.ReplayAll() |
795 | 789 |
796 output = filter(lambda x: x.IsTextFile(), list) | 790 output = filter(lambda x: x.IsTextFile(), list) |
797 self.failUnless(len(output) == 1) | 791 self.failUnless(len(output) == 1) |
798 self.failUnless(list[0] == output[0]) | 792 self.failUnless(list[0] == output[0]) |
799 | 793 |
800 | 794 |
801 class CannedChecksUnittest(PresubmitTestsBase): | 795 class CannedChecksUnittest(PresubmitTestsBase): |
802 """Tests presubmit_canned_checks.py.""" | 796 """Tests presubmit_canned_checks.py.""" |
803 class MockInputApi(object): | |
804 class MockUrllib2(object): | |
805 class urlopen(object): | |
806 def __init__(self, url): | |
807 if url == 'url_to_open': | |
808 self.result = '1' | |
809 else: | |
810 self.result = '0' | |
811 def read(self): | |
812 return self.result | |
813 def close(self): | |
814 pass | |
815 def __init__(self, lines=None): | |
816 self.lines = lines | |
817 self.basename = lambda x: x | |
818 self.urllib2 = self.MockUrllib2() | |
819 self.re = presubmit.re | |
820 | 797 |
821 def RightHandSideLines(self): | 798 def setUp(self): |
822 for line in self.lines: | 799 PresubmitTestsBase.setUp(self) |
823 yield (presubmit.AffectedFile('bingo', 'M'), 1, line) | 800 self.mox.StubOutWithMock(presubmit_canned_checks, |
| 801 '_RunPythonUnitTests_LoadTests') |
| 802 |
| 803 def MockInputApi(self): |
| 804 input_api = self.mox.CreateMock(presubmit.InputApi) |
| 805 input_api.re = presubmit.re |
| 806 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) |
| 807 input_api.unittest = unittest |
| 808 return input_api |
| 809 |
| 810 def MakeBasicChange(self, name, description): |
| 811 ci = presubmit.gcl.ChangeInfo(name=name, description=description) |
| 812 return presubmit.GclChange(ci, self.fake_root_dir) |
824 | 813 |
825 def testMembersChanged(self): | 814 def testMembersChanged(self): |
826 self.mox.ReplayAll() | 815 self.mox.ReplayAll() |
827 members = [ | 816 members = [ |
828 'CheckChangeHasBugField', 'CheckChangeHasNoTabs', | 817 'CheckChangeHasBugField', 'CheckChangeHasNoTabs', |
829 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 818 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
830 'CheckChangeHasTestField', 'CheckDoNotSubmit', | 819 'CheckChangeHasTestField', 'CheckDoNotSubmit', |
831 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 820 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
832 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 821 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
833 ] | 822 ] |
834 # If this test fails, you should add the relevant test. | 823 # If this test fails, you should add the relevant test. |
835 self.compareMembers(presubmit_canned_checks, members) | 824 self.compareMembers(presubmit_canned_checks, members) |
836 | 825 |
| 826 def TestDescription(self, check, description1, description2, error_type): |
| 827 input_api1 = self.MockInputApi() |
| 828 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) |
| 829 input_api2 = self.MockInputApi() |
| 830 input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2) |
| 831 self.mox.ReplayAll() |
| 832 |
| 833 results1 = check(input_api1, presubmit.OutputApi) |
| 834 self.assertEquals(results1, []) |
| 835 results2 = check(input_api2, presubmit.OutputApi) |
| 836 self.assertEquals(len(results2), 1) |
| 837 self.assertEquals(results2[0].__class__, error_type) |
| 838 |
| 839 def TestContent(self, check, content1, content2, error_type): |
| 840 input_api1 = self.MockInputApi() |
| 841 input_api1.change = self.MakeBasicChange('foo', 'Foo\n') |
| 842 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 843 affected_file.LocalPath().AndReturn('foo.cc') |
| 844 output1 = [ |
| 845 (affected_file, 42, 'yo, ' + content1), |
| 846 (affected_file, 43, 'yer'), |
| 847 (affected_file, 23, 'ya'), |
| 848 ] |
| 849 input_api1.RightHandSideLines().AndReturn(output1) |
| 850 input_api2 = self.MockInputApi() |
| 851 input_api2.change = self.MakeBasicChange('foo', 'Foo\n') |
| 852 output2 = [ |
| 853 (affected_file, 42, 'yo, ' + content2), |
| 854 (affected_file, 43, 'yer'), |
| 855 (affected_file, 23, 'ya'), |
| 856 ] |
| 857 input_api2.RightHandSideLines().AndReturn(output2) |
| 858 self.mox.ReplayAll() |
| 859 |
| 860 results1 = check(input_api1, presubmit.OutputApi) |
| 861 self.assertEquals(results1, []) |
| 862 results2 = check(input_api2, presubmit.OutputApi) |
| 863 self.assertEquals(len(results2), 1) |
| 864 self.assertEquals(results2[0].__class__, error_type) |
| 865 |
837 def testCannedCheckChangeHasBugField(self): | 866 def testCannedCheckChangeHasBugField(self): |
838 self.mox.ReplayAll() | 867 self.TestDescription(presubmit_canned_checks.CheckChangeHasBugField, |
839 change = self.MakeBasicChange('foo', | 868 'BUG=1234', '', |
840 'Foo\nBUG=1234') | 869 presubmit.OutputApi.PresubmitNotifyResult) |
841 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
842 self.failIf(presubmit_canned_checks.CheckChangeHasBugField( | |
843 api, presubmit.OutputApi)) | |
844 | |
845 change = self.MakeBasicChange('foo', | |
846 'Foo\nNEVERTESTED=did some stuff') | |
847 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
848 self.failUnless(presubmit_canned_checks.CheckChangeHasBugField( | |
849 api, presubmit.OutputApi)) | |
850 | 870 |
851 def testCannedCheckChangeHasTestField(self): | 871 def testCannedCheckChangeHasTestField(self): |
852 self.mox.ReplayAll() | 872 self.TestDescription(presubmit_canned_checks.CheckChangeHasTestField, |
853 change = self.MakeBasicChange('foo', | 873 'TEST=did some stuff', '', |
854 'Foo\nTEST=did some stuff') | 874 presubmit.OutputApi.PresubmitNotifyResult) |
855 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
856 self.failIf(presubmit_canned_checks.CheckChangeHasTestField( | |
857 api, presubmit.OutputApi)) | |
858 | |
859 change = self.MakeBasicChange('foo', | |
860 'Foo\nNOTEST=did some stuff') | |
861 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
862 self.failUnless(presubmit_canned_checks.CheckChangeHasTestField( | |
863 api, presubmit.OutputApi)) | |
864 | 875 |
865 def testCannedCheckChangeHasTestedField(self): | 876 def testCannedCheckChangeHasTestedField(self): |
866 self.mox.ReplayAll() | 877 self.TestDescription(presubmit_canned_checks.CheckChangeHasTestedField, |
867 change = self.MakeBasicChange('foo', | 878 'TESTED=did some stuff', '', |
868 'Foo\nTESTED=did some stuff') | 879 presubmit.OutputApi.PresubmitError) |
869 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
870 self.failIf(presubmit_canned_checks.CheckChangeHasTestedField( | |
871 api, presubmit.OutputApi)) | |
872 | |
873 change = self.MakeBasicChange('foo', | |
874 'Foo\nNEVERTESTED=did some stuff') | |
875 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
876 self.failUnless(presubmit_canned_checks.CheckChangeHasTestedField( | |
877 api, presubmit.OutputApi)) | |
878 | 880 |
879 def testCannedCheckChangeHasQAField(self): | 881 def testCannedCheckChangeHasQAField(self): |
880 self.mox.ReplayAll() | 882 self.TestDescription(presubmit_canned_checks.CheckChangeHasQaField, |
881 change = self.MakeBasicChange('foo', | 883 'QA=BSOD your machine', '', |
882 'Foo\nQA=test floop feature very well') | 884 presubmit.OutputApi.PresubmitError) |
883 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
884 self.failIf(presubmit_canned_checks.CheckChangeHasQaField( | |
885 api, presubmit.OutputApi)) | |
886 | |
887 change = self.MakeBasicChange('foo', | |
888 'Foo\nNOTFORQA=test floop feature very well') | |
889 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
890 self.failUnless(presubmit_canned_checks.CheckChangeHasQaField( | |
891 api, presubmit.OutputApi)) | |
892 | 885 |
893 def testCannedCheckDoNotSubmitInDescription(self): | 886 def testCannedCheckDoNotSubmitInDescription(self): |
894 self.mox.ReplayAll() | 887 self.TestDescription(presubmit_canned_checks.CheckDoNotSubmitInDescription, |
895 change = self.MakeBasicChange('foo', 'hello') | 888 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', |
896 api = presubmit.InputApi(change, './PRESUBMIT.py') | 889 presubmit.OutputApi.PresubmitError) |
897 self.failIf(presubmit_canned_checks.CheckDoNotSubmitInDescription( | |
898 api, presubmit.OutputApi)) | |
899 | |
900 change = self.MakeBasicChange('foo', | |
901 'DO NOT ' + 'SUBMIT') | |
902 api = presubmit.InputApi(change, './PRESUBMIT.py') | |
903 self.failUnless(presubmit_canned_checks.CheckDoNotSubmitInDescription( | |
904 api, presubmit.OutputApi)) | |
905 | 890 |
906 def testCannedCheckDoNotSubmitInFiles(self): | 891 def testCannedCheckDoNotSubmitInFiles(self): |
907 self.mox.ReplayAll() | 892 self.TestContent(presubmit_canned_checks.CheckDoNotSubmitInFiles, |
908 self.failIf(presubmit_canned_checks.CheckDoNotSubmitInFiles( | 893 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', |
909 self.MockInputApi(['hello', 'there']), presubmit.OutputApi | 894 presubmit.OutputApi.PresubmitError) |
910 )) | |
911 self.failUnless(presubmit_canned_checks.CheckDoNotSubmitInFiles( | |
912 self.MockInputApi(['hello', 'yo, DO NOT ' + 'SUBMIT']), | |
913 presubmit.OutputApi)) | |
914 | 895 |
915 def testCannedCheckChangeHasNoTabs(self): | 896 def testCannedCheckChangeHasNoTabs(self): |
916 self.mox.ReplayAll() | 897 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, |
917 self.failIf(presubmit_canned_checks.CheckChangeHasNoTabs( | 898 'blah blah', 'blah\tblah', |
918 self.MockInputApi(['hello', 'there']), presubmit.OutputApi | 899 presubmit.OutputApi.PresubmitError) |
919 )) | |
920 self.failUnless(presubmit_canned_checks.CheckChangeHasNoTabs( | |
921 self.MockInputApi(['hello', 'there\tit is']), presubmit.OutputApi | |
922 )) | |
923 | 900 |
924 def testCannedCheckLongLines(self): | 901 def testCannedCheckLongLines(self): |
| 902 check = lambda x,y: presubmit_canned_checks.CheckLongLines(x, y, 10) |
| 903 self.TestContent(check, '', 'blah blah blah', |
| 904 presubmit.OutputApi.PresubmitPromptWarning) |
| 905 |
| 906 def testCannedCheckTreeIsOpenOpen(self): |
| 907 input_api = self.MockInputApi() |
| 908 connection = self.mox.CreateMockAnything() |
| 909 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
| 910 connection.read().AndReturn('1') |
| 911 connection.close() |
925 self.mox.ReplayAll() | 912 self.mox.ReplayAll() |
926 self.failIf(presubmit_canned_checks.CheckLongLines( | 913 results = presubmit_canned_checks.CheckTreeIsOpen( |
927 self.MockInputApi(['hello', 'there']), presubmit.OutputApi, 5 | 914 input_api, presubmit.OutputApi, url='url_to_open', closed='0') |
928 )) | 915 self.assertEquals(results, []) |
929 self.failUnless(presubmit_canned_checks.CheckLongLines( | |
930 self.MockInputApi(['hello', 'there!']), presubmit.OutputApi, 5 | |
931 )) | |
932 | 916 |
933 def testCannedCheckTreeIsOpen(self): | 917 def testCannedCheckTreeIsOpenClosed(self): |
| 918 input_api = self.MockInputApi() |
| 919 connection = self.mox.CreateMockAnything() |
| 920 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) |
| 921 connection.read().AndReturn('0') |
| 922 connection.close() |
934 self.mox.ReplayAll() | 923 self.mox.ReplayAll() |
935 self.failIf(presubmit_canned_checks.CheckTreeIsOpen( | 924 results = presubmit_canned_checks.CheckTreeIsOpen( |
936 self.MockInputApi(), presubmit.OutputApi, url='url_to_open', closed='0' | 925 input_api, presubmit.OutputApi, url='url_to_closed', closed='0') |
937 )) | 926 self.assertEquals(len(results), 1) |
938 self.failUnless(presubmit_canned_checks.CheckTreeIsOpen( | 927 self.assertEquals(results[0].__class__, |
939 self.MockInputApi(), presubmit.OutputApi, url='url_to_closed', closed='0' | 928 presubmit.OutputApi.PresubmitError) |
940 )) | |
941 | 929 |
942 def RunPythonUnitTests(self): | 930 def testRunPythonUnitTests1(self): |
| 931 input_api = self.MockInputApi() |
943 self.mox.ReplayAll() | 932 self.mox.ReplayAll() |
944 # TODO(maruel): Add real tests. | 933 results = presubmit_canned_checks.RunPythonUnitTests( |
945 self.failIf(presubmit_canned_checks.RunPythonUnitTests( | 934 input_api, presubmit.OutputApi, []) |
946 self.MockInputApi(), | 935 self.assertEquals(results, []) |
947 presubmit.OutputApi, [])) | 936 |
948 self.failUnless(presubmit_canned_checks.RunPythonUnitTests( | 937 def testRunPythonUnitTests2(self): |
949 self.MockInputApi(), | 938 input_api = self.MockInputApi() |
950 presubmit.OutputApi, ['non_existent_module'])) | 939 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module' |
| 940 ).AndRaise(exceptions.ImportError('Blehh')) |
| 941 self.mox.ReplayAll() |
| 942 results = presubmit_canned_checks.RunPythonUnitTests( |
| 943 input_api, presubmit.OutputApi, ['_non_existent_module']) |
| 944 self.assertEquals(len(results), 1) |
| 945 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) |
| 946 |
| 947 def testRunPythonUnitTests3(self): |
| 948 input_api = self.MockInputApi() |
| 949 test_module = self.mox.CreateMockAnything() |
| 950 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' |
| 951 ).AndReturn([]) |
| 952 self.mox.ReplayAll() |
| 953 |
| 954 results = presubmit_canned_checks.RunPythonUnitTests( |
| 955 input_api, presubmit.OutputApi, ['test_module']) |
| 956 self.assertEquals(results, []) |
| 957 |
| 958 def testRunPythonUnitTests4(self): |
| 959 input_api = self.MockInputApi() |
| 960 input_api.unittest = self.mox.CreateMock(unittest) |
| 961 test = self.mox.CreateMockAnything() |
| 962 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' |
| 963 ).AndReturn([test]) |
| 964 runner = self.mox.CreateMockAnything() |
| 965 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) |
| 966 suite = self.mox.CreateMockAnything() |
| 967 input_api.unittest.TestSuite([test]).AndReturn(suite) |
| 968 test_result = self.mox.CreateMockAnything() |
| 969 runner.run(suite).AndReturn(test_result) |
| 970 test_result.wasSuccessful().AndReturn(False) |
| 971 test_result.failures = 2 |
| 972 test_result.errors = 3 |
| 973 self.mox.ReplayAll() |
| 974 |
| 975 results = presubmit_canned_checks.RunPythonUnitTests( |
| 976 input_api, presubmit.OutputApi, ['test_module']) |
| 977 self.assertEquals(len(results), 1) |
| 978 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) |
| 979 |
| 980 def testRunPythonUnitTests5(self): |
| 981 input_api = self.MockInputApi() |
| 982 input_api.unittest = self.mox.CreateMock(unittest) |
| 983 test = self.mox.CreateMockAnything() |
| 984 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' |
| 985 ).AndReturn([test]) |
| 986 runner = self.mox.CreateMockAnything() |
| 987 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) |
| 988 suite = self.mox.CreateMockAnything() |
| 989 input_api.unittest.TestSuite([test]).AndReturn(suite) |
| 990 test_result = self.mox.CreateMockAnything() |
| 991 runner.run(suite).AndReturn(test_result) |
| 992 test_result.wasSuccessful().AndReturn(True) |
| 993 test_result.failures = 0 |
| 994 test_result.errors = 0 |
| 995 self.mox.ReplayAll() |
| 996 |
| 997 results = presubmit_canned_checks.RunPythonUnitTests( |
| 998 input_api, presubmit.OutputApi, ['test_module']) |
| 999 self.assertEquals(len(results), 0) |
| 1000 |
951 | 1001 |
952 if __name__ == '__main__': | 1002 if __name__ == '__main__': |
953 unittest.main() | 1003 unittest.main() |
OLD | NEW |