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

Side by Side Diff: tests/patch_test.py

Issue 6792028: Move patch.py and rietveld.py from commit-queue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fixed remaining issues Created 9 years, 8 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """Unit tests for patch.py."""
7
8 import os
9 import sys
10 import unittest
11
12 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
13 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
14
15 import patch
16
17
18 class PatchTest(unittest.TestCase):
19 def testFilePatchDelete(self):
20 c = patch.FilePatchDelete('foo', False)
21 self.assertEquals(c.is_delete, True)
22 self.assertEquals(c.is_binary, False)
23 self.assertEquals(c.filename, 'foo')
24 try:
25 c.get()
26 self.fail()
27 except NotImplementedError:
28 pass
29 c = patch.FilePatchDelete('foo', True)
30 self.assertEquals(c.is_delete, True)
31 self.assertEquals(c.is_binary, True)
32 self.assertEquals(c.filename, 'foo')
33 try:
34 c.get()
35 self.fail()
36 except NotImplementedError:
37 pass
38
39 def testFilePatchBinary(self):
40 c = patch.FilePatchBinary('foo', 'data', [])
41 self.assertEquals(c.is_delete, False)
42 self.assertEquals(c.is_binary, True)
43 self.assertEquals(c.filename, 'foo')
44 self.assertEquals(c.get(), 'data')
45
46 def testFilePatchDiff(self):
47 c = patch.FilePatchDiff('foo', 'data', [])
48 self.assertEquals(c.is_delete, False)
49 self.assertEquals(c.is_binary, False)
50 self.assertEquals(c.filename, 'foo')
51 self.assertEquals(c.is_git_diff, False)
52 self.assertEquals(c.patchlevel, 0)
53 self.assertEquals(c.get(), 'data')
54 diff = (
55 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
56 'old mode 100644\n'
57 'new mode 100755\n')
58 c = patch.FilePatchDiff('git_cl/git-cl', diff, [])
59 self.assertEquals(c.is_delete, False)
60 self.assertEquals(c.is_binary, False)
61 self.assertEquals(c.filename, 'git_cl/git-cl')
62 self.assertEquals(c.is_git_diff, True)
63 self.assertEquals(c.patchlevel, 1)
64 self.assertEquals(c.get(), diff)
65 diff = (
66 'Index: Junk\n'
67 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
68 'old mode 100644\n'
69 'new mode 100755\n')
70 c = patch.FilePatchDiff('git_cl/git-cl', diff, [])
71 self.assertEquals(c.is_delete, False)
72 self.assertEquals(c.is_binary, False)
73 self.assertEquals(c.filename, 'git_cl/git-cl')
74 self.assertEquals(c.is_git_diff, True)
75 self.assertEquals(c.patchlevel, 1)
76 self.assertEquals(c.get(), diff)
77
78 def testInvalidFilePatchDiffGit(self):
79 try:
80 patch.FilePatchDiff('svn_utils_test.txt', (
81 'diff --git a/tests/svn_utils_test_data/svn_utils_test.txt '
82 'b/tests/svn_utils_test_data/svn_utils_test.txt\n'
83 'index 0e4de76..8320059 100644\n'
84 '--- a/svn_utils_test.txt\n'
85 '+++ b/svn_utils_test.txt\n'
86 '@@ -3,6 +3,7 @@ bb\n'
87 'ccc\n'
88 'dd\n'
89 'e\n'
90 '+FOO!\n'
91 'ff\n'
92 'ggg\n'
93 'hh\n'),
94 [])
95 self.fail()
96 except patch.UnsupportedPatchFormat:
97 pass
98 try:
99 patch.FilePatchDiff('svn_utils_test2.txt', (
100 'diff --git a/svn_utils_test_data/svn_utils_test.txt '
101 'b/svn_utils_test.txt\n'
102 'index 0e4de76..8320059 100644\n'
103 '--- a/svn_utils_test.txt\n'
104 '+++ b/svn_utils_test.txt\n'
105 '@@ -3,6 +3,7 @@ bb\n'
106 'ccc\n'
107 'dd\n'
108 'e\n'
109 '+FOO!\n'
110 'ff\n'
111 'ggg\n'
112 'hh\n'),
113 [])
114 self.fail()
115 except patch.UnsupportedPatchFormat:
116 pass
117
118 def testInvalidFilePatchDiffSvn(self):
119 try:
120 patch.FilePatchDiff('svn_utils_test.txt', (
121 '--- svn_utils_test.txt2\n'
122 '+++ svn_utils_test.txt\n'
123 '@@ -3,6 +3,7 @@ bb\n'
124 'ccc\n'
125 'dd\n'
126 'e\n'
127 '+FOO!\n'
128 'ff\n'
129 'ggg\n'
130 'hh\n'),
131 [])
132 self.fail()
133 except patch.UnsupportedPatchFormat:
134 pass
135
136 def testValidSvn(self):
137 # pylint: disable=R0201
138 # Method could be a function
139 # Should not throw.
140 patch.FilePatchDiff('chrome/file.cc', (
141 'Index: chrome/file.cc\n'
142 '===================================================================\n'
143 '--- chrome/file.cc\t(revision 74690)\n'
144 '+++ chrome/file.cc\t(working copy)\n'
145 '@@ -80,10 +80,13 @@\n'
146 ' // Foo\n'
147 ' // Bar\n'
148 ' void foo() {\n'
149 '- return bar;\n'
150 '+ return foo;\n'
151 ' }\n'
152 ' \n'
153 ' \n'), [])
154 patch.FilePatchDiff('chrome/file.cc', (
155 '--- /dev/null\t2\n'
156 '+++ chrome/file.cc\tfoo\n'), [])
157 patch.FilePatchDiff('chrome/file.cc', (
158 '--- chrome/file.cc\tbar\n'
159 '+++ /dev/null\tfoo\n'), [])
160
161
162 if __name__ == '__main__':
163 unittest.main()
OLDNEW
« tests/local_rietveld.py ('K') | « tests/local_rietveld.py ('k') | tests/rietveld_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698