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

Side by Side Diff: tests/patch_test.py

Issue 10894036: Fix hunk handling for 'default hunk header values'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Add verification code for the number of commas Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « testing_support/patches_data.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/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unit tests for patch.py.""" 7 """Unit tests for patch.py."""
8 8
9 import logging 9 import logging
10 import os 10 import os
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 'tools/run_local_server.sh', 353 'tools/run_local_server.sh',
354 'bar', 354 'bar',
355 'chrome/file.cc', 355 'chrome/file.cc',
356 'foo', 356 'foo',
357 'other/place/foo', 357 'other/place/foo',
358 'tools/clang_check/README.chromium', 358 'tools/clang_check/README.chromium',
359 ] 359 ]
360 patchset = patch.PatchSet(patches) 360 patchset = patch.PatchSet(patches)
361 self.assertEquals(expected, patchset.filenames) 361 self.assertEquals(expected, patchset.filenames)
362 362
363 def testGitPatch(self):
364 p = patch.FilePatchDiff('chrome/file.cc', GIT.PATCH, [])
365 self._check_patch(
366 p, 'chrome/file.cc', GIT.PATCH, is_git_diff=True, patchlevel=1,
367 nb_hunks=1)
368
369 def testGitPatchShortHunkHeader(self):
370 p = patch.FilePatchDiff(
371 'chrome/browser/api/OWNERS', GIT.PATCH_SHORT_HUNK_HEADER, [])
372 self._check_patch(
373 p, 'chrome/browser/api/OWNERS', GIT.PATCH_SHORT_HUNK_HEADER,
374 is_git_diff=True, patchlevel=1, nb_hunks=1)
375
363 376
364 class PatchTestFail(unittest.TestCase): 377 class PatchTestFail(unittest.TestCase):
365 # All patches that should throw. 378 # All patches that should throw.
366 def testFilePatchDelete(self): 379 def testFilePatchDelete(self):
367 self.assertFalse(hasattr(patch.FilePatchDelete('foo', False), 'get')) 380 self.assertFalse(hasattr(patch.FilePatchDelete('foo', False), 'get'))
368 381
369 def testFilePatchDeleteBin(self): 382 def testFilePatchDeleteBin(self):
370 self.assertFalse(hasattr(patch.FilePatchDelete('foo', True), 'get')) 383 self.assertFalse(hasattr(patch.FilePatchDelete('foo', True), 'get'))
371 384
372 def testFilePatchDiffBad(self): 385 def testFilePatchDiffBad(self):
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 except patch.UnsupportedPatchFormat: 519 except patch.UnsupportedPatchFormat:
507 pass 520 pass
508 521
509 def testInvertedOnlyHeader(self): 522 def testInvertedOnlyHeader(self):
510 try: 523 try:
511 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', []) 524 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', [])
512 self.fail() 525 self.fail()
513 except patch.UnsupportedPatchFormat: 526 except patch.UnsupportedPatchFormat:
514 pass 527 pass
515 528
529 def testBadHunkCommas(self):
530 try:
531 patch.FilePatchDiff(
532 'file_a',
533 '--- file_a\n'
534 '+++ file_a\n'
535 '@@ -0,,0 +1 @@\n'
536 '+foo\n',
537 [])
538 self.fail()
539 except patch.UnsupportedPatchFormat:
540 pass
541
516 542
517 if __name__ == '__main__': 543 if __name__ == '__main__':
518 logging.basicConfig(level= 544 logging.basicConfig(level=
519 [logging.WARNING, logging.INFO, logging.DEBUG][ 545 [logging.WARNING, logging.INFO, logging.DEBUG][
520 min(2, sys.argv.count('-v'))]) 546 min(2, sys.argv.count('-v'))])
521 unittest.main() 547 unittest.main()
OLDNEW
« no previous file with comments | « testing_support/patches_data.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698