| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 patch.py.""" | 6 """Unit tests for patch.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 def testGitDelete(self): | 452 def testGitDelete(self): |
| 453 p = patch.FilePatchDiff('tools/clang_check/README.chromium', GIT_DELETE, []) | 453 p = patch.FilePatchDiff('tools/clang_check/README.chromium', GIT_DELETE, []) |
| 454 self._check_patch( | 454 self._check_patch( |
| 455 p, 'tools/clang_check/README.chromium', GIT_DELETE, is_delete=True, | 455 p, 'tools/clang_check/README.chromium', GIT_DELETE, is_delete=True, |
| 456 is_git_diff=True, patchlevel=1) | 456 is_git_diff=True, patchlevel=1) |
| 457 | 457 |
| 458 def testGitRename(self): | 458 def testGitRename(self): |
| 459 p = patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) | 459 p = patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) |
| 460 self._check_patch(p, 'tools/run_local_server.sh', GIT_RENAME, | 460 self._check_patch(p, 'tools/run_local_server.sh', GIT_RENAME, |
| 461 is_git_diff=True, patchlevel=1, | 461 is_git_diff=True, patchlevel=1, |
| 462 source_filename='tools/run_local_server.PY') | 462 source_filename='tools/run_local_server.PY', is_new=True) |
| 463 | 463 |
| 464 def testGitRenamePartial(self): | 464 def testGitRenamePartial(self): |
| 465 p = patch.FilePatchDiff( | 465 p = patch.FilePatchDiff( |
| 466 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, []) | 466 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, []) |
| 467 self._check_patch( | 467 self._check_patch( |
| 468 p, 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, | 468 p, 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, |
| 469 source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True, | 469 source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True, |
| 470 patchlevel=1) | 470 patchlevel=1, is_new=True) |
| 471 | 471 |
| 472 def testGitCopy(self): | 472 def testGitCopy(self): |
| 473 p = patch.FilePatchDiff('pp', GIT_COPY, []) | 473 p = patch.FilePatchDiff('pp', GIT_COPY, []) |
| 474 self._check_patch(p, 'pp', GIT_COPY, is_git_diff=True, patchlevel=1, | 474 self._check_patch(p, 'pp', GIT_COPY, is_git_diff=True, patchlevel=1, |
| 475 source_filename='PRESUBMIT.py') | 475 source_filename='PRESUBMIT.py', is_new=True) |
| 476 | 476 |
| 477 def testOnlyHeader(self): | 477 def testOnlyHeader(self): |
| 478 diff = '--- file_a\n+++ file_a\n' | 478 diff = '--- file_a\n+++ file_a\n' |
| 479 p = patch.FilePatchDiff('file_a', diff, []) | 479 p = patch.FilePatchDiff('file_a', diff, []) |
| 480 self._check_patch(p, 'file_a', diff) | 480 self._check_patch(p, 'file_a', diff) |
| 481 | 481 |
| 482 def testSmallest(self): | 482 def testSmallest(self): |
| 483 diff = '--- file_a\n+++ file_a\n@@ -0,0 +1 @@\n+foo\n' | 483 diff = '--- file_a\n+++ file_a\n@@ -0,0 +1 @@\n+foo\n' |
| 484 p = patch.FilePatchDiff('file_a', diff, []) | 484 p = patch.FilePatchDiff('file_a', diff, []) |
| 485 self._check_patch(p, 'file_a', diff) | 485 self._check_patch(p, 'file_a', diff) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 496 try: | 496 try: |
| 497 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', []) | 497 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', []) |
| 498 self.fail() | 498 self.fail() |
| 499 except patch.UnsupportedPatchFormat: | 499 except patch.UnsupportedPatchFormat: |
| 500 pass | 500 pass |
| 501 | 501 |
| 502 def testRenameOnlyHeader(self): | 502 def testRenameOnlyHeader(self): |
| 503 diff = '--- file_a\n+++ file_b\n' | 503 diff = '--- file_a\n+++ file_b\n' |
| 504 p = patch.FilePatchDiff('file_b', diff, []) | 504 p = patch.FilePatchDiff('file_b', diff, []) |
| 505 # Should it be marked as new? | 505 # Should it be marked as new? |
| 506 self._check_patch(p, 'file_b', diff, source_filename='file_a') | 506 self._check_patch(p, 'file_b', diff, source_filename='file_a', is_new=True) |
| 507 | 507 |
| 508 def testGitCopyPartial(self): | 508 def testGitCopyPartial(self): |
| 509 diff = ( | 509 diff = ( |
| 510 'diff --git a/wtf b/wtf2\n' | 510 'diff --git a/wtf b/wtf2\n' |
| 511 'similarity index 98%\n' | 511 'similarity index 98%\n' |
| 512 'copy from wtf\n' | 512 'copy from wtf\n' |
| 513 'copy to wtf2\n' | 513 'copy to wtf2\n' |
| 514 'index 79fbaf3..3560689 100755\n' | 514 'index 79fbaf3..3560689 100755\n' |
| 515 '--- a/wtf\n' | 515 '--- a/wtf\n' |
| 516 '+++ b/wtf2\n' | 516 '+++ b/wtf2\n' |
| 517 '@@ -1,4 +1,4 @@\n' | 517 '@@ -1,4 +1,4 @@\n' |
| 518 '-#!/usr/bin/env python\n' | 518 '-#!/usr/bin/env python\n' |
| 519 '+#!/usr/bin/env python1.3\n' | 519 '+#!/usr/bin/env python1.3\n' |
| 520 ' # Copyright (c) 2010 The Chromium Authors. All rights reserved.\n' | 520 ' # Copyright (c) 2010 The Chromium Authors. All rights reserved.\n' |
| 521 ' # blah blah blah as\n' | 521 ' # blah blah blah as\n' |
| 522 ' # found in the LICENSE file.\n') | 522 ' # found in the LICENSE file.\n') |
| 523 p = patch.FilePatchDiff('wtf2', diff, []) | 523 p = patch.FilePatchDiff('wtf2', diff, []) |
| 524 # Should it be marked as new? | 524 # Should it be marked as new? |
| 525 self._check_patch( | 525 self._check_patch( |
| 526 p, 'wtf2', diff, source_filename='wtf', is_git_diff=True, patchlevel=1) | 526 p, 'wtf2', diff, source_filename='wtf', is_git_diff=True, patchlevel=1, |
| 527 is_new=True) |
| 527 | 528 |
| 528 def testGitExe(self): | 529 def testGitExe(self): |
| 529 diff = ( | 530 diff = ( |
| 530 'diff --git a/natsort_test.py b/natsort_test.py\n' | 531 'diff --git a/natsort_test.py b/natsort_test.py\n' |
| 531 'new file mode 100755\n' | 532 'new file mode 100755\n' |
| 532 '--- /dev/null\n' | 533 '--- /dev/null\n' |
| 533 '+++ b/natsort_test.py\n' | 534 '+++ b/natsort_test.py\n' |
| 534 '@@ -0,0 +1,1 @@\n' | 535 '@@ -0,0 +1,1 @@\n' |
| 535 '+#!/usr/bin/env python\n') | 536 '+#!/usr/bin/env python\n') |
| 536 p = patch.FilePatchDiff('natsort_test.py', diff, []) | 537 p = patch.FilePatchDiff('natsort_test.py', diff, []) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 549 p = patch.FilePatchDiff('natsort_test.py', diff, []) | 550 p = patch.FilePatchDiff('natsort_test.py', diff, []) |
| 550 self._check_patch( | 551 self._check_patch( |
| 551 p, 'natsort_test.py', diff, is_new=True, is_git_diff=True, patchlevel=1) | 552 p, 'natsort_test.py', diff, is_new=True, is_git_diff=True, patchlevel=1) |
| 552 | 553 |
| 553 | 554 |
| 554 if __name__ == '__main__': | 555 if __name__ == '__main__': |
| 555 logging.basicConfig(level= | 556 logging.basicConfig(level= |
| 556 [logging.WARNING, logging.INFO, logging.DEBUG][ | 557 [logging.WARNING, logging.INFO, logging.DEBUG][ |
| 557 min(2, sys.argv.count('-v'))]) | 558 min(2, sys.argv.count('-v'))]) |
| 558 unittest.main() | 559 unittest.main() |
| OLD | NEW |