| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 53   elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: | 53   elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: | 
| 54     return [output_api.PresubmitPromptWarning("??"), | 54     return [output_api.PresubmitPromptWarning("??"), | 
| 55             output_api.PresubmitError("XX!!XX")] | 55             output_api.PresubmitError("XX!!XX")] | 
| 56   else: | 56   else: | 
| 57     return () | 57     return () | 
| 58 """ | 58 """ | 
| 59 | 59 | 
| 60   def setUp(self): | 60   def setUp(self): | 
| 61     mox.MoxTestBase.setUp(self) | 61     mox.MoxTestBase.setUp(self) | 
| 62     self.mox.StubOutWithMock(presubmit, 'warnings') | 62     self.mox.StubOutWithMock(presubmit, 'warnings') | 
| 63     # Stub out 'os' but keep os.path.dirname/join/normpath and os.sep. | 63     # Stub out 'os' but keep os.path.dirname/join/normpath/splitext and os.sep. | 
| 64     os_sep = presubmit.os.sep | 64     os_sep = presubmit.os.sep | 
| 65     os_path_join = presubmit.os.path.join | 65     os_path_join = presubmit.os.path.join | 
| 66     os_path_dirname = presubmit.os.path.dirname | 66     os_path_dirname = presubmit.os.path.dirname | 
| 67     os_path_normpath = presubmit.os.path.normpath | 67     os_path_normpath = presubmit.os.path.normpath | 
|  | 68     os_path_splitext = presubmit.os.path.splitext | 
| 68     self.mox.StubOutWithMock(presubmit, 'os') | 69     self.mox.StubOutWithMock(presubmit, 'os') | 
| 69     self.mox.StubOutWithMock(presubmit.os, 'path') | 70     self.mox.StubOutWithMock(presubmit.os, 'path') | 
| 70     presubmit.os.sep = os_sep | 71     presubmit.os.sep = os_sep | 
| 71     presubmit.os.path.join = os_path_join | 72     presubmit.os.path.join = os_path_join | 
| 72     presubmit.os.path.dirname = os_path_dirname | 73     presubmit.os.path.dirname = os_path_dirname | 
| 73     presubmit.os.path.normpath = os_path_normpath | 74     presubmit.os.path.normpath = os_path_normpath | 
|  | 75     presubmit.os.path.splitext = os_path_splitext | 
| 74     self.mox.StubOutWithMock(presubmit, 'sys') | 76     self.mox.StubOutWithMock(presubmit, 'sys') | 
| 75     # Special mocks. | 77     # Special mocks. | 
| 76     def MockAbsPath(f): | 78     def MockAbsPath(f): | 
| 77       return f | 79       return f | 
| 78     presubmit.os.path.abspath = MockAbsPath | 80     presubmit.os.path.abspath = MockAbsPath | 
| 79     self.mox.StubOutWithMock(presubmit.gcl, 'GetRepositoryRoot') | 81     self.mox.StubOutWithMock(presubmit.gcl, 'GetRepositoryRoot') | 
| 80     fake_root_dir = RootDir() | 82     fake_root_dir = RootDir() | 
| 81     self.fake_root_dir = fake_root_dir | 83     self.fake_root_dir = fake_root_dir | 
| 82     def MockGetRepositoryRoot(): | 84     def MockGetRepositoryRoot(): | 
| 83       return fake_root_dir | 85       return fake_root_dir | 
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 516                        'Running default presubmit script.\n\n' | 518                        'Running default presubmit script.\n\n' | 
| 517                        '** Presubmit Messages **\n\n' | 519                        '** Presubmit Messages **\n\n' | 
| 518                        'http://tracker.com/42\n\n')) | 520                        'http://tracker.com/42\n\n')) | 
| 519 | 521 | 
| 520 | 522 | 
| 521 class InputApiUnittest(PresubmitTestsBase): | 523 class InputApiUnittest(PresubmitTestsBase): | 
| 522   """Tests presubmit.InputApi.""" | 524   """Tests presubmit.InputApi.""" | 
| 523   def testMembersChanged(self): | 525   def testMembersChanged(self): | 
| 524     self.mox.ReplayAll() | 526     self.mox.ReplayAll() | 
| 525     members = [ | 527     members = [ | 
| 526       'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', | 528       'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', | 
| 527       'DepotToLocalPath', 'LocalPaths', 'LocalToDepotPath', | 529       'AffectedTextFiles', | 
| 528       'PresubmitLocalPath', 'RightHandSideLines', 'ReadFile', 'ServerPaths', | 530       'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', | 
|  | 531       'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', | 
|  | 532       'LocalToDepotPath', | 
|  | 533       'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', | 
| 529       'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', | 534       'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', | 
| 530       'is_committing', 'marshal', 'os_path', 'pickle', 'platform', | 535       'is_committing', 'marshal', 'os_path', 'pickle', 'platform', | 
| 531       're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', | 536       're', 'subprocess', 'tempfile', 'traceback', 'unittest', 'urllib2', | 
| 532       'version', | 537       'version', | 
| 533     ] | 538     ] | 
| 534     # If this test fails, you should add the relevant test. | 539     # If this test fails, you should add the relevant test. | 
| 535     self.compareMembers(presubmit.InputApi(None, './.', False), members) | 540     self.compareMembers(presubmit.InputApi(None, './.', False), members) | 
| 536 | 541 | 
| 537   def testDepotToLocalPath(self): | 542   def testDepotToLocalPath(self): | 
| 538     presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn( | 543     presubmit.gclient.CaptureSVNInfo('svn://foo/smurf').AndReturn( | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 566     self.assertEquals(api.PresubmitLocalPath(), 'foo/path') | 571     self.assertEquals(api.PresubmitLocalPath(), 'foo/path') | 
| 567     self.assertEquals(api.change, 42) | 572     self.assertEquals(api.change, 42) | 
| 568 | 573 | 
| 569   def testInputApiPresubmitScriptFiltering(self): | 574   def testInputApiPresubmitScriptFiltering(self): | 
| 570     join = presubmit.os.path.join | 575     join = presubmit.os.path.join | 
| 571     description_lines = ('Hello there', | 576     description_lines = ('Hello there', | 
| 572                          'this is a change', | 577                          'this is a change', | 
| 573                          'BUG=123', | 578                          'BUG=123', | 
| 574                          ' STORY =http://foo/  \t', | 579                          ' STORY =http://foo/  \t', | 
| 575                          'and some more regular text') | 580                          'and some more regular text') | 
|  | 581     blat = join('foo', 'blat.cc') | 
|  | 582     readme = join('foo', 'blat', 'READ_ME2') | 
|  | 583     binary = join('foo', 'blat', 'binary.dll') | 
|  | 584     weird = join('foo', 'blat', 'weird.xyz') | 
|  | 585     third_party = join('foo', 'third_party', 'third.cc') | 
|  | 586     another = join('foo', 'blat', 'another.h') | 
|  | 587     beingdeleted = join('foo', 'mat', 'beingdeleted.txt') | 
|  | 588     notfound = join('flop', 'notfound.txt') | 
|  | 589     flap = join('boo', 'flap.h') | 
| 576     files = [ | 590     files = [ | 
| 577       ['A', join('foo', 'blat.cc')], | 591       ['A', blat], | 
| 578       ['M', join('foo', 'blat', 'binary.dll')], | 592       ['M', readme], | 
|  | 593       ['M', binary], | 
|  | 594       ['M', weird], | 
|  | 595       ['M', another], | 
|  | 596       ['M', third_party], | 
| 579       ['D', 'foo/mat/beingdeleted.txt'], | 597       ['D', 'foo/mat/beingdeleted.txt'], | 
| 580       ['M', 'flop/notfound.txt'], | 598       ['M', 'flop/notfound.txt'], | 
| 581       ['A', 'boo/flap.h'], | 599       ['A', 'boo/flap.h'], | 
| 582     ] | 600     ] | 
| 583 | 601 | 
| 584 | 602     for i in (blat, readme, binary, weird, another, third_party): | 
| 585     blat = join('foo', 'blat.cc') | 603       presubmit.os.path.exists(i).AndReturn(True) | 
| 586     binary = join('foo', 'blat', 'binary.dll') | 604       presubmit.os.path.isdir(i).AndReturn(False) | 
| 587     beingdeleted = join('foo', 'mat', 'beingdeleted.txt') |  | 
| 588     notfound = join('flop', 'notfound.txt') |  | 
| 589     flap = join('boo', 'flap.h') |  | 
| 590     presubmit.os.path.exists(blat).AndReturn(True) |  | 
| 591     presubmit.os.path.isdir(blat).AndReturn(False) |  | 
| 592     presubmit.os.path.exists(binary).AndReturn(True) |  | 
| 593     presubmit.os.path.isdir(binary).AndReturn(False) |  | 
| 594     presubmit.os.path.exists(beingdeleted).AndReturn(False) | 605     presubmit.os.path.exists(beingdeleted).AndReturn(False) | 
| 595     presubmit.os.path.exists(notfound).AndReturn(False) | 606     presubmit.os.path.exists(notfound).AndReturn(False) | 
| 596     presubmit.os.path.exists(flap).AndReturn(True) | 607     presubmit.os.path.exists(flap).AndReturn(True) | 
| 597     presubmit.os.path.isdir(flap).AndReturn(False) | 608     presubmit.os.path.isdir(flap).AndReturn(False) | 
| 598     presubmit.gclient.CaptureSVNInfo(beingdeleted).AndReturn({}) | 609     presubmit.gclient.CaptureSVNInfo(beingdeleted).AndReturn({}) | 
| 599     presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) | 610     presubmit.gclient.CaptureSVNInfo(notfound).AndReturn({}) | 
| 600     presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) | 611     presubmit.gcl.GetSVNFileProperty(blat, 'svn:mime-type').AndReturn(None) | 
|  | 612     presubmit.gcl.GetSVNFileProperty(readme, 'svn:mime-type').AndReturn(None) | 
| 601     presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( | 613     presubmit.gcl.GetSVNFileProperty(binary, 'svn:mime-type').AndReturn( | 
| 602         'application/octet-stream') | 614         'application/octet-stream') | 
|  | 615     presubmit.gcl.GetSVNFileProperty(weird, 'svn:mime-type').AndReturn(None) | 
|  | 616     presubmit.gcl.GetSVNFileProperty(another, 'svn:mime-type').AndReturn(None) | 
|  | 617     presubmit.gcl.GetSVNFileProperty(third_party, 'svn:mime-type' | 
|  | 618         ).AndReturn(None) | 
| 603     presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') | 619     presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') | 
|  | 620     presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2') | 
| 604     self.mox.ReplayAll() | 621     self.mox.ReplayAll() | 
| 605 | 622 | 
| 606     ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, | 623     ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, | 
| 607                                   description='\n'.join(description_lines), | 624                                   description='\n'.join(description_lines), | 
| 608                                   files=files) | 625                                   files=files) | 
| 609     change = presubmit.GclChange(ci) | 626     change = presubmit.GclChange(ci) | 
| 610     api = presubmit.InputApi(change, 'foo/PRESUBMIT.py', False) | 627     input_api = presubmit.InputApi(change, 'foo/PRESUBMIT.py', False) | 
| 611     affected_files = api.AffectedFiles() | 628     # Doesn't filter much | 
| 612     self.assertEquals(len(affected_files), 3) | 629     got_files = input_api.AffectedFiles() | 
| 613     self.assertEquals(affected_files[0].LocalPath(), | 630     self.assertEquals(len(got_files), 7) | 
| 614                       presubmit.normpath('foo/blat.cc')) | 631     self.assertEquals(got_files[0].LocalPath(), presubmit.normpath(blat)) | 
| 615     self.assertEquals(affected_files[1].LocalPath(), | 632     self.assertEquals(got_files[1].LocalPath(), presubmit.normpath(readme)) | 
| 616                       presubmit.normpath('foo/blat/binary.dll')) | 633     self.assertEquals(got_files[2].LocalPath(), presubmit.normpath(binary)) | 
| 617     self.assertEquals(affected_files[2].LocalPath(), | 634     self.assertEquals(got_files[3].LocalPath(), presubmit.normpath(weird)) | 
| 618                       presubmit.normpath('foo/mat/beingdeleted.txt')) | 635     self.assertEquals(got_files[4].LocalPath(), presubmit.normpath(another)) | 
| 619     rhs_lines = [] | 636     self.assertEquals(got_files[5].LocalPath(), presubmit.normpath(third_party)) | 
| 620     for line in api.RightHandSideLines(): | 637     self.assertEquals(got_files[6].LocalPath(), | 
| 621       rhs_lines.append(line) | 638                       presubmit.normpath(beingdeleted)) | 
| 622     self.assertEquals(len(rhs_lines), 2) | 639     # Ignores weird because of whitelist, third_party because of blacklist, | 
| 623     self.assertEqual(rhs_lines[0][0].LocalPath(), | 640     # binary isn't a text file and beingdeleted doesn't exist. The rest is | 
| 624                     presubmit.normpath('foo/blat.cc')) | 641     # outside foo/. | 
|  | 642     rhs_lines = [x for x in input_api.RightHandSideLines(None)] | 
|  | 643     self.assertEquals(len(rhs_lines), 4) | 
|  | 644     self.assertEqual(rhs_lines[0][0].LocalPath(), presubmit.normpath(blat)) | 
|  | 645     self.assertEqual(rhs_lines[1][0].LocalPath(), presubmit.normpath(blat)) | 
|  | 646     self.assertEqual(rhs_lines[2][0].LocalPath(), presubmit.normpath(another)) | 
|  | 647     self.assertEqual(rhs_lines[3][0].LocalPath(), presubmit.normpath(another)) | 
|  | 648 | 
|  | 649   def testCustomFilter(self): | 
|  | 650     def FilterSourceFile(affected_file): | 
|  | 651       return 'a' in affected_file.LocalPath() | 
|  | 652     files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')] | 
|  | 653     for (action, item) in files: | 
|  | 654       presubmit.os.path.exists(item).AndReturn(True) | 
|  | 655       presubmit.os.path.isdir(item).AndReturn(False) | 
|  | 656       presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) | 
|  | 657     self.mox.ReplayAll() | 
|  | 658 | 
|  | 659     ci = presubmit.gcl.ChangeInfo('mychange', 0, 0, '', files) | 
|  | 660     change = presubmit.GclChange(ci) | 
|  | 661     input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) | 
|  | 662     got_files = input_api.AffectedSourceFiles(FilterSourceFile) | 
|  | 663     self.assertEquals(len(got_files), 2) | 
|  | 664     self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 
|  | 665     self.assertEquals(got_files[1].LocalPath(), 'eeabee') | 
|  | 666 | 
|  | 667   def testLambdaFilter(self): | 
|  | 668     white_list = [r".*?a.*?"] | 
|  | 669     black_list = [r".*?b.*?"] | 
|  | 670     files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')] | 
|  | 671     for (action, item) in files: | 
|  | 672       presubmit.os.path.exists(item).AndReturn(True) | 
|  | 673       presubmit.os.path.isdir(item).AndReturn(False) | 
|  | 674       presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) | 
|  | 675     self.mox.ReplayAll() | 
|  | 676 | 
|  | 677     ci = presubmit.gcl.ChangeInfo('mychange', 0, 0, '', files) | 
|  | 678     change = presubmit.GclChange(ci) | 
|  | 679     input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) | 
|  | 680     # Sample usage of overiding the default white and black lists. | 
|  | 681     got_files = input_api.AffectedSourceFiles( | 
|  | 682         lambda x: input_api.FilterSourceFile(x, white_list, black_list)) | 
|  | 683     self.assertEquals(len(got_files), 2) | 
|  | 684     self.assertEquals(got_files[0].LocalPath(), 'eeaee') | 
|  | 685     self.assertEquals(got_files[1].LocalPath(), 'eecaee') | 
| 625 | 686 | 
| 626   def testGetAbsoluteLocalPath(self): | 687   def testGetAbsoluteLocalPath(self): | 
| 627     join = presubmit.os.path.join | 688     join = presubmit.os.path.join | 
| 628     normpath = presubmit.normpath | 689     normpath = presubmit.normpath | 
| 629     # Regression test for bug of presubmit stuff that relies on invoking | 690     # Regression test for bug of presubmit stuff that relies on invoking | 
| 630     # SVN (e.g. to get mime type of file) not working unless gcl invoked | 691     # SVN (e.g. to get mime type of file) not working unless gcl invoked | 
| 631     # from the client root (e.g. if you were at 'src' and did 'cd base' before | 692     # from the client root (e.g. if you were at 'src' and did 'cd base' before | 
| 632     # invoking 'gcl upload' it would fail because svn wouldn't find the files | 693     # invoking 'gcl upload' it would fail because svn wouldn't find the files | 
| 633     # the presubmit script was asking about). | 694     # the presubmit script was asking about). | 
| 634     files = [ | 695     files = [ | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 898   def TestContent(self, check, content1, content2, error_type): | 959   def TestContent(self, check, content1, content2, error_type): | 
| 899     input_api1 = self.MockInputApi() | 960     input_api1 = self.MockInputApi() | 
| 900     input_api1.change = self.MakeBasicChange('foo', 'Foo\n') | 961     input_api1.change = self.MakeBasicChange('foo', 'Foo\n') | 
| 901     affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 962     affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 
| 902     affected_file.LocalPath().AndReturn('foo.cc') | 963     affected_file.LocalPath().AndReturn('foo.cc') | 
| 903     output1 = [ | 964     output1 = [ | 
| 904       (affected_file, 42, 'yo, ' + content1), | 965       (affected_file, 42, 'yo, ' + content1), | 
| 905       (affected_file, 43, 'yer'), | 966       (affected_file, 43, 'yer'), | 
| 906       (affected_file, 23, 'ya'), | 967       (affected_file, 23, 'ya'), | 
| 907     ] | 968     ] | 
| 908     input_api1.RightHandSideLines().AndReturn(output1) | 969     input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) | 
| 909     input_api2 = self.MockInputApi() | 970     input_api2 = self.MockInputApi() | 
| 910     input_api2.change = self.MakeBasicChange('foo', 'Foo\n') | 971     input_api2.change = self.MakeBasicChange('foo', 'Foo\n') | 
| 911     output2 = [ | 972     output2 = [ | 
| 912       (affected_file, 42, 'yo, ' + content2), | 973       (affected_file, 42, 'yo, ' + content2), | 
| 913       (affected_file, 43, 'yer'), | 974       (affected_file, 43, 'yer'), | 
| 914       (affected_file, 23, 'ya'), | 975       (affected_file, 23, 'ya'), | 
| 915     ] | 976     ] | 
| 916     input_api2.RightHandSideLines().AndReturn(output2) | 977     input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2) | 
| 917     self.mox.ReplayAll() | 978     self.mox.ReplayAll() | 
| 918 | 979 | 
| 919     results1 = check(input_api1, presubmit.OutputApi) | 980     results1 = check(input_api1, presubmit.OutputApi, None) | 
| 920     self.assertEquals(results1, []) | 981     self.assertEquals(results1, []) | 
| 921     results2 = check(input_api2, presubmit.OutputApi) | 982     results2 = check(input_api2, presubmit.OutputApi, None) | 
| 922     self.assertEquals(len(results2), 1) | 983     self.assertEquals(len(results2), 1) | 
| 923     self.assertEquals(results2[0].__class__, error_type) | 984     self.assertEquals(results2[0].__class__, error_type) | 
| 924 | 985 | 
| 925   def testCannedCheckChangeHasBugField(self): | 986   def testCannedCheckChangeHasBugField(self): | 
| 926     self.TestDescription(presubmit_canned_checks.CheckChangeHasBugField, | 987     self.TestDescription(presubmit_canned_checks.CheckChangeHasBugField, | 
| 927                          'BUG=1234', '', | 988                          'BUG=1234', '', | 
| 928                          presubmit.OutputApi.PresubmitNotifyResult) | 989                          presubmit.OutputApi.PresubmitNotifyResult) | 
| 929 | 990 | 
| 930   def testCannedCheckChangeHasTestField(self): | 991   def testCannedCheckChangeHasTestField(self): | 
| 931     self.TestDescription(presubmit_canned_checks.CheckChangeHasTestField, | 992     self.TestDescription(presubmit_canned_checks.CheckChangeHasTestField, | 
| 932                          'TEST=did some stuff', '', | 993                          'TEST=did some stuff', '', | 
| 933                          presubmit.OutputApi.PresubmitNotifyResult) | 994                          presubmit.OutputApi.PresubmitNotifyResult) | 
| 934 | 995 | 
| 935   def testCannedCheckChangeHasTestedField(self): | 996   def testCannedCheckChangeHasTestedField(self): | 
| 936     self.TestDescription(presubmit_canned_checks.CheckChangeHasTestedField, | 997     self.TestDescription(presubmit_canned_checks.CheckChangeHasTestedField, | 
| 937                          'TESTED=did some stuff', '', | 998                          'TESTED=did some stuff', '', | 
| 938                          presubmit.OutputApi.PresubmitError) | 999                          presubmit.OutputApi.PresubmitError) | 
| 939 | 1000 | 
| 940   def testCannedCheckChangeHasQAField(self): | 1001   def testCannedCheckChangeHasQAField(self): | 
| 941     self.TestDescription(presubmit_canned_checks.CheckChangeHasQaField, | 1002     self.TestDescription(presubmit_canned_checks.CheckChangeHasQaField, | 
| 942                          'QA=BSOD your machine', '', | 1003                          'QA=BSOD your machine', '', | 
| 943                          presubmit.OutputApi.PresubmitError) | 1004                          presubmit.OutputApi.PresubmitError) | 
| 944 | 1005 | 
| 945   def testCannedCheckDoNotSubmitInDescription(self): | 1006   def testCannedCheckDoNotSubmitInDescription(self): | 
| 946     self.TestDescription(presubmit_canned_checks.CheckDoNotSubmitInDescription, | 1007     self.TestDescription(presubmit_canned_checks.CheckDoNotSubmitInDescription, | 
| 947                          'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1008                          'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 
| 948                          presubmit.OutputApi.PresubmitError) | 1009                          presubmit.OutputApi.PresubmitError) | 
| 949 | 1010 | 
| 950   def testCannedCheckDoNotSubmitInFiles(self): | 1011   def testCannedCheckDoNotSubmitInFiles(self): | 
| 951     self.TestContent(presubmit_canned_checks.CheckDoNotSubmitInFiles, | 1012     self.TestContent( | 
| 952                      'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1013         lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), | 
| 953                      presubmit.OutputApi.PresubmitError) | 1014         'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 
|  | 1015         presubmit.OutputApi.PresubmitError) | 
| 954 | 1016 | 
| 955   def testCheckChangeHasNoCR(self): | 1017   def testCheckChangeHasNoCR(self): | 
| 956     input_api1 = self.MockInputApi() | 1018     input_api1 = self.MockInputApi() | 
| 957     self.mox.StubOutWithMock(input_api1, 'ReadFile') | 1019     self.mox.StubOutWithMock(input_api1, 'ReadFile') | 
| 958     input_api1.change = self.MakeBasicChange('foo', 'Foo\n') | 1020     input_api1.change = self.MakeBasicChange('foo', 'Foo\n') | 
| 959     affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1021     affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 
| 960     input_api1.AffectedTextFiles().AndReturn([affected_file1]) | 1022     input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) | 
| 961     input_api1.ReadFile(affected_file1, 'rb').AndReturn("Hey!\nHo!\n") | 1023     input_api1.ReadFile(affected_file1, 'rb').AndReturn("Hey!\nHo!\n") | 
| 962     input_api2 = self.MockInputApi() | 1024     input_api2 = self.MockInputApi() | 
| 963     self.mox.StubOutWithMock(input_api2, 'ReadFile') | 1025     self.mox.StubOutWithMock(input_api2, 'ReadFile') | 
| 964     input_api2.change = self.MakeBasicChange('foo', 'Foo\n') | 1026     input_api2.change = self.MakeBasicChange('foo', 'Foo\n') | 
| 965     affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1027     affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) | 
| 966     input_api2.AffectedTextFiles().AndReturn([affected_file2]) | 1028     input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) | 
| 967     input_api2.ReadFile(affected_file2, 'rb').AndReturn("Hey!\r\nHo!\r\n") | 1029     input_api2.ReadFile(affected_file2, 'rb').AndReturn("Hey!\r\nHo!\r\n") | 
| 968     affected_file2.LocalPath().AndReturn('bar.cc') | 1030     affected_file2.LocalPath().AndReturn('bar.cc') | 
| 969     self.mox.ReplayAll() | 1031     self.mox.ReplayAll() | 
| 970 | 1032 | 
| 971     results = presubmit_canned_checks.CheckChangeHasNoCR( | 1033     results = presubmit_canned_checks.CheckChangeHasNoCR( | 
| 972         input_api1, presubmit.OutputApi) | 1034         input_api1, presubmit.OutputApi, None) | 
| 973     self.assertEquals(results, []) | 1035     self.assertEquals(results, []) | 
| 974     results2 = presubmit_canned_checks.CheckChangeHasNoCR( | 1036     results2 = presubmit_canned_checks.CheckChangeHasNoCR( | 
| 975         input_api2, presubmit.OutputApi) | 1037         input_api2, presubmit.OutputApi, None) | 
| 976     self.assertEquals(len(results2), 1) | 1038     self.assertEquals(len(results2), 1) | 
| 977     self.assertEquals(results2[0].__class__, | 1039     self.assertEquals(results2[0].__class__, | 
| 978                       presubmit.OutputApi.PresubmitPromptWarning) | 1040                       presubmit.OutputApi.PresubmitPromptWarning) | 
| 979 | 1041 | 
| 980   def testCannedCheckChangeHasNoTabs(self): | 1042   def testCannedCheckChangeHasNoTabs(self): | 
| 981     self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, | 1043     self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, | 
| 982                      'blah blah', 'blah\tblah', | 1044                      'blah blah', 'blah\tblah', | 
| 983                      presubmit.OutputApi.PresubmitPromptWarning) | 1045                      presubmit.OutputApi.PresubmitPromptWarning) | 
| 984 | 1046 | 
| 985   def testCannedCheckLongLines(self): | 1047   def testCannedCheckLongLines(self): | 
| 986     check = lambda x,y: presubmit_canned_checks.CheckLongLines(x, y, 10) | 1048     check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) | 
| 987     self.TestContent(check, '', 'blah blah blah', | 1049     self.TestContent(check, '', 'blah blah blah', | 
| 988                      presubmit.OutputApi.PresubmitPromptWarning) | 1050                      presubmit.OutputApi.PresubmitPromptWarning) | 
| 989 | 1051 | 
| 990   def testCannedCheckTreeIsOpenOpen(self): | 1052   def testCannedCheckTreeIsOpenOpen(self): | 
| 991     input_api = self.MockInputApi() | 1053     input_api = self.MockInputApi() | 
| 992     input_api.is_committing = True | 1054     input_api.is_committing = True | 
| 993     connection = self.mox.CreateMockAnything() | 1055     connection = self.mox.CreateMockAnything() | 
| 994     input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 1056     input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 
| 995     connection.read().AndReturn('1') | 1057     connection.read().AndReturn('1') | 
| 996     connection.close() | 1058     connection.close() | 
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1135     test_result.errors = 0 | 1197     test_result.errors = 0 | 
| 1136     self.mox.ReplayAll() | 1198     self.mox.ReplayAll() | 
| 1137 | 1199 | 
| 1138     results = presubmit_canned_checks.RunPythonUnitTests( | 1200     results = presubmit_canned_checks.RunPythonUnitTests( | 
| 1139         input_api, presubmit.OutputApi, ['test_module']) | 1201         input_api, presubmit.OutputApi, ['test_module']) | 
| 1140     self.assertEquals(len(results), 0) | 1202     self.assertEquals(len(results), 0) | 
| 1141 | 1203 | 
| 1142 | 1204 | 
| 1143 if __name__ == '__main__': | 1205 if __name__ == '__main__': | 
| 1144   unittest.main() | 1206   unittest.main() | 
| OLD | NEW | 
|---|