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

Side by Side Diff: tests/patch_test.py

Issue 8066012: Share more data between checkout_test and patches_data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 2 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 | « tests/checkout_test.py ('k') | 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
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 self.assertEquals(RAW.MINIMAL_NEW, p.get()) 106 self.assertEquals(RAW.MINIMAL_NEW, p.get())
107 107
108 def testValidSvnDelete(self): 108 def testValidSvnDelete(self):
109 p = patch.FilePatchDiff('chrome/file.cc', RAW.MINIMAL_DELETE, []) 109 p = patch.FilePatchDiff('chrome/file.cc', RAW.MINIMAL_DELETE, [])
110 self.assertEquals(RAW.MINIMAL_DELETE, p.diff_header) 110 self.assertEquals(RAW.MINIMAL_DELETE, p.diff_header)
111 self.assertEquals('', p.diff_hunks) 111 self.assertEquals('', p.diff_hunks)
112 self.assertEquals(RAW.MINIMAL_DELETE, p.get()) 112 self.assertEquals(RAW.MINIMAL_DELETE, p.get())
113 113
114 def testRelPath(self): 114 def testRelPath(self):
115 patches = patch.PatchSet([ 115 patches = patch.PatchSet([
116 patch.FilePatchDiff('pp', GIT.COPY, []),
117 patch.FilePatchDiff(
118 'chromeos\\views/webui_menu_widget.h', GIT.RENAME_PARTIAL, []),
119 patch.FilePatchDiff('tools/run_local_server.sh', GIT.RENAME, []),
120 patch.FilePatchBinary('bar', 'data', [], is_new=False),
116 patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []), 121 patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []),
122 patch.FilePatchDiff('foo', GIT.NEW, []),
123 patch.FilePatchDelete('other/place/foo', True),
117 patch.FilePatchDiff( 124 patch.FilePatchDiff(
118 'tools\\clang_check/README.chromium', GIT.DELETE, []), 125 'tools\\clang_check/README.chromium', GIT.DELETE, []),
119 patch.FilePatchDiff('tools/run_local_server.sh', GIT.RENAME, []),
120 patch.FilePatchDiff(
121 'chromeos\\views/webui_menu_widget.h', GIT.RENAME_PARTIAL, []),
122 patch.FilePatchDiff('pp', GIT.COPY, []),
123 patch.FilePatchDiff('foo', GIT.NEW, []),
124 patch.FilePatchDelete('other/place/foo', True),
125 patch.FilePatchBinary('bar', 'data', [], is_new=False),
126 ]) 126 ])
127 expected = [ 127 expected = [
128 'chrome/file.cc', 'tools/clang_check/README.chromium', 128 'pp',
129 'chromeos/views/webui_menu_widget.h',
129 'tools/run_local_server.sh', 130 'tools/run_local_server.sh',
130 'chromeos/views/webui_menu_widget.h', 'pp', 'foo', 131 'bar',
131 'other/place/foo', 'bar'] 132 'chrome/file.cc',
133 'foo',
134 'other/place/foo',
135 'tools/clang_check/README.chromium',
136 ]
132 self.assertEquals(expected, patches.filenames) 137 self.assertEquals(expected, patches.filenames)
133 orig_name = patches.patches[0].filename 138
134 orig_source_name = patches.patches[0].source_filename or orig_name 139 # Test patch #4.
140 orig_name = patches.patches[4].filename
141 orig_source_name = patches.patches[4].source_filename or orig_name
135 patches.set_relpath(os.path.join('a', 'bb')) 142 patches.set_relpath(os.path.join('a', 'bb'))
136 expected = [os.path.join('a', 'bb', x) for x in expected] 143 expected = [os.path.join('a', 'bb', x) for x in expected]
137 self.assertEquals(expected, patches.filenames) 144 self.assertEquals(expected, patches.filenames)
138 # Make sure each header is updated accordingly. 145 # Make sure each header is updated accordingly.
139 header = [] 146 header = []
140 new_name = os.path.join('a', 'bb', orig_name) 147 new_name = os.path.join('a', 'bb', orig_name)
141 new_source_name = os.path.join('a', 'bb', orig_source_name) 148 new_source_name = os.path.join('a', 'bb', orig_source_name)
142 for line in RAW.PATCH.splitlines(True): 149 for line in RAW.PATCH.splitlines(True):
143 if line.startswith('@@'): 150 if line.startswith('@@'):
144 break 151 break
145 if line[:3] == '---': 152 if line[:3] == '---':
146 line = line.replace(orig_source_name, new_source_name) 153 line = line.replace(orig_source_name, new_source_name)
147 if line[:3] == '+++': 154 if line[:3] == '+++':
148 line = line.replace(orig_name, new_name) 155 line = line.replace(orig_name, new_name)
149 header.append(line) 156 header.append(line)
150 header = ''.join(header) 157 header = ''.join(header)
151 self.assertEquals(header, patches.patches[0].diff_header) 158 self.assertEquals(header, patches.patches[4].diff_header)
152 159
153 def testRelPathEmpty(self): 160 def testRelPathEmpty(self):
154 patches = patch.PatchSet([ 161 patches = patch.PatchSet([
155 patch.FilePatchDiff('chrome\\file.cc', RAW.PATCH, []), 162 patch.FilePatchDiff('chrome\\file.cc', RAW.PATCH, []),
156 patch.FilePatchDelete('other\\place\\foo', True), 163 patch.FilePatchDelete('other\\place\\foo', True),
157 ]) 164 ])
158 patches.set_relpath('') 165 patches.set_relpath('')
159 self.assertEquals( 166 self.assertEquals(
160 ['chrome/file.cc', 'other/place/foo'], 167 ['chrome/file.cc', 'other/place/foo'],
161 [f.filename for f in patches]) 168 [f.filename for f in patches])
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 self.fail() 401 self.fail()
395 except patch.UnsupportedPatchFormat: 402 except patch.UnsupportedPatchFormat:
396 pass 403 pass
397 404
398 405
399 if __name__ == '__main__': 406 if __name__ == '__main__':
400 logging.basicConfig(level= 407 logging.basicConfig(level=
401 [logging.WARNING, logging.INFO, logging.DEBUG][ 408 [logging.WARNING, logging.INFO, logging.DEBUG][
402 min(2, sys.argv.count('-v'))]) 409 min(2, sys.argv.count('-v'))])
403 unittest.main() 410 unittest.main()
OLDNEW
« no previous file with comments | « tests/checkout_test.py ('k') | tests/patches_data.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698