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 14 matching lines...) Expand all Loading... |
25 filename, | 25 filename, |
26 diff, | 26 diff, |
27 source_filename=None, | 27 source_filename=None, |
28 is_binary=False, | 28 is_binary=False, |
29 is_delete=False, | 29 is_delete=False, |
30 is_git_diff=False, | 30 is_git_diff=False, |
31 is_new=False, | 31 is_new=False, |
32 patchlevel=0, | 32 patchlevel=0, |
33 svn_properties=None, | 33 svn_properties=None, |
34 nb_hunks=None): | 34 nb_hunks=None): |
35 svn_properties = svn_properties or [] | |
36 self.assertEquals(p.filename, filename) | 35 self.assertEquals(p.filename, filename) |
37 self.assertEquals(p.source_filename, source_filename) | 36 self.assertEquals(p.source_filename, source_filename) |
38 self.assertEquals(p.is_binary, is_binary) | 37 self.assertEquals(p.is_binary, is_binary) |
39 self.assertEquals(p.is_delete, is_delete) | 38 self.assertEquals(p.is_delete, is_delete) |
40 if hasattr(p, 'is_git_diff'): | 39 if hasattr(p, 'is_git_diff'): |
41 self.assertEquals(p.is_git_diff, is_git_diff) | 40 self.assertEquals(p.is_git_diff, is_git_diff) |
42 self.assertEquals(p.is_new, is_new) | 41 self.assertEquals(p.is_new, is_new) |
43 if hasattr(p, 'patchlevel'): | 42 if hasattr(p, 'patchlevel'): |
44 self.assertEquals(p.patchlevel, patchlevel) | 43 self.assertEquals(p.patchlevel, patchlevel) |
45 if diff: | 44 if diff: |
46 if is_binary: | 45 if is_binary: |
47 self.assertEquals(p.get(), diff) | 46 self.assertEquals(p.get(), diff) |
48 else: | 47 else: |
49 self.assertEquals(p.get(True), diff) | 48 self.assertEquals(p.get(True), diff) |
50 if hasattr(p, 'hunks'): | 49 if hasattr(p, 'hunks'): |
51 self.assertEquals(len(p.hunks), nb_hunks) | 50 self.assertEquals(len(p.hunks), nb_hunks) |
52 else: | 51 else: |
53 self.assertEquals(None, nb_hunks) | 52 self.assertEquals(None, nb_hunks) |
| 53 if hasattr(p, 'svn_properties'): |
| 54 self.assertEquals(p.svn_properties, svn_properties or []) |
54 | 55 |
55 def testFilePatchDelete(self): | 56 def testFilePatchDelete(self): |
56 p = patch.FilePatchDelete('foo', False) | 57 p = patch.FilePatchDelete('foo', False) |
57 self._check_patch(p, 'foo', None, is_delete=True) | 58 self._check_patch(p, 'foo', None, is_delete=True) |
58 | 59 |
59 def testFilePatchDeleteBin(self): | 60 def testFilePatchDeleteBin(self): |
60 p = patch.FilePatchDelete('foo', True) | 61 p = patch.FilePatchDelete('foo', True) |
61 self._check_patch(p, 'foo', None, is_delete=True, is_binary=True) | 62 self._check_patch(p, 'foo', None, is_delete=True, is_binary=True) |
62 | 63 |
63 def testFilePatchBinary(self): | 64 def testFilePatchBinary(self): |
(...skipping 18 matching lines...) Expand all Loading... |
82 self._check_patch( | 83 self._check_patch( |
83 p, 'git_cl/git-cl', GIT.MODE_EXE, is_git_diff=True, patchlevel=1, | 84 p, 'git_cl/git-cl', GIT.MODE_EXE, is_git_diff=True, patchlevel=1, |
84 svn_properties=[('svn:executable', '*')], nb_hunks=0) | 85 svn_properties=[('svn:executable', '*')], nb_hunks=0) |
85 | 86 |
86 def testFilePatchDiffHeaderModeIndex(self): | 87 def testFilePatchDiffHeaderModeIndex(self): |
87 p = patch.FilePatchDiff('git_cl/git-cl', GIT.MODE_EXE_JUNK, []) | 88 p = patch.FilePatchDiff('git_cl/git-cl', GIT.MODE_EXE_JUNK, []) |
88 self._check_patch( | 89 self._check_patch( |
89 p, 'git_cl/git-cl', GIT.MODE_EXE_JUNK, is_git_diff=True, patchlevel=1, | 90 p, 'git_cl/git-cl', GIT.MODE_EXE_JUNK, is_git_diff=True, patchlevel=1, |
90 svn_properties=[('svn:executable', '*')], nb_hunks=0) | 91 svn_properties=[('svn:executable', '*')], nb_hunks=0) |
91 | 92 |
| 93 def testFilePatchDiffHeaderNotExecutable(self): |
| 94 p = patch.FilePatchDiff( |
| 95 'build/android/ant/create.js', GIT.NEW_NOT_EXECUTABLE, []) |
| 96 self._check_patch( |
| 97 p, 'build/android/ant/create.js', GIT.NEW_NOT_EXECUTABLE, |
| 98 is_git_diff=True, patchlevel=1, is_new=True, |
| 99 nb_hunks=1) |
| 100 |
92 def testFilePatchDiffSvnNew(self): | 101 def testFilePatchDiffSvnNew(self): |
93 # The code path is different for git and svn. | 102 # The code path is different for git and svn. |
94 p = patch.FilePatchDiff('foo', RAW.NEW, []) | 103 p = patch.FilePatchDiff('foo', RAW.NEW, []) |
95 self._check_patch(p, 'foo', RAW.NEW, is_new=True, nb_hunks=1) | 104 self._check_patch(p, 'foo', RAW.NEW, is_new=True, nb_hunks=1) |
96 | 105 |
97 def testFilePatchDiffGitNew(self): | 106 def testFilePatchDiffGitNew(self): |
98 # The code path is different for git and svn. | 107 # The code path is different for git and svn. |
99 p = patch.FilePatchDiff('foo', GIT.NEW, []) | 108 p = patch.FilePatchDiff('foo', GIT.NEW, []) |
100 self._check_patch( | 109 self._check_patch( |
101 p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1, | 110 p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1, |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 self.fail() | 547 self.fail() |
539 except patch.UnsupportedPatchFormat: | 548 except patch.UnsupportedPatchFormat: |
540 pass | 549 pass |
541 | 550 |
542 | 551 |
543 if __name__ == '__main__': | 552 if __name__ == '__main__': |
544 logging.basicConfig(level= | 553 logging.basicConfig(level= |
545 [logging.WARNING, logging.INFO, logging.DEBUG][ | 554 [logging.WARNING, logging.INFO, logging.DEBUG][ |
546 min(2, sys.argv.count('-v'))]) | 555 min(2, sys.argv.count('-v'))]) |
547 unittest.main() | 556 unittest.main() |
OLD | NEW |