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 os |
10 import StringIO | 10 import StringIO |
(...skipping 17 matching lines...) Expand all Loading... |
28 elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: | 28 elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: |
29 return [output_api.PresubmitPromptWarning("??"), | 29 return [output_api.PresubmitPromptWarning("??"), |
30 output_api.PresubmitError("XX!!XX")] | 30 output_api.PresubmitError("XX!!XX")] |
31 else: | 31 else: |
32 return () | 32 return () |
33 """ | 33 """ |
34 | 34 |
35 def setUp(self): | 35 def setUp(self): |
36 super_mox.SuperMoxTestBase.setUp(self) | 36 super_mox.SuperMoxTestBase.setUp(self) |
37 self.mox.StubOutWithMock(presubmit, 'warnings') | 37 self.mox.StubOutWithMock(presubmit, 'warnings') |
38 # Stub out 'os' but keep os.path.dirname/join/normpath/splitext and os.sep. | 38 # Stub out 'os' but keep os.path.commonprefix/dirname/join/normpath/splitext |
| 39 # and os.sep. |
39 os_sep = presubmit.os.sep | 40 os_sep = presubmit.os.sep |
| 41 os_path_commonprefix = presubmit.os.path.commonprefix |
| 42 os_path_dirname = presubmit.os.path.dirname |
40 os_path_join = presubmit.os.path.join | 43 os_path_join = presubmit.os.path.join |
41 os_path_dirname = presubmit.os.path.dirname | |
42 os_path_normpath = presubmit.os.path.normpath | 44 os_path_normpath = presubmit.os.path.normpath |
43 os_path_splitext = presubmit.os.path.splitext | 45 os_path_splitext = presubmit.os.path.splitext |
44 self.mox.StubOutWithMock(presubmit, 'os') | 46 self.mox.StubOutWithMock(presubmit, 'os') |
45 self.mox.StubOutWithMock(presubmit.os, 'path') | 47 self.mox.StubOutWithMock(presubmit.os, 'path') |
46 presubmit.os.sep = os_sep | 48 presubmit.os.sep = os_sep |
47 presubmit.os.path.join = os_path_join | 49 presubmit.os.path.join = os_path_join |
48 presubmit.os.path.dirname = os_path_dirname | 50 presubmit.os.path.dirname = os_path_dirname |
49 presubmit.os.path.normpath = os_path_normpath | 51 presubmit.os.path.normpath = os_path_normpath |
50 presubmit.os.path.splitext = os_path_splitext | 52 presubmit.os.path.splitext = os_path_splitext |
51 self.mox.StubOutWithMock(presubmit, 'random') | 53 self.mox.StubOutWithMock(presubmit, 'random') |
52 self.mox.StubOutWithMock(presubmit, 'sys') | 54 self.mox.StubOutWithMock(presubmit, 'sys') |
53 presubmit._ASKED_FOR_FEEDBACK = False | 55 presubmit._ASKED_FOR_FEEDBACK = False |
54 # Special mocks. | 56 # Special mocks. |
55 def MockAbsPath(f): | 57 def MockAbsPath(f): |
56 return f | 58 return f |
57 presubmit.os.path.abspath = MockAbsPath | 59 presubmit.os.path.abspath = MockAbsPath |
| 60 presubmit.os.path.commonprefix = os_path_commonprefix |
58 self.fake_root_dir = self.RootDir() | 61 self.fake_root_dir = self.RootDir() |
59 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') | 62 self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') |
60 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') | 63 self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') |
61 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') | 64 self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') |
62 | 65 |
63 | 66 |
64 class PresubmitUnittest(PresubmitTestsBase): | 67 class PresubmitUnittest(PresubmitTestsBase): |
65 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 68 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
66 def testMembersChanged(self): | 69 def testMembersChanged(self): |
67 self.mox.ReplayAll() | 70 self.mox.ReplayAll() |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 def CheckChangeOnCommit(input_api, output_api): | 390 def CheckChangeOnCommit(input_api, output_api): |
388 raise Exception("Test error") | 391 raise Exception("Test error") |
389 """ | 392 """ |
390 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') | 393 presubmit.os.path.isfile(join(self.fake_root_dir, 'PRESUBMIT.py') |
391 ).AndReturn(False) | 394 ).AndReturn(False) |
392 presubmit.os.path.isfile(join(self.fake_root_dir, | 395 presubmit.os.path.isfile(join(self.fake_root_dir, |
393 'haspresubmit', | 396 'haspresubmit', |
394 'PRESUBMIT.py')).AndReturn(False) | 397 'PRESUBMIT.py')).AndReturn(False) |
395 presubmit.random.randint(0, 4).AndReturn(0) | 398 presubmit.random.randint(0, 4).AndReturn(0) |
396 self.mox.ReplayAll() | 399 self.mox.ReplayAll() |
397 | 400 |
398 output = StringIO.StringIO() | 401 output = StringIO.StringIO() |
399 input = StringIO.StringIO('y\n') | 402 input = StringIO.StringIO('y\n') |
400 # Always fail. | 403 # Always fail. |
401 change = presubmit.Change('mychange', '\n'.join(description_lines), | 404 change = presubmit.Change('mychange', '\n'.join(description_lines), |
402 self.fake_root_dir, files, 0, 0) | 405 self.fake_root_dir, files, 0, 0) |
403 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, | 406 self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input, |
404 DEFAULT_SCRIPT, False)) | 407 DEFAULT_SCRIPT, False)) |
405 text = ('Warning, no presubmit.py found.\n' | 408 text = ('Warning, no presubmit.py found.\n' |
406 'Running default presubmit script.\n' | 409 'Running default presubmit script.\n' |
407 '** Presubmit ERRORS **\n!!\n\n' | 410 '** Presubmit ERRORS **\n!!\n\n' |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 try: | 447 try: |
445 y = False | 448 y = False |
446 x = input_api.change.invalid | 449 x = input_api.change.invalid |
447 except AttributeError: | 450 except AttributeError: |
448 y = True | 451 y = True |
449 if not y: | 452 if not y: |
450 return [output_api.PresubmitError('Tag parsing failed. 8')] | 453 return [output_api.PresubmitError('Tag parsing failed. 8')] |
451 if 'TEST' in input_api.change.tags: | 454 if 'TEST' in input_api.change.tags: |
452 return [output_api.PresubmitError('Tag parsing failed. 3')] | 455 return [output_api.PresubmitError('Tag parsing failed. 3')] |
453 if input_api.change.DescriptionText() != 'Blah Blah': | 456 if input_api.change.DescriptionText() != 'Blah Blah': |
454 return [output_api.PresubmitError('Tag parsing failed. 4 ' + | 457 return [output_api.PresubmitError('Tag parsing failed. 4 ' + |
455 input_api.change.DescriptionText())] | 458 input_api.change.DescriptionText())] |
456 if (input_api.change.FullDescriptionText() != | 459 if (input_api.change.FullDescriptionText() != |
457 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): | 460 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): |
458 return [output_api.PresubmitError('Tag parsing failed. 5 ' + | 461 return [output_api.PresubmitError('Tag parsing failed. 5 ' + |
459 input_api.change.FullDescriptionText())] | 462 input_api.change.FullDescriptionText())] |
460 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] | 463 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] |
461 def CheckChangeOnCommit(input_api, output_api): | 464 def CheckChangeOnCommit(input_api, output_api): |
462 raise Exception("Test error") | 465 raise Exception("Test error") |
463 """ | 466 """ |
464 presubmit.random.randint(0, 4).AndReturn(1) | 467 presubmit.random.randint(0, 4).AndReturn(1) |
(...skipping 18 matching lines...) Expand all Loading... |
483 presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.git') | 486 presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.git') |
484 ).AndReturn(False) | 487 ).AndReturn(False) |
485 presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.svn') | 488 presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.svn') |
486 ).AndReturn(False) | 489 ).AndReturn(False) |
487 #presubmit.ParseFiles([], None).AndReturn([]) | 490 #presubmit.ParseFiles([], None).AndReturn([]) |
488 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, | 491 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, |
489 mox.IgnoreArg(), | 492 mox.IgnoreArg(), |
490 mox.IgnoreArg(), | 493 mox.IgnoreArg(), |
491 None, False).AndReturn(False) | 494 None, False).AndReturn(False) |
492 self.mox.ReplayAll() | 495 self.mox.ReplayAll() |
493 | 496 |
494 self.assertEquals(True, | 497 self.assertEquals(True, |
495 presubmit.Main(['presubmit', '--root', | 498 presubmit.Main(['presubmit', '--root', |
496 self.fake_root_dir])) | 499 self.fake_root_dir])) |
497 | 500 |
498 | 501 |
499 class InputApiUnittest(PresubmitTestsBase): | 502 class InputApiUnittest(PresubmitTestsBase): |
500 """Tests presubmit.InputApi.""" | 503 """Tests presubmit.InputApi.""" |
501 def testMembersChanged(self): | 504 def testMembersChanged(self): |
502 self.mox.ReplayAll() | 505 self.mox.ReplayAll() |
503 members = [ | 506 members = [ |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 self.failIf(warning._Handle(output, input)) | 893 self.failIf(warning._Handle(output, input)) |
891 self.failUnless(output.getvalue().count('???')) | 894 self.failUnless(output.getvalue().count('???')) |
892 | 895 |
893 | 896 |
894 class AffectedFileUnittest(PresubmitTestsBase): | 897 class AffectedFileUnittest(PresubmitTestsBase): |
895 def testMembersChanged(self): | 898 def testMembersChanged(self): |
896 self.mox.ReplayAll() | 899 self.mox.ReplayAll() |
897 members = [ | 900 members = [ |
898 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath', | 901 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath', |
899 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', | 902 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', |
900 'scm', | |
901 ] | 903 ] |
902 # If this test fails, you should add the relevant test. | 904 # If this test fails, you should add the relevant test. |
903 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) | 905 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) |
904 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) | 906 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) |
905 | 907 |
906 def testAffectedFile(self): | 908 def testAffectedFile(self): |
907 path = presubmit.os.path.join('foo', 'blat.cc') | 909 path = presubmit.os.path.join('foo', 'blat.cc') |
908 presubmit.os.path.exists(path).AndReturn(True) | 910 presubmit.os.path.exists(path).AndReturn(True) |
909 presubmit.os.path.isdir(path).AndReturn(False) | 911 presubmit.os.path.isdir(path).AndReturn(False) |
910 presubmit.gcl.ReadFile(path).AndReturn('whatever\ncookie') | 912 presubmit.gcl.ReadFile(path).AndReturn('whatever\ncookie') |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 self.failUnless(len(output) == 1) | 969 self.failUnless(len(output) == 1) |
968 self.failUnless(list[0] == output[0]) | 970 self.failUnless(list[0] == output[0]) |
969 | 971 |
970 | 972 |
971 class GclChangeUnittest(PresubmitTestsBase): | 973 class GclChangeUnittest(PresubmitTestsBase): |
972 def testMembersChanged(self): | 974 def testMembersChanged(self): |
973 members = [ | 975 members = [ |
974 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 976 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', |
975 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', | 977 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', |
976 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', | 978 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', |
977 'issue', 'patchset', 'tags', | 979 'issue', 'patchset', 'scm', 'tags', |
978 ] | 980 ] |
979 # If this test fails, you should add the relevant test. | 981 # If this test fails, you should add the relevant test. |
980 self.mox.ReplayAll() | 982 self.mox.ReplayAll() |
981 | 983 |
982 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], | 984 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], |
983 0, 0) | 985 0, 0) |
984 self.compareMembers(change, members) | 986 self.compareMembers(change, members) |
985 | 987 |
986 | 988 |
987 class CannedChecksUnittest(PresubmitTestsBase): | 989 class CannedChecksUnittest(PresubmitTestsBase): |
988 """Tests presubmit_canned_checks.py.""" | 990 """Tests presubmit_canned_checks.py.""" |
989 | 991 |
990 def setUp(self): | 992 def setUp(self): |
991 PresubmitTestsBase.setUp(self) | 993 PresubmitTestsBase.setUp(self) |
992 | 994 |
993 def MockInputApi(self, change, committing): | 995 def MockInputApi(self, change, committing): |
994 input_api = self.mox.CreateMock(presubmit.InputApi) | 996 input_api = self.mox.CreateMock(presubmit.InputApi) |
995 input_api.cStringIO = presubmit.cStringIO | 997 input_api.cStringIO = presubmit.cStringIO |
| 998 input_api.os_path = presubmit.os.path |
996 input_api.re = presubmit.re | 999 input_api.re = presubmit.re |
997 input_api.traceback = presubmit.traceback | 1000 input_api.traceback = presubmit.traceback |
998 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) | 1001 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) |
999 input_api.unittest = unittest | 1002 input_api.unittest = unittest |
1000 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess) | 1003 input_api.subprocess = self.mox.CreateMock(presubmit.subprocess) |
1001 | 1004 |
1002 input_api.change = change | 1005 input_api.change = change |
1003 input_api.is_committing = committing | 1006 input_api.is_committing = committing |
1004 input_api.python_executable = 'pyyyyython' | 1007 input_api.python_executable = 'pyyyyython' |
1005 return input_api | 1008 return input_api |
1006 | 1009 |
1007 def testMembersChanged(self): | 1010 def testMembersChanged(self): |
1008 self.mox.ReplayAll() | 1011 self.mox.ReplayAll() |
1009 members = [ | 1012 members = [ |
1010 'CheckChangeHasBugField', 'CheckChangeHasDescription', | 1013 'CheckChangeHasBugField', 'CheckChangeHasDescription', |
1011 'CheckChangeHasNoStrayWhitespace', | 1014 'CheckChangeHasNoStrayWhitespace', |
1012 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', | 1015 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', |
1013 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', | 1016 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', |
1014 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 1017 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
1015 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', | 1018 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', |
| 1019 'CheckSvnModifiedDirectories', |
1016 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', | 1020 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', |
1017 'CheckDoNotSubmit', | 1021 'CheckDoNotSubmit', |
1018 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 1022 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
1019 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 1023 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
1020 ] | 1024 ] |
1021 # If this test fails, you should add the relevant test. | 1025 # If this test fails, you should add the relevant test. |
1022 self.compareMembers(presubmit_canned_checks, members) | 1026 self.compareMembers(presubmit_canned_checks, members) |
1023 | 1027 |
1024 def DescriptionTest(self, check, description1, description2, error_type, | 1028 def DescriptionTest(self, check, description1, description2, error_type, |
1025 committing): | 1029 committing): |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 self.mox.ReplayAll() | 1088 self.mox.ReplayAll() |
1085 | 1089 |
1086 results = check(input_api1, presubmit.OutputApi) | 1090 results = check(input_api1, presubmit.OutputApi) |
1087 self.assertEquals(results, []) | 1091 self.assertEquals(results, []) |
1088 results2 = check(input_api2, presubmit.OutputApi) | 1092 results2 = check(input_api2, presubmit.OutputApi) |
1089 self.assertEquals(len(results2), 1) | 1093 self.assertEquals(len(results2), 1) |
1090 self.assertEquals(results2[0].__class__, error_type) | 1094 self.assertEquals(results2[0].__class__, error_type) |
1091 | 1095 |
1092 def SvnPropertyTest(self, check, property, value1, value2, committing, | 1096 def SvnPropertyTest(self, check, property, value1, value2, committing, |
1093 error_type, use_source_file): | 1097 error_type, use_source_file): |
1094 input_api1 = self.MockInputApi(None, committing) | 1098 change1 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) |
| 1099 input_api1 = self.MockInputApi(change1, committing) |
1095 files1 = [ | 1100 files1 = [ |
1096 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | 1101 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
1097 presubmit.SvnAffectedFile('foo.cc', 'M'), | 1102 presubmit.SvnAffectedFile('foo.cc', 'M'), |
1098 ] | 1103 ] |
1099 if use_source_file: | 1104 if use_source_file: |
1100 input_api1.AffectedSourceFiles(None).AndReturn(files1) | 1105 input_api1.AffectedSourceFiles(None).AndReturn(files1) |
1101 else: | 1106 else: |
1102 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1) | 1107 input_api1.AffectedFiles(include_deleted=False).AndReturn(files1) |
1103 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), | 1108 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
1104 property).AndReturn(value1) | 1109 property).AndReturn(value1) |
1105 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), | 1110 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
1106 property).AndReturn(value1) | 1111 property).AndReturn(value1) |
1107 input_api2 = self.MockInputApi(None, committing) | 1112 change2 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) |
| 1113 input_api2 = self.MockInputApi(change2, committing) |
1108 files2 = [ | 1114 files2 = [ |
1109 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | 1115 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
1110 presubmit.SvnAffectedFile('foo.cc', 'M'), | 1116 presubmit.SvnAffectedFile('foo.cc', 'M'), |
1111 ] | 1117 ] |
1112 if use_source_file: | 1118 if use_source_file: |
1113 input_api2.AffectedSourceFiles(None).AndReturn(files2) | 1119 input_api2.AffectedSourceFiles(None).AndReturn(files2) |
1114 else: | 1120 else: |
1115 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2) | 1121 input_api2.AffectedFiles(include_deleted=False).AndReturn(files2) |
1116 | 1122 |
1117 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), | 1123 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
1118 property).AndReturn(value2) | 1124 property).AndReturn(value2) |
1119 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), | 1125 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
1120 property).AndReturn(value2) | 1126 property).AndReturn(value2) |
1121 self.mox.ReplayAll() | 1127 self.mox.ReplayAll() |
1122 | 1128 |
1123 results1 = check(input_api1, presubmit.OutputApi, None) | 1129 results1 = check(input_api1, presubmit.OutputApi, None) |
1124 self.assertEquals(results1, []) | 1130 self.assertEquals(results1, []) |
1125 results2 = check(input_api2, presubmit.OutputApi, None) | 1131 results2 = check(input_api2, presubmit.OutputApi, None) |
1126 self.assertEquals(len(results2), 1) | 1132 self.assertEquals(len(results2), 1) |
1127 self.assertEquals(results2[0].__class__, error_type) | 1133 self.assertEquals(results2[0].__class__, error_type) |
1128 | 1134 |
1129 def testCannedCheckChangeHasBugField(self): | 1135 def testCannedCheckChangeHasBugField(self): |
1130 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, | 1136 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, |
1131 'Foo\nBUG=1234', 'Foo\n', | 1137 'Foo\nBUG=1234', 'Foo\n', |
1132 presubmit.OutputApi.PresubmitNotifyResult, | 1138 presubmit.OutputApi.PresubmitNotifyResult, |
1133 False) | 1139 False) |
1134 | 1140 |
1135 def testCheckChangeHasDescription(self): | 1141 def testCheckChangeHasDescription(self): |
1136 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, | 1142 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, |
1137 'Bleh', '', | 1143 'Bleh', '', |
1138 presubmit.OutputApi.PresubmitNotifyResult, | 1144 presubmit.OutputApi.PresubmitNotifyResult, |
1139 False) | 1145 False) |
1140 self.mox.VerifyAll() | 1146 self.mox.VerifyAll() |
1141 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, | 1147 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, |
1142 'Bleh', '', | 1148 'Bleh', '', |
1143 presubmit.OutputApi.PresubmitError, | 1149 presubmit.OutputApi.PresubmitError, |
1144 True) | 1150 True) |
1145 | 1151 |
1146 def testCannedCheckChangeHasTestField(self): | 1152 def testCannedCheckChangeHasTestField(self): |
1147 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField, | 1153 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField, |
1148 'Foo\nTEST=did some stuff', 'Foo\n', | 1154 'Foo\nTEST=did some stuff', 'Foo\n', |
1149 presubmit.OutputApi.PresubmitNotifyResult, | 1155 presubmit.OutputApi.PresubmitNotifyResult, |
1150 False) | 1156 False) |
1151 | 1157 |
1152 def testCannedCheckChangeHasTestedField(self): | 1158 def testCannedCheckChangeHasTestedField(self): |
1153 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField, | 1159 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField, |
1154 'Foo\nTESTED=did some stuff', 'Foo\n', | 1160 'Foo\nTESTED=did some stuff', 'Foo\n', |
1155 presubmit.OutputApi.PresubmitError, | 1161 presubmit.OutputApi.PresubmitError, |
(...skipping 16 matching lines...) Expand all Loading... |
1172 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), | 1178 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), |
1173 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1179 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', |
1174 presubmit.OutputApi.PresubmitError) | 1180 presubmit.OutputApi.PresubmitError) |
1175 | 1181 |
1176 def testCheckChangeHasNoStrayWhitespace(self): | 1182 def testCheckChangeHasNoStrayWhitespace(self): |
1177 self.ContentTest( | 1183 self.ContentTest( |
1178 lambda x,y,z: | 1184 lambda x,y,z: |
1179 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), | 1185 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), |
1180 'Foo', 'Foo ', | 1186 'Foo', 'Foo ', |
1181 presubmit.OutputApi.PresubmitPromptWarning) | 1187 presubmit.OutputApi.PresubmitPromptWarning) |
1182 | 1188 |
1183 | 1189 |
1184 def testCheckChangeHasOnlyOneEol(self): | 1190 def testCheckChangeHasOnlyOneEol(self): |
1185 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, | 1191 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, |
1186 "Hey!\nHo!\n", "Hey!\nHo!\n\n", | 1192 "Hey!\nHo!\n", "Hey!\nHo!\n\n", |
1187 presubmit.OutputApi.PresubmitPromptWarning) | 1193 presubmit.OutputApi.PresubmitPromptWarning) |
1188 | 1194 |
1189 def testCheckChangeHasNoCR(self): | 1195 def testCheckChangeHasNoCR(self): |
1190 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, | 1196 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, |
1191 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", | 1197 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", |
1192 presubmit.OutputApi.PresubmitPromptWarning) | 1198 presubmit.OutputApi.PresubmitPromptWarning) |
1193 | 1199 |
1194 def testCheckChangeHasNoCrAndHasOnlyOneEol(self): | 1200 def testCheckChangeHasNoCrAndHasOnlyOneEol(self): |
1195 self.ReadFileTest( | 1201 self.ReadFileTest( |
1196 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, | 1202 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, |
1197 "Hey!\nHo!\n", "Hey!\nHo!\n\n", | 1203 "Hey!\nHo!\n", "Hey!\nHo!\n\n", |
1198 presubmit.OutputApi.PresubmitPromptWarning) | 1204 presubmit.OutputApi.PresubmitPromptWarning) |
1199 self.mox.VerifyAll() | 1205 self.mox.VerifyAll() |
1200 self.ReadFileTest( | 1206 self.ReadFileTest( |
1201 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, | 1207 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, |
1202 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", | 1208 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", |
1203 presubmit.OutputApi.PresubmitPromptWarning) | 1209 presubmit.OutputApi.PresubmitPromptWarning) |
(...skipping 12 matching lines...) Expand all Loading... |
1216 # Test CheckSvnProperty at the same time. | 1222 # Test CheckSvnProperty at the same time. |
1217 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1223 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1218 'svn:eol-style', 'LF', '', True, | 1224 'svn:eol-style', 'LF', '', True, |
1219 presubmit.OutputApi.PresubmitError, True) | 1225 presubmit.OutputApi.PresubmitError, True) |
1220 | 1226 |
1221 def testCheckChangeSvnEolStyleUpload(self): | 1227 def testCheckChangeSvnEolStyleUpload(self): |
1222 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1228 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1223 'svn:eol-style', 'LF', '', False, | 1229 'svn:eol-style', 'LF', '', False, |
1224 presubmit.OutputApi.PresubmitNotifyResult, True) | 1230 presubmit.OutputApi.PresubmitNotifyResult, True) |
1225 | 1231 |
| 1232 def testCannedCheckSvnAccidentalSubmission(self): |
| 1233 modified_dir_file = 'foo/' |
| 1234 accidental_submssion_file = 'foo/bar.cc' |
| 1235 |
| 1236 change = self.mox.CreateMock(presubmit.SvnChange) |
| 1237 change.scm = 'svn' |
| 1238 change.GetModifiedFiles().AndReturn([modified_dir_file]) |
| 1239 change.GetAllModifiedFiles().AndReturn([modified_dir_file, |
| 1240 accidental_submssion_file]) |
| 1241 input_api = self.MockInputApi(change, True) |
| 1242 |
| 1243 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1244 affected_file.Action().AndReturn('M') |
| 1245 affected_file.IsDirectory().AndReturn(True) |
| 1246 affected_file.AbsoluteLocalPath().AndReturn(accidental_submssion_file) |
| 1247 affected_file.LocalPath().AndReturn(accidental_submssion_file) |
| 1248 input_api.AffectedFiles(None).AndReturn([affected_file]) |
| 1249 |
| 1250 self.mox.ReplayAll() |
| 1251 |
| 1252 check = presubmit_canned_checks.CheckSvnModifiedDirectories |
| 1253 results = check(input_api, presubmit.OutputApi, None) |
| 1254 self.assertEquals(len(results), 1) |
| 1255 self.assertEquals(results[0].__class__, |
| 1256 presubmit.OutputApi.PresubmitPromptWarning) |
| 1257 |
1226 def testCheckSvnForCommonMimeTypes(self): | 1258 def testCheckSvnForCommonMimeTypes(self): |
1227 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') | 1259 self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty') |
1228 input_api = self.MockInputApi(None, False) | 1260 input_api = self.MockInputApi(None, False) |
1229 output_api = presubmit.OutputApi() | 1261 output_api = presubmit.OutputApi() |
1230 A = lambda x: presubmit.AffectedFile(x, 'M') | 1262 A = lambda x: presubmit.AffectedFile(x, 'M') |
1231 files = [ | 1263 files = [ |
1232 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), | 1264 A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'), |
1233 A('random'), A('g.jpeg'), A('h.ico'), | 1265 A('random'), A('g.jpeg'), A('h.ico'), |
1234 ] | 1266 ] |
1235 input_api.AffectedFiles(include_deletes=False).AndReturn(files) | 1267 input_api.AffectedFiles(include_deletes=False).AndReturn(files) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 process.communicate().AndReturn(('', '')) | 1407 process.communicate().AndReturn(('', '')) |
1376 self.mox.ReplayAll() | 1408 self.mox.ReplayAll() |
1377 | 1409 |
1378 results = presubmit_canned_checks.RunPythonUnitTests( | 1410 results = presubmit_canned_checks.RunPythonUnitTests( |
1379 input_api, presubmit.OutputApi, ['test_module']) | 1411 input_api, presubmit.OutputApi, ['test_module']) |
1380 self.assertEquals(len(results), 0) | 1412 self.assertEquals(len(results), 0) |
1381 | 1413 |
1382 | 1414 |
1383 if __name__ == '__main__': | 1415 if __name__ == '__main__': |
1384 unittest.main() | 1416 unittest.main() |
OLD | NEW |