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 os | 8 import os |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 'e\n' | 246 'e\n' |
247 '+FOO!\n' | 247 '+FOO!\n' |
248 'ff\n' | 248 'ff\n' |
249 'ggg\n' | 249 'ggg\n' |
250 'hh\n'), | 250 'hh\n'), |
251 []) | 251 []) |
252 self.fail() | 252 self.fail() |
253 except patch.UnsupportedPatchFormat: | 253 except patch.UnsupportedPatchFormat: |
254 pass | 254 pass |
255 | 255 |
256 def testInvalidFilePatchDiffSvn(self): | |
257 try: | |
258 patch.FilePatchDiff('svn_utils_test.txt', ( | |
259 '--- svn_utils_test.txt2\n' | |
260 '+++ svn_utils_test.txt\n' | |
261 '@@ -3,6 +3,7 @@ bb\n' | |
262 'ccc\n' | |
263 'dd\n' | |
264 'e\n' | |
265 '+FOO!\n' | |
266 'ff\n' | |
267 'ggg\n' | |
268 'hh\n'), | |
269 []) | |
270 self.fail() | |
271 except patch.UnsupportedPatchFormat: | |
272 pass | |
273 | |
274 def testValidSvn(self): | 256 def testValidSvn(self): |
275 # pylint: disable=R0201 | 257 # pylint: disable=R0201 |
276 # Method could be a function | 258 # Method could be a function |
277 # Should not throw. | 259 # Should not throw. |
278 p = patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []) | 260 p = patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []) |
279 lines = SVN_PATCH.splitlines(True) | 261 lines = SVN_PATCH.splitlines(True) |
280 header = ''.join(lines[:4]) | 262 header = ''.join(lines[:4]) |
281 hunks = ''.join(lines[4:]) | 263 hunks = ''.join(lines[4:]) |
282 self.assertEquals(header, p.diff_header) | 264 self.assertEquals(header, p.diff_header) |
283 self.assertEquals(hunks, p.diff_hunks) | 265 self.assertEquals(hunks, p.diff_hunks) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 # Shouldn't throw. | 340 # Shouldn't throw. |
359 patch.FilePatchDiff('tools/clang_check/README.chromium', GIT_DELETE, []) | 341 patch.FilePatchDiff('tools/clang_check/README.chromium', GIT_DELETE, []) |
360 patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) | 342 patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) |
361 patch.FilePatchDiff( | 343 patch.FilePatchDiff( |
362 'chrome/browser/chromeos/views/webui_menu_widget.h', | 344 'chrome/browser/chromeos/views/webui_menu_widget.h', |
363 GIT_RENAME_PARTIAL, []) | 345 GIT_RENAME_PARTIAL, []) |
364 patch.FilePatchDiff('pp', GIT_COPY, []) | 346 patch.FilePatchDiff('pp', GIT_COPY, []) |
365 patch.FilePatchDiff('foo', GIT_NEW, []) | 347 patch.FilePatchDiff('foo', GIT_NEW, []) |
366 self.assertTrue(True) | 348 self.assertTrue(True) |
367 | 349 |
| 350 def testOnlyHeader(self): |
| 351 p = patch.FilePatchDiff('file_a', '--- file_a\n+++ file_a\n', []) |
| 352 self.assertTrue(p) |
| 353 |
| 354 def testSmallest(self): |
| 355 p = patch.FilePatchDiff( |
| 356 'file_a', '--- file_a\n+++ file_a\n@@ -0,0 +1 @@\n+foo\n', []) |
| 357 self.assertTrue(p) |
| 358 |
| 359 def testInverted(self): |
| 360 try: |
| 361 patch.FilePatchDiff( |
| 362 'file_a', '+++ file_a\n--- file_a\n@@ -0,0 +1 @@\n+foo\n', []) |
| 363 self.fail() |
| 364 except patch.UnsupportedPatchFormat: |
| 365 pass |
| 366 |
| 367 def testInvertedOnlyHeader(self): |
| 368 try: |
| 369 patch.FilePatchDiff('file_a', '+++ file_a\n--- file_a\n', []) |
| 370 self.fail() |
| 371 except patch.UnsupportedPatchFormat: |
| 372 pass |
| 373 |
| 374 def testRenameOnlyHeader(self): |
| 375 p = patch.FilePatchDiff('file_b', '--- file_a\n+++ file_b\n', []) |
| 376 self.assertTrue(p) |
| 377 |
| 378 def testGitCopy(self): |
| 379 diff = ( |
| 380 'diff --git a/wtf b/wtf2\n' |
| 381 'similarity index 98%\n' |
| 382 'copy from wtf\n' |
| 383 'copy to wtf2\n' |
| 384 'index 79fbaf3..3560689 100755\n' |
| 385 '--- a/wtf\n' |
| 386 '+++ b/wtf2\n' |
| 387 '@@ -1,4 +1,4 @@\n' |
| 388 '-#!/usr/bin/env python\n' |
| 389 '+#!/usr/bin/env python1.3\n' |
| 390 ' # Copyright (c) 2010 The Chromium Authors. All rights reserved.\n' |
| 391 ' # blah blah blah as\n' |
| 392 ' # found in the LICENSE file.\n') |
| 393 p = patch.FilePatchDiff('wtf2', diff, []) |
| 394 self.assertTrue(p) |
| 395 |
368 | 396 |
369 if __name__ == '__main__': | 397 if __name__ == '__main__': |
370 unittest.main() | 398 unittest.main() |
OLD | NEW |