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 sys | 11 import sys |
11 import unittest | 12 import unittest |
12 | 13 |
13 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
14 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) | 15 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) |
15 | 16 |
16 import patch | 17 import patch |
17 from tests.patches_data import GIT, RAW | 18 from tests.patches_data import GIT, RAW |
18 | 19 |
19 | 20 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 'foo', | 147 'foo', |
147 'other/place/foo', | 148 'other/place/foo', |
148 'tools/clang_check/README.chromium', | 149 'tools/clang_check/README.chromium', |
149 ] | 150 ] |
150 self.assertEquals(expected, patches.filenames) | 151 self.assertEquals(expected, patches.filenames) |
151 | 152 |
152 # Test patch #4. | 153 # Test patch #4. |
153 orig_name = patches.patches[4].filename | 154 orig_name = patches.patches[4].filename |
154 orig_source_name = patches.patches[4].source_filename or orig_name | 155 orig_source_name = patches.patches[4].source_filename or orig_name |
155 patches.set_relpath(os.path.join('a', 'bb')) | 156 patches.set_relpath(os.path.join('a', 'bb')) |
156 expected = [os.path.join('a', 'bb', x) for x in expected] | 157 # Expect posixpath all the time. |
| 158 expected = [posixpath.join('a', 'bb', x) for x in expected] |
157 self.assertEquals(expected, patches.filenames) | 159 self.assertEquals(expected, patches.filenames) |
158 # Make sure each header is updated accordingly. | 160 # Make sure each header is updated accordingly. |
159 header = [] | 161 header = [] |
160 new_name = os.path.join('a', 'bb', orig_name) | 162 new_name = posixpath.join('a', 'bb', orig_name) |
161 new_source_name = os.path.join('a', 'bb', orig_source_name) | 163 new_source_name = posixpath.join('a', 'bb', orig_source_name) |
162 for line in RAW.PATCH.splitlines(True): | 164 for line in RAW.PATCH.splitlines(True): |
163 if line.startswith('@@'): | 165 if line.startswith('@@'): |
164 break | 166 break |
165 if line[:3] == '---': | 167 if line[:3] == '---': |
166 line = line.replace(orig_source_name, new_source_name) | 168 line = line.replace(orig_source_name, new_source_name) |
167 if line[:3] == '+++': | 169 if line[:3] == '+++': |
168 line = line.replace(orig_name, new_name) | 170 line = line.replace(orig_name, new_name) |
169 header.append(line) | 171 header.append(line) |
170 header = ''.join(header) | 172 header = ''.join(header) |
171 self.assertEquals(header, patches.patches[4].diff_header) | 173 self.assertEquals(header, patches.patches[4].diff_header) |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 self.fail() | 454 self.fail() |
453 except patch.UnsupportedPatchFormat: | 455 except patch.UnsupportedPatchFormat: |
454 pass | 456 pass |
455 | 457 |
456 | 458 |
457 if __name__ == '__main__': | 459 if __name__ == '__main__': |
458 logging.basicConfig(level= | 460 logging.basicConfig(level= |
459 [logging.WARNING, logging.INFO, logging.DEBUG][ | 461 [logging.WARNING, logging.INFO, logging.DEBUG][ |
460 min(2, sys.argv.count('-v'))]) | 462 min(2, sys.argv.count('-v'))]) |
461 unittest.main() | 463 unittest.main() |
OLD | NEW |