| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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() |
| OLD | NEW |