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

Side by Side Diff: tests/presubmit_unittest.py

Issue 122016: Melting pot of changes. (Closed)
Patch Set: 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 {'URL': 'svn:/foo/boo/flap.h'}) 203 {'URL': 'svn:/foo/boo/flap.h'})
204 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') 204 presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?')
205 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') 205 presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?')
206 self.mox.ReplayAll() 206 self.mox.ReplayAll()
207 207
208 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0, 208 ci = presubmit.gcl.ChangeInfo(name='mychange', issue=0, patchset=0,
209 description='\n'.join(description_lines), 209 description='\n'.join(description_lines),
210 files=files) 210 files=files)
211 change = presubmit.GclChange(ci) 211 change = presubmit.GclChange(ci)
212 212
213 self.failUnless(change.Change() == 'mychange') 213 self.failUnless(change.Name() == 'mychange')
214 self.failUnless(change.DescriptionText() == 214 self.failUnless(change.DescriptionText() ==
215 'Hello there\nthis is a change\nand some more regular text') 215 'Hello there\nthis is a change\nand some more regular text')
216 self.failUnless(change.FullDescriptionText() == 216 self.failUnless(change.FullDescriptionText() ==
217 '\n'.join(description_lines)) 217 '\n'.join(description_lines))
218 218
219 self.failUnless(change.BUG == '123') 219 self.failUnless(change.BUG == '123')
220 self.failUnless(change.STORY == 'http://foo/') 220 self.failUnless(change.STORY == 'http://foo/')
221 221
222 self.failUnless(len(change.AffectedFiles()) == 4) 222 self.failUnless(len(change.AffectedFiles()) == 4)
223 self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5) 223 self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5)
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 affected_files = change.AffectedFiles(include_dirs=False) 475 affected_files = change.AffectedFiles(include_dirs=False)
476 self.failUnless(len(affected_files) == 1) 476 self.failUnless(len(affected_files) == 1)
477 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) 477 self.failUnless(affected_files[0].LocalPath().endswith('blat.cc'))
478 affected_files_and_dirs = change.AffectedFiles(include_dirs=True) 478 affected_files_and_dirs = change.AffectedFiles(include_dirs=True)
479 self.failUnless(len(affected_files_and_dirs) == 2) 479 self.failUnless(len(affected_files_and_dirs) == 2)
480 480
481 def testTags(self): 481 def testTags(self):
482 DEFAULT_SCRIPT = """ 482 DEFAULT_SCRIPT = """
483 def CheckChangeOnUpload(input_api, output_api): 483 def CheckChangeOnUpload(input_api, output_api):
484 if input_api.change.tags['BUG'] != 'boo': 484 if input_api.change.tags['BUG'] != 'boo':
485 return [output_api.PresubmitError('Tag parsing failed. 1')] 485 return [output_api.PresubmitError('Tag parsing failed. 1')]
486 if input_api.change.tags['STORY'] != 'http://tracker.com/42': 486 if input_api.change.tags['STORY'] != 'http://tracker.com/42':
487 return [output_api.PresubmitError('Tag parsing failed. 2')] 487 return [output_api.PresubmitError('Tag parsing failed. 2')]
488 if input_api.change.BUG != 'boo': 488 if input_api.change.BUG != 'boo':
489 return [output_api.PresubmitError('Tag parsing failed. 6')] 489 return [output_api.PresubmitError('Tag parsing failed. 6')]
490 if input_api.change.STORY != 'http://tracker.com/42': 490 if input_api.change.STORY != 'http://tracker.com/42':
491 return [output_api.PresubmitError('Tag parsing failed. 7')] 491 return [output_api.PresubmitError('Tag parsing failed. 7')]
492 if 'TEST' in input_api.change.tags: 492 try:
493 return [output_api.PresubmitError('Tag parsing failed. 3')] 493 y = False
494 if input_api.change.DescriptionText() != 'Blah Blah': 494 x = input_api.change.invalid
495 return [output_api.PresubmitError('Tag parsing failed. 4 ' + 495 except AttributeError:
496 input_api.change.DescriptionText())] 496 y = True
497 if (input_api.change.FullDescriptionText() != 497 if not y:
498 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): 498 return [output_api.PresubmitError('Tag parsing failed. 8')]
499 return [output_api.PresubmitError('Tag parsing failed. 5 ' + 499 if 'TEST' in input_api.change.tags:
500 input_api.change.FullDescriptionText())] 500 return [output_api.PresubmitError('Tag parsing failed. 3')]
501 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] 501 if input_api.change.DescriptionText() != 'Blah Blah':
502 return [output_api.PresubmitError('Tag parsing failed. 4 ' +
503 input_api.change.DescriptionText())]
504 if (input_api.change.FullDescriptionText() !=
505 'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'):
506 return [output_api.PresubmitError('Tag parsing failed. 5 ' +
507 input_api.change.FullDescriptionText())]
508 return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])]
502 def CheckChangeOnCommit(input_api, output_api): 509 def CheckChangeOnCommit(input_api, output_api):
503 raise Exception("Test error") 510 raise Exception("Test error")
504 """ 511 """
505 self.mox.ReplayAll() 512 self.mox.ReplayAll()
506 513
507 change = presubmit.gcl.ChangeInfo( 514 change = presubmit.gcl.ChangeInfo(
508 name='foo', 515 name='foo',
509 issue=0, 516 issue=0,
510 patchset=0, 517 patchset=0,
511 description="Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", 518 description="Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 907
901 output = filter(lambda x: x.IsTextFile(), list) 908 output = filter(lambda x: x.IsTextFile(), list)
902 self.failUnless(len(output) == 1) 909 self.failUnless(len(output) == 1)
903 self.failUnless(list[0] == output[0]) 910 self.failUnless(list[0] == output[0])
904 911
905 912
906 class GclChangeUnittest(PresubmitTestsBase): 913 class GclChangeUnittest(PresubmitTestsBase):
907 def testMembersChanged(self): 914 def testMembersChanged(self):
908 self.mox.ReplayAll() 915 self.mox.ReplayAll()
909 members = [ 916 members = [
910 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'Change', 917 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
911 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 918 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
912 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 919 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
913 'issue', 'patchset', 'tags', 920 'issue', 'patchset', 'tags',
914 ] 921 ]
915 # If this test fails, you should add the relevant test. 922 # If this test fails, you should add the relevant test.
916 ci = presubmit.gcl.ChangeInfo('', 0, 0, '', None) 923 ci = presubmit.gcl.ChangeInfo('', 0, 0, '', None)
917 self.compareMembers(presubmit.GclChange(ci, self.fake_root_dir), members) 924 self.compareMembers(presubmit.GclChange(ci, self.fake_root_dir), members)
918 925
919 926
920 class CannedChecksUnittest(PresubmitTestsBase): 927 class CannedChecksUnittest(PresubmitTestsBase):
921 """Tests presubmit_canned_checks.py.""" 928 """Tests presubmit_canned_checks.py."""
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 test_result.errors = 0 1314 test_result.errors = 0
1308 self.mox.ReplayAll() 1315 self.mox.ReplayAll()
1309 1316
1310 results = presubmit_canned_checks.RunPythonUnitTests( 1317 results = presubmit_canned_checks.RunPythonUnitTests(
1311 input_api, presubmit.OutputApi, ['test_module']) 1318 input_api, presubmit.OutputApi, ['test_module'])
1312 self.assertEquals(len(results), 0) 1319 self.assertEquals(len(results), 0)
1313 1320
1314 1321
1315 if __name__ == '__main__': 1322 if __name__ == '__main__':
1316 unittest.main() 1323 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