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

Side by Side Diff: tests/patch_test.py

Issue 7847021: Move sample patches to its own file so it can be reused by rietveld_test.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 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 | « no previous file | tests/patches_data.py » ('j') | 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 # 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
11 import unittest 11 import unittest
12 12
13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
14 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) 14 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
15 15
16 import patch 16 import patch
17 17 from tests.patches_data import GIT, RAW
18
19 SVN_PATCH = (
20 'Index: chrome/file.cc\n'
21 '===================================================================\n'
22 '--- chrome/file.cc\t(revision 74690)\n'
23 '+++ chrome/file.cc\t(working copy)\n'
24 '@@ -80,10 +80,13 @@\n'
25 ' // Foo\n'
26 ' // Bar\n'
27 ' void foo() {\n'
28 '- return bar;\n'
29 '+ return foo;\n'
30 ' }\n'
31 ' \n'
32 ' \n')
33
34
35 GIT_PATCH = (
36 'diff --git a/chrome/file.cc b/chrome/file.cc\n'
37 'index 0e4de76..8320059 100644\n'
38 '--- a/chrome/file.cc\n'
39 '+++ b/chrome/file.cc\n'
40 '@@ -3,6 +3,7 @@ bb\n'
41 ' ccc\n'
42 ' dd\n'
43 ' e\n'
44 '+FOO!\n'
45 ' ff\n'
46 ' ggg\n'
47 ' hh\n')
48
49
50 # http://codereview.chromium.org/download/issue6368055_22_29.diff
51 GIT_DELETE = (
52 'Index: tools/clang_check/README.chromium\n'
53 'diff --git a/tools/clang_check/README.chromium '
54 'b/tools/clang_check/README.chromium\n'
55 'deleted file mode 100644\n'
56 'index fcaa7e0e94bb604a026c4f478fecb1c5796f5413..'
57 '0000000000000000000000000000000000000000\n'
58 '--- a/tools/clang_check/README.chromium\n'
59 '+++ /dev/null\n'
60 '@@ -1,9 +0,0 @@\n'
61 '-These are terrible, terrible hacks.\n'
62 '-\n'
63 '-They are meant to be temporary. clang currently doesn\'t allow running a '
64 'plugin\n'
65 '-AND doing the normal codegen process. We want our syntax complaining '
66 'plugins to\n'
67 '-run during normal compile, but for now, you can user run_plugin.sh to '
68 'hack the\n'
69 '-build system to do a syntax check.\n'
70 '-\n'
71 '-Also see http://code.google.com/p/chromium/wiki/WritingClangPlugins\n'
72 '-\n')
73
74
75 # http://codereview.chromium.org/download/issue6250123_3013_6010.diff
76 GIT_RENAME_PARTIAL = (
77 'Index: chromeos/views/webui_menu_widget.h\n'
78 'diff --git a/chromeos/views/DOMui_menu_widget.h '
79 'b/chromeos/views/webui_menu_widget.h\n'
80 'similarity index 79%\n'
81 'rename from chromeos/views/DOMui_menu_widget.h\n'
82 'rename to chromeos/views/webui_menu_widget.h\n'
83 'index 095d4c474fd9718f5aebfa41a1ccb2d951356d41..'
84 '157925075434b590e8acaaf605a64f24978ba08b 100644\n'
85 '--- a/chromeos/views/DOMui_menu_widget.h\n'
86 '+++ b/chromeos/views/webui_menu_widget.h\n'
87 '@@ -1,9 +1,9 @@\n'
88 '-// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n'
89 '+// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n'
90 ' // Use of this source code is governed by a BSD-style license that can be'
91 '\n'
92 ' // found in the LICENSE file.\n'
93 ' \n'
94 '-#ifndef CHROME_BROWSER_CHROMEOS_VIEWS_DOMUI_MENU_WIDGET_H_\n'
95 '-#define CHROME_BROWSER_CHROMEOS_VIEWS_DOMUI_MENU_WIDGET_H_\n'
96 '+#ifndef CHROME_BROWSER_CHROMEOS_VIEWS_WEBUI_MENU_WIDGET_H_\n'
97 '+#define CHROME_BROWSER_CHROMEOS_VIEWS_WEBUI_MENU_WIDGET_H_\n'
98 ' #pragma once\n'
99 ' \n'
100 ' #include <string>\n')
101
102
103 # http://codereview.chromium.org/download/issue6287022_3001_4010.diff
104 GIT_RENAME = (
105 'Index: tools/run_local_server.sh\n'
106 'diff --git a/tools/run_local_server.PY b/tools/run_local_server.sh\n'
107 'similarity index 100%\n'
108 'rename from tools/run_local_server.PY\n'
109 'rename to tools/run_local_server.sh\n')
110
111
112 GIT_COPY = (
113 'diff --git a/PRESUBMIT.py b/pp\n'
114 'similarity index 100%\n'
115 'copy from PRESUBMIT.py\n'
116 'copy to pp\n')
117
118
119 GIT_NEW = (
120 'diff --git a/foo b/foo\n'
121 'new file mode 100644\n'
122 'index 0000000..5716ca5\n'
123 '--- /dev/null\n'
124 '+++ b/foo\n'
125 '@@ -0,0 +1 @@\n'
126 '+bar\n')
127
128
129 NEW = (
130 '--- /dev/null\n'
131 '+++ foo\n'
132 '@@ -0,0 +1 @@\n'
133 '+bar\n')
134
135
136 DELETE = (
137 '--- tools/clang_check/README.chromium\n'
138 '+++ /dev/null\n'
139 '@@ -1,1 +0,0 @@\n'
140 '-bar\n')
141 18
142 19
143 class PatchTest(unittest.TestCase): 20 class PatchTest(unittest.TestCase):
144 def _check_patch(self, 21 def _check_patch(self,
145 p, 22 p,
146 filename, 23 filename,
147 diff, 24 diff,
148 source_filename=None, 25 source_filename=None,
149 is_binary=False, 26 is_binary=False,
150 is_delete=False, 27 is_delete=False,
(...skipping 26 matching lines...) Expand all
177 54
178 def testFilePatchBinary(self): 55 def testFilePatchBinary(self):
179 p = patch.FilePatchBinary('foo', 'data', [], is_new=False) 56 p = patch.FilePatchBinary('foo', 'data', [], is_new=False)
180 self._check_patch(p, 'foo', 'data', is_binary=True) 57 self._check_patch(p, 'foo', 'data', is_binary=True)
181 58
182 def testFilePatchBinaryNew(self): 59 def testFilePatchBinaryNew(self):
183 p = patch.FilePatchBinary('foo', 'data', [], is_new=True) 60 p = patch.FilePatchBinary('foo', 'data', [], is_new=True)
184 self._check_patch(p, 'foo', 'data', is_binary=True, is_new=True) 61 self._check_patch(p, 'foo', 'data', is_binary=True, is_new=True)
185 62
186 def testFilePatchDiff(self): 63 def testFilePatchDiff(self):
187 p = patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []) 64 p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, [])
188 self._check_patch(p, 'chrome/file.cc', SVN_PATCH) 65 self._check_patch(p, 'chrome/file.cc', RAW.PATCH)
189 66
190 def testFilePatchDiffHeaderMode(self): 67 def testFilePatchDiffHeaderMode(self):
191 diff = ( 68 p = patch.FilePatchDiff('git_cl/git-cl', GIT.MODE_EXE, [])
192 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
193 'old mode 100644\n'
194 'new mode 100755\n')
195 p = patch.FilePatchDiff('git_cl/git-cl', diff, [])
196 self._check_patch( 69 self._check_patch(
197 p, 'git_cl/git-cl', diff, is_git_diff=True, patchlevel=1, 70 p, 'git_cl/git-cl', GIT.MODE_EXE, is_git_diff=True, patchlevel=1,
198 svn_properties=[('svn:executable', '*')]) 71 svn_properties=[('svn:executable', '*')])
199 72
200 def testFilePatchDiffHeaderModeIndex(self): 73 def testFilePatchDiffHeaderModeIndex(self):
201 diff = ( 74 p = patch.FilePatchDiff('git_cl/git-cl', GIT.MODE_EXE_JUNK, [])
202 'Index: Junk\n'
203 'diff --git a/git_cl/git-cl b/git_cl/git-cl\n'
204 'old mode 100644\n'
205 'new mode 100755\n')
206 p = patch.FilePatchDiff('git_cl/git-cl', diff, [])
207 self._check_patch( 75 self._check_patch(
208 p, 'git_cl/git-cl', diff, is_git_diff=True, patchlevel=1, 76 p, 'git_cl/git-cl', GIT.MODE_EXE_JUNK, is_git_diff=True, patchlevel=1,
209 svn_properties=[('svn:executable', '*')]) 77 svn_properties=[('svn:executable', '*')])
210 78
211 def testFilePatchDiffSvnNew(self): 79 def testFilePatchDiffSvnNew(self):
212 # The code path is different for git and svn. 80 # The code path is different for git and svn.
213 p = patch.FilePatchDiff('foo', NEW, []) 81 p = patch.FilePatchDiff('foo', RAW.NEW, [])
214 self._check_patch(p, 'foo', NEW, is_new=True) 82 self._check_patch(p, 'foo', RAW.NEW, is_new=True)
215 83
216 def testFilePatchDiffGitNew(self): 84 def testFilePatchDiffGitNew(self):
217 # The code path is different for git and svn. 85 # The code path is different for git and svn.
218 p = patch.FilePatchDiff('foo', GIT_NEW, []) 86 p = patch.FilePatchDiff('foo', GIT.NEW, [])
219 self._check_patch( 87 self._check_patch(
220 p, 'foo', GIT_NEW, is_new=True, is_git_diff=True, patchlevel=1) 88 p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1)
221 89
222 def testValidSvn(self): 90 def testValidSvn(self):
223 # pylint: disable=R0201 91 # pylint: disable=R0201
224 # Method could be a function 92 # Method could be a function
225 # Should not throw. 93 # Should not throw.
226 p = patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []) 94 p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, [])
227 lines = SVN_PATCH.splitlines(True) 95 lines = RAW.PATCH.splitlines(True)
228 header = ''.join(lines[:4]) 96 header = ''.join(lines[:4])
229 hunks = ''.join(lines[4:]) 97 hunks = ''.join(lines[4:])
230 self.assertEquals(header, p.diff_header) 98 self.assertEquals(header, p.diff_header)
231 self.assertEquals(hunks, p.diff_hunks) 99 self.assertEquals(hunks, p.diff_hunks)
232 self.assertEquals(SVN_PATCH, p.get()) 100 self.assertEquals(RAW.PATCH, p.get())
233 101
234 def testValidSvnNew(self): 102 def testValidSvnNew(self):
235 text = '--- /dev/null\t2\n+++ chrome/file.cc\tfoo\n' 103 p = patch.FilePatchDiff('chrome/file.cc', RAW.MINIMAL_NEW, [])
236 p = patch.FilePatchDiff('chrome/file.cc', text, []) 104 self.assertEquals(RAW.MINIMAL_NEW, p.diff_header)
237 self.assertEquals(text, p.diff_header)
238 self.assertEquals('', p.diff_hunks) 105 self.assertEquals('', p.diff_hunks)
239 self.assertEquals(text, p.get()) 106 self.assertEquals(RAW.MINIMAL_NEW, p.get())
240 107
241 def testValidSvnDelete(self): 108 def testValidSvnDelete(self):
242 text = '--- chrome/file.cc\tbar\n+++ /dev/null\tfoo\n' 109 p = patch.FilePatchDiff('chrome/file.cc', RAW.MINIMAL_DELETE, [])
243 p = patch.FilePatchDiff('chrome/file.cc', text, []) 110 self.assertEquals(RAW.MINIMAL_DELETE, p.diff_header)
244 self.assertEquals(text, p.diff_header)
245 self.assertEquals('', p.diff_hunks) 111 self.assertEquals('', p.diff_hunks)
246 self.assertEquals(text, p.get()) 112 self.assertEquals(RAW.MINIMAL_DELETE, p.get())
247 113
248 def testRelPath(self): 114 def testRelPath(self):
249 patches = patch.PatchSet([ 115 patches = patch.PatchSet([
250 patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []), 116 patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []),
251 patch.FilePatchDiff( 117 patch.FilePatchDiff(
252 'tools\\clang_check/README.chromium', GIT_DELETE, []), 118 'tools\\clang_check/README.chromium', GIT.DELETE, []),
253 patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []), 119 patch.FilePatchDiff('tools/run_local_server.sh', GIT.RENAME, []),
254 patch.FilePatchDiff( 120 patch.FilePatchDiff(
255 'chromeos\\views/webui_menu_widget.h', GIT_RENAME_PARTIAL, []), 121 'chromeos\\views/webui_menu_widget.h', GIT.RENAME_PARTIAL, []),
256 patch.FilePatchDiff('pp', GIT_COPY, []), 122 patch.FilePatchDiff('pp', GIT.COPY, []),
257 patch.FilePatchDiff('foo', GIT_NEW, []), 123 patch.FilePatchDiff('foo', GIT.NEW, []),
258 patch.FilePatchDelete('other/place/foo', True), 124 patch.FilePatchDelete('other/place/foo', True),
259 patch.FilePatchBinary('bar', 'data', [], is_new=False), 125 patch.FilePatchBinary('bar', 'data', [], is_new=False),
260 ]) 126 ])
261 expected = [ 127 expected = [
262 'chrome/file.cc', 'tools/clang_check/README.chromium', 128 'chrome/file.cc', 'tools/clang_check/README.chromium',
263 'tools/run_local_server.sh', 129 'tools/run_local_server.sh',
264 'chromeos/views/webui_menu_widget.h', 'pp', 'foo', 130 'chromeos/views/webui_menu_widget.h', 'pp', 'foo',
265 'other/place/foo', 'bar'] 131 'other/place/foo', 'bar']
266 self.assertEquals(expected, patches.filenames) 132 self.assertEquals(expected, patches.filenames)
267 orig_name = patches.patches[0].filename 133 orig_name = patches.patches[0].filename
268 orig_source_name = patches.patches[0].source_filename or orig_name 134 orig_source_name = patches.patches[0].source_filename or orig_name
269 patches.set_relpath(os.path.join('a', 'bb')) 135 patches.set_relpath(os.path.join('a', 'bb'))
270 expected = [os.path.join('a', 'bb', x) for x in expected] 136 expected = [os.path.join('a', 'bb', x) for x in expected]
271 self.assertEquals(expected, patches.filenames) 137 self.assertEquals(expected, patches.filenames)
272 # Make sure each header is updated accordingly. 138 # Make sure each header is updated accordingly.
273 header = [] 139 header = []
274 new_name = os.path.join('a', 'bb', orig_name) 140 new_name = os.path.join('a', 'bb', orig_name)
275 new_source_name = os.path.join('a', 'bb', orig_source_name) 141 new_source_name = os.path.join('a', 'bb', orig_source_name)
276 for line in SVN_PATCH.splitlines(True): 142 for line in RAW.PATCH.splitlines(True):
277 if line.startswith('@@'): 143 if line.startswith('@@'):
278 break 144 break
279 if line[:3] == '---': 145 if line[:3] == '---':
280 line = line.replace(orig_source_name, new_source_name) 146 line = line.replace(orig_source_name, new_source_name)
281 if line[:3] == '+++': 147 if line[:3] == '+++':
282 line = line.replace(orig_name, new_name) 148 line = line.replace(orig_name, new_name)
283 header.append(line) 149 header.append(line)
284 header = ''.join(header) 150 header = ''.join(header)
285 self.assertEquals(header, patches.patches[0].diff_header) 151 self.assertEquals(header, patches.patches[0].diff_header)
286 152
287 def testRelPathEmpty(self): 153 def testRelPathEmpty(self):
288 patches = patch.PatchSet([ 154 patches = patch.PatchSet([
289 patch.FilePatchDiff('chrome\\file.cc', SVN_PATCH, []), 155 patch.FilePatchDiff('chrome\\file.cc', RAW.PATCH, []),
290 patch.FilePatchDelete('other\\place\\foo', True), 156 patch.FilePatchDelete('other\\place\\foo', True),
291 ]) 157 ])
292 patches.set_relpath('') 158 patches.set_relpath('')
293 self.assertEquals( 159 self.assertEquals(
294 ['chrome/file.cc', 'other/place/foo'], 160 ['chrome/file.cc', 'other/place/foo'],
295 [f.filename for f in patches]) 161 [f.filename for f in patches])
296 self.assertEquals([None, None], [f.source_filename for f in patches]) 162 self.assertEquals([None, None], [f.source_filename for f in patches])
297 163
298 def testBackSlash(self): 164 def testBackSlash(self):
299 mangled_patch = SVN_PATCH.replace('chrome/', 'chrome\\') 165 mangled_patch = RAW.PATCH.replace('chrome/', 'chrome\\')
300 patches = patch.PatchSet([ 166 patches = patch.PatchSet([
301 patch.FilePatchDiff('chrome\\file.cc', mangled_patch, []), 167 patch.FilePatchDiff('chrome\\file.cc', mangled_patch, []),
302 patch.FilePatchDelete('other\\place\\foo', True), 168 patch.FilePatchDelete('other\\place\\foo', True),
303 ]) 169 ])
304 expected = ['chrome/file.cc', 'other/place/foo'] 170 expected = ['chrome/file.cc', 'other/place/foo']
305 self.assertEquals(expected, patches.filenames) 171 self.assertEquals(expected, patches.filenames)
306 self.assertEquals(SVN_PATCH, patches.patches[0].get()) 172 self.assertEquals(RAW.PATCH, patches.patches[0].get())
307 173
308 def testDelete(self): 174 def testDelete(self):
309 p = patch.FilePatchDiff('tools/clang_check/README.chromium', DELETE, []) 175 p = patch.FilePatchDiff('tools/clang_check/README.chromium', RAW.DELETE, [])
310 self._check_patch( 176 self._check_patch(
311 p, 'tools/clang_check/README.chromium', DELETE, is_delete=True) 177 p, 'tools/clang_check/README.chromium', RAW.DELETE, is_delete=True)
312 178
313 def testGitDelete(self): 179 def testGitDelete(self):
314 p = patch.FilePatchDiff('tools/clang_check/README.chromium', GIT_DELETE, []) 180 p = patch.FilePatchDiff('tools/clang_check/README.chromium', GIT.DELETE, [])
315 self._check_patch( 181 self._check_patch(
316 p, 'tools/clang_check/README.chromium', GIT_DELETE, is_delete=True, 182 p, 'tools/clang_check/README.chromium', GIT.DELETE, is_delete=True,
317 is_git_diff=True, patchlevel=1) 183 is_git_diff=True, patchlevel=1)
318 184
319 def testGitRename(self): 185 def testGitRename(self):
320 p = patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) 186 p = patch.FilePatchDiff('tools/run_local_server.sh', GIT.RENAME, [])
321 self._check_patch(p, 'tools/run_local_server.sh', GIT_RENAME, 187 self._check_patch(p, 'tools/run_local_server.sh', GIT.RENAME,
322 is_git_diff=True, patchlevel=1, 188 is_git_diff=True, patchlevel=1,
323 source_filename='tools/run_local_server.PY', is_new=True) 189 source_filename='tools/run_local_server.PY', is_new=True)
324 190
325 def testGitRenamePartial(self): 191 def testGitRenamePartial(self):
326 p = patch.FilePatchDiff( 192 p = patch.FilePatchDiff(
327 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, []) 193 'chromeos/views/webui_menu_widget.h', GIT.RENAME_PARTIAL, [])
328 self._check_patch( 194 self._check_patch(
329 p, 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, 195 p, 'chromeos/views/webui_menu_widget.h', GIT.RENAME_PARTIAL,
330 source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True, 196 source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True,
331 patchlevel=1, is_new=True) 197 patchlevel=1, is_new=True)
332 198
333 def testGitCopy(self): 199 def testGitCopy(self):
334 p = patch.FilePatchDiff('pp', GIT_COPY, []) 200 p = patch.FilePatchDiff('pp', GIT.COPY, [])
335 self._check_patch(p, 'pp', GIT_COPY, is_git_diff=True, patchlevel=1, 201 self._check_patch(p, 'pp', GIT.COPY, is_git_diff=True, patchlevel=1,
336 source_filename='PRESUBMIT.py', is_new=True) 202 source_filename='PRESUBMIT.py', is_new=True)
337 203
338 def testOnlyHeader(self): 204 def testOnlyHeader(self):
339 diff = '--- file_a\n+++ file_a\n' 205 p = patch.FilePatchDiff('file_a', RAW.MINIMAL, [])
340 p = patch.FilePatchDiff('file_a', diff, []) 206 self._check_patch(p, 'file_a', RAW.MINIMAL)
341 self._check_patch(p, 'file_a', diff)
342 207
343 def testSmallest(self): 208 def testSmallest(self):
344 diff = '--- file_a\n+++ file_a\n@@ -0,0 +1 @@\n+foo\n' 209 p = patch.FilePatchDiff('file_a', RAW.NEW_NOT_NULL, [])
345 p = patch.FilePatchDiff('file_a', diff, []) 210 self._check_patch(p, 'file_a', RAW.NEW_NOT_NULL)
346 self._check_patch(p, 'file_a', diff)
347 211
348 def testRenameOnlyHeader(self): 212 def testRenameOnlyHeader(self):
349 diff = '--- file_a\n+++ file_b\n' 213 p = patch.FilePatchDiff('file_b', RAW.MINIMAL_RENAME, [])
350 p = patch.FilePatchDiff('file_b', diff, []) 214 self._check_patch(
351 # Should it be marked as new? 215 p, 'file_b', RAW.MINIMAL_RENAME, source_filename='file_a', is_new=True)
352 self._check_patch(p, 'file_b', diff, source_filename='file_a', is_new=True)
353 216
354 def testGitCopyPartial(self): 217 def testGitCopyPartial(self):
355 diff = ( 218 p = patch.FilePatchDiff('wtf2', GIT.COPY_PARTIAL, [])
356 'diff --git a/wtf b/wtf2\n'
357 'similarity index 98%\n'
358 'copy from wtf\n'
359 'copy to wtf2\n'
360 'index 79fbaf3..3560689 100755\n'
361 '--- a/wtf\n'
362 '+++ b/wtf2\n'
363 '@@ -1,4 +1,4 @@\n'
364 '-#!/usr/bin/env python\n'
365 '+#!/usr/bin/env python1.3\n'
366 ' # Copyright (c) 2010 The Chromium Authors. All rights reserved.\n'
367 ' # blah blah blah as\n'
368 ' # found in the LICENSE file.\n')
369 p = patch.FilePatchDiff('wtf2', diff, [])
370 # Should it be marked as new?
371 self._check_patch( 219 self._check_patch(
372 p, 'wtf2', diff, source_filename='wtf', is_git_diff=True, patchlevel=1, 220 p, 'wtf2', GIT.COPY_PARTIAL, source_filename='wtf', is_git_diff=True,
373 is_new=True) 221 patchlevel=1, is_new=True)
374 222
375 def testGitExe(self): 223 def testGitNewExe(self):
376 diff = ( 224 p = patch.FilePatchDiff('natsort_test.py', GIT.NEW_EXE, [])
377 'diff --git a/natsort_test.py b/natsort_test.py\n'
378 'new file mode 100755\n'
379 '--- /dev/null\n'
380 '+++ b/natsort_test.py\n'
381 '@@ -0,0 +1,1 @@\n'
382 '+#!/usr/bin/env python\n')
383 p = patch.FilePatchDiff('natsort_test.py', diff, [])
384 self._check_patch( 225 self._check_patch(
385 p, 'natsort_test.py', diff, is_new=True, is_git_diff=True, patchlevel=1, 226 p, 'natsort_test.py', GIT.NEW_EXE, is_new=True, is_git_diff=True,
386 svn_properties=[('svn:executable', '*')]) 227 patchlevel=1, svn_properties=[('svn:executable', '*')])
387 228
388 def testGitExe2(self): 229 def testGitNewMode(self):
389 diff = ( 230 p = patch.FilePatchDiff('natsort_test.py', GIT.NEW_MODE, [])
390 'diff --git a/natsort_test.py b/natsort_test.py\n'
391 'new file mode 100644\n'
392 '--- /dev/null\n'
393 '+++ b/natsort_test.py\n'
394 '@@ -0,0 +1,1 @@\n'
395 '+#!/usr/bin/env python\n')
396 p = patch.FilePatchDiff('natsort_test.py', diff, [])
397 self._check_patch( 231 self._check_patch(
398 p, 'natsort_test.py', diff, is_new=True, is_git_diff=True, patchlevel=1) 232 p, 'natsort_test.py', GIT.NEW_MODE, is_new=True, is_git_diff=True,
233 patchlevel=1)
399 234
400 235
401 class PatchTestFail(unittest.TestCase): 236 class PatchTestFail(unittest.TestCase):
402 # All patches that should throw. 237 # All patches that should throw.
403 def testFilePatchDelete(self): 238 def testFilePatchDelete(self):
404 p = patch.FilePatchDelete('foo', False) 239 p = patch.FilePatchDelete('foo', False)
405 try: 240 try:
406 p.get() 241 p.get()
407 self.fail() 242 self.fail()
408 except NotImplementedError: 243 except NotImplementedError:
(...skipping 23 matching lines...) Expand all
432 267
433 def testFilePatchDiffNone(self): 268 def testFilePatchDiffNone(self):
434 try: 269 try:
435 patch.FilePatchDiff('foo', None, []) 270 patch.FilePatchDiff('foo', None, [])
436 self.fail() 271 self.fail()
437 except patch.UnsupportedPatchFormat: 272 except patch.UnsupportedPatchFormat:
438 pass 273 pass
439 274
440 def testFilePatchBadDiffName(self): 275 def testFilePatchBadDiffName(self):
441 try: 276 try:
442 patch.FilePatchDiff('foo', SVN_PATCH, []) 277 patch.FilePatchDiff('foo', RAW.PATCH, [])
443 self.fail() 278 self.fail()
444 except patch.UnsupportedPatchFormat, e: 279 except patch.UnsupportedPatchFormat, e:
445 self.assertEquals( 280 self.assertEquals(
446 "Can't process patch for file foo.\nUnexpected diff: chrome/file.cc.", 281 "Can't process patch for file foo.\nUnexpected diff: chrome/file.cc.",
447 str(e)) 282 str(e))
448 283
449 def testFilePatchDiffBadHeader(self): 284 def testFilePatchDiffBadHeader(self):
450 try: 285 try:
451 diff = ( 286 diff = (
452 '+++ b/foo\n' 287 '+++ b/foo\n'
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 'ff\n' 364 'ff\n'
530 'ggg\n' 365 'ggg\n'
531 'hh\n'), 366 'hh\n'),
532 []) 367 [])
533 self.fail() 368 self.fail()
534 except patch.UnsupportedPatchFormat: 369 except patch.UnsupportedPatchFormat:
535 pass 370 pass
536 371
537 def testRelPathBad(self): 372 def testRelPathBad(self):
538 patches = patch.PatchSet([ 373 patches = patch.PatchSet([
539 patch.FilePatchDiff('chrome\\file.cc', SVN_PATCH, []), 374 patch.FilePatchDiff('chrome\\file.cc', RAW.PATCH, []),
540 patch.FilePatchDelete('other\\place\\foo', True), 375 patch.FilePatchDelete('other\\place\\foo', True),
541 ]) 376 ])
542 try: 377 try:
543 patches.set_relpath('..') 378 patches.set_relpath('..')
544 self.fail() 379 self.fail()
545 except patch.UnsupportedPatchFormat: 380 except patch.UnsupportedPatchFormat:
546 pass 381 pass
547 382
548 def testInverted(self): 383 def testInverted(self):
549 try: 384 try:
550 patch.FilePatchDiff( 385 patch.FilePatchDiff(
551 'file_a', '+++ file_a\n--- file_a\n@@ -0,0 +1 @@\n+foo\n', []) 386 'file_a', '+++ file_a\n--- file_a\n@@ -0,0 +1 @@\n+foo\n', [])
552 self.fail() 387 self.fail()
553 except patch.UnsupportedPatchFormat: 388 except patch.UnsupportedPatchFormat:
554 pass 389 pass
555 390
556 def testInvertedOnlyHeader(self): 391 def testInvertedOnlyHeader(self):
557 try: 392 try:
558 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', []) 393 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', [])
559 self.fail() 394 self.fail()
560 except patch.UnsupportedPatchFormat: 395 except patch.UnsupportedPatchFormat:
561 pass 396 pass
562 397
563 398
564 if __name__ == '__main__': 399 if __name__ == '__main__':
565 logging.basicConfig(level= 400 logging.basicConfig(level=
566 [logging.WARNING, logging.INFO, logging.DEBUG][ 401 [logging.WARNING, logging.INFO, logging.DEBUG][
567 min(2, sys.argv.count('-v'))]) 402 min(2, sys.argv.count('-v'))])
568 unittest.main() 403 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | tests/patches_data.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698