| 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 posixpath | 10 import posixpath |
| 11 import sys | 11 import sys |
| 12 import unittest | 12 import unittest |
| 13 | 13 |
| 14 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 15 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) | |
| 16 | 15 |
| 17 import patch | 16 import patch |
| 18 from tests.patches_data import GIT, RAW | 17 from tests.patches_data import GIT, RAW |
| 19 | 18 |
| 20 | 19 |
| 21 class PatchTest(unittest.TestCase): | 20 class PatchTest(unittest.TestCase): |
| 22 def _check_patch(self, | 21 def _check_patch(self, |
| 23 p, | 22 p, |
| 24 filename, | 23 filename, |
| 25 diff, | 24 diff, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 p = patch.FilePatchDiff('foo', RAW.NEW, []) | 84 p = patch.FilePatchDiff('foo', RAW.NEW, []) |
| 86 self._check_patch(p, 'foo', RAW.NEW, is_new=True) | 85 self._check_patch(p, 'foo', RAW.NEW, is_new=True) |
| 87 | 86 |
| 88 def testFilePatchDiffGitNew(self): | 87 def testFilePatchDiffGitNew(self): |
| 89 # The code path is different for git and svn. | 88 # The code path is different for git and svn. |
| 90 p = patch.FilePatchDiff('foo', GIT.NEW, []) | 89 p = patch.FilePatchDiff('foo', GIT.NEW, []) |
| 91 self._check_patch( | 90 self._check_patch( |
| 92 p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1) | 91 p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1) |
| 93 | 92 |
| 94 def testValidSvn(self): | 93 def testValidSvn(self): |
| 95 # pylint: disable=R0201 | |
| 96 # Method could be a function | |
| 97 # Should not throw. | 94 # Should not throw. |
| 98 p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []) | 95 p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []) |
| 99 lines = RAW.PATCH.splitlines(True) | 96 lines = RAW.PATCH.splitlines(True) |
| 100 header = ''.join(lines[:4]) | 97 header = ''.join(lines[:4]) |
| 101 hunks = ''.join(lines[4:]) | 98 hunks = ''.join(lines[4:]) |
| 102 self.assertEquals(header, p.diff_header) | 99 self.assertEquals(header, p.diff_header) |
| 103 self.assertEquals(hunks, p.diff_hunks) | 100 self.assertEquals(hunks, p.diff_hunks) |
| 104 self.assertEquals(RAW.PATCH, p.get(True)) | 101 self.assertEquals(RAW.PATCH, p.get(True)) |
| 105 self.assertEquals(RAW.PATCH, p.get(False)) | 102 self.assertEquals(RAW.PATCH, p.get(False)) |
| 106 | 103 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 self.fail() | 451 self.fail() |
| 455 except patch.UnsupportedPatchFormat: | 452 except patch.UnsupportedPatchFormat: |
| 456 pass | 453 pass |
| 457 | 454 |
| 458 | 455 |
| 459 if __name__ == '__main__': | 456 if __name__ == '__main__': |
| 460 logging.basicConfig(level= | 457 logging.basicConfig(level= |
| 461 [logging.WARNING, logging.INFO, logging.DEBUG][ | 458 [logging.WARNING, logging.INFO, logging.DEBUG][ |
| 462 min(2, sys.argv.count('-v'))]) | 459 min(2, sys.argv.count('-v'))]) |
| 463 unittest.main() | 460 unittest.main() |
| OLD | NEW |