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

Side by Side Diff: tests/gclient_scm_test.py

Issue 3106014: Remove 'options' usage from scm.py (Closed)
Patch Set: Created 10 years, 4 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
« scm.py ('K') | « scm.py ('k') | no next file » | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # Import before super_mox to keep valid references. 8 # Import before super_mox to keep valid references.
9 from os import rename 9 from os import rename
10 from shutil import rmtree 10 from shutil import rmtree
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 options = self.Options(verbose=True) 118 options = self.Options(verbose=True)
119 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 119 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
120 gclient_scm.os.path.isdir(base_path).AndReturn(False) 120 gclient_scm.os.path.isdir(base_path).AndReturn(False)
121 # It'll to a checkout instead. 121 # It'll to a checkout instead.
122 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 122 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
123 ).AndReturn(False) 123 ).AndReturn(False)
124 print("\n_____ %s is missing, synching instead" % self.relpath) 124 print("\n_____ %s is missing, synching instead" % self.relpath)
125 # Checkout. 125 # Checkout.
126 gclient_scm.os.path.exists(base_path).AndReturn(False) 126 gclient_scm.os.path.exists(base_path).AndReturn(False)
127 files_list = self.mox.CreateMockAnything() 127 files_list = self.mox.CreateMockAnything()
128 gclient_scm.scm.SVN.RunAndGetFileList(options, 128 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
129 ['checkout', self.url, base_path], 129 ['checkout', self.url, base_path],
130 self.root_dir, files_list) 130 self.root_dir, files_list)
131 131
132 self.mox.ReplayAll() 132 self.mox.ReplayAll()
133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
134 relpath=self.relpath) 134 relpath=self.relpath)
135 scm.revert(options, self.args, files_list) 135 scm.revert(options, self.args, files_list)
136 136
137 def testRevertNone(self): 137 def testRevertNone(self):
138 options = self.Options(verbose=True) 138 options = self.Options(verbose=True)
139 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 139 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
140 gclient_scm.os.path.isdir(base_path).AndReturn(True) 140 gclient_scm.os.path.isdir(base_path).AndReturn(True)
141 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([]) 141 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([])
142 gclient_scm.scm.SVN.RunAndGetFileList(options, 142 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
143 ['update', '--revision', 'BASE'], 143 ['update', '--revision', 'BASE'],
144 base_path, mox.IgnoreArg()) 144 base_path, mox.IgnoreArg())
145 145
146 self.mox.ReplayAll() 146 self.mox.ReplayAll()
147 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 147 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
148 relpath=self.relpath) 148 relpath=self.relpath)
149 file_list = [] 149 file_list = []
150 scm.revert(options, self.args, file_list) 150 scm.revert(options, self.args, file_list)
151 151
152 def testRevert2Files(self): 152 def testRevert2Files(self):
153 options = self.Options(verbose=True) 153 options = self.Options(verbose=True)
154 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 154 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
155 gclient_scm.os.path.isdir(base_path).AndReturn(True) 155 gclient_scm.os.path.isdir(base_path).AndReturn(True)
156 items = [ 156 items = [
157 ('M ', 'a'), 157 ('M ', 'a'),
158 ('A ', 'b'), 158 ('A ', 'b'),
159 ] 159 ]
160 file_path1 = gclient_scm.os.path.join(base_path, 'a') 160 file_path1 = gclient_scm.os.path.join(base_path, 'a')
161 file_path2 = gclient_scm.os.path.join(base_path, 'b') 161 file_path2 = gclient_scm.os.path.join(base_path, 'b')
162 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) 162 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
163 gclient_scm.os.path.exists(file_path1).AndReturn(True) 163 gclient_scm.os.path.exists(file_path1).AndReturn(True)
164 gclient_scm.os.path.isfile(file_path1).AndReturn(True) 164 gclient_scm.os.path.isfile(file_path1).AndReturn(True)
165 gclient_scm.os.remove(file_path1) 165 gclient_scm.os.remove(file_path1)
166 gclient_scm.os.path.exists(file_path2).AndReturn(True) 166 gclient_scm.os.path.exists(file_path2).AndReturn(True)
167 gclient_scm.os.path.isfile(file_path2).AndReturn(True) 167 gclient_scm.os.path.isfile(file_path2).AndReturn(True)
168 gclient_scm.os.remove(file_path2) 168 gclient_scm.os.remove(file_path2)
169 gclient_scm.scm.SVN.RunAndGetFileList(options, 169 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
170 ['update', '--revision', 'BASE'], 170 ['update', '--revision', 'BASE'],
171 base_path, mox.IgnoreArg()) 171 base_path, mox.IgnoreArg())
172 print(gclient_scm.os.path.join(base_path, 'a')) 172 print(gclient_scm.os.path.join(base_path, 'a'))
173 print(gclient_scm.os.path.join(base_path, 'b')) 173 print(gclient_scm.os.path.join(base_path, 'b'))
174 174
175 self.mox.ReplayAll() 175 self.mox.ReplayAll()
176 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 176 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
177 relpath=self.relpath) 177 relpath=self.relpath)
178 file_list = [] 178 file_list = []
179 scm.revert(options, self.args, file_list) 179 scm.revert(options, self.args, file_list)
180 180
181 def testRevertDirectory(self): 181 def testRevertDirectory(self):
182 options = self.Options(verbose=True) 182 options = self.Options(verbose=True)
183 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 183 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
184 gclient_scm.os.path.isdir(base_path).AndReturn(True) 184 gclient_scm.os.path.isdir(base_path).AndReturn(True)
185 items = [ 185 items = [
186 ('~ ', 'a'), 186 ('~ ', 'a'),
187 ] 187 ]
188 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) 188 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
189 file_path = gclient_scm.os.path.join(base_path, 'a') 189 file_path = gclient_scm.os.path.join(base_path, 'a')
190 print(file_path) 190 print(file_path)
191 gclient_scm.os.path.exists(file_path).AndReturn(True) 191 gclient_scm.os.path.exists(file_path).AndReturn(True)
192 gclient_scm.os.path.isfile(file_path).AndReturn(False) 192 gclient_scm.os.path.isfile(file_path).AndReturn(False)
193 gclient_scm.os.path.islink(file_path).AndReturn(False) 193 gclient_scm.os.path.islink(file_path).AndReturn(False)
194 gclient_scm.os.path.isdir(file_path).AndReturn(True) 194 gclient_scm.os.path.isdir(file_path).AndReturn(True)
195 gclient_scm.gclient_utils.RemoveDirectory(file_path) 195 gclient_scm.gclient_utils.RemoveDirectory(file_path)
196 file_list1 = [] 196 file_list1 = []
197 gclient_scm.scm.SVN.RunAndGetFileList(options, 197 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
198 ['update', '--revision', 'BASE'], 198 ['update', '--revision', 'BASE'],
199 base_path, mox.IgnoreArg()) 199 base_path, mox.IgnoreArg())
200 200
201 self.mox.ReplayAll() 201 self.mox.ReplayAll()
202 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 202 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
203 relpath=self.relpath) 203 relpath=self.relpath)
204 file_list2 = [] 204 file_list2 = []
205 scm.revert(options, self.args, file_list2) 205 scm.revert(options, self.args, file_list2)
206 206
207 def testStatus(self): 207 def testStatus(self):
208 options = self.Options(verbose=True) 208 options = self.Options(verbose=True)
209 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 209 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
210 gclient_scm.os.path.isdir(base_path).AndReturn(True) 210 gclient_scm.os.path.isdir(base_path).AndReturn(True)
211 gclient_scm.scm.SVN.RunAndGetFileList(options, 211 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
212 ['status'] + self.args, 212 ['status'] + self.args,
213 base_path, []).AndReturn(None) 213 base_path, []).AndReturn(None)
214 214
215 self.mox.ReplayAll() 215 self.mox.ReplayAll()
216 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 216 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
217 relpath=self.relpath) 217 relpath=self.relpath)
218 file_list = [] 218 file_list = []
219 self.assertEqual(scm.status(options, self.args, file_list), None) 219 self.assertEqual(scm.status(options, self.args, file_list), None)
220 220
221 221
222 # TODO(maruel): TEST REVISIONS!!! 222 # TODO(maruel): TEST REVISIONS!!!
223 # TODO(maruel): TEST RELOCATE!!! 223 # TODO(maruel): TEST RELOCATE!!!
224 def testUpdateCheckout(self): 224 def testUpdateCheckout(self):
225 options = self.Options(verbose=True) 225 options = self.Options(verbose=True)
226 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 226 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
227 file_info = gclient_scm.gclient_utils.PrintableObject() 227 file_info = gclient_scm.gclient_utils.PrintableObject()
228 file_info.root = 'blah' 228 file_info.root = 'blah'
229 file_info.url = self.url 229 file_info.url = self.url
230 file_info.uuid = 'ABC' 230 file_info.uuid = 'ABC'
231 file_info.revision = 42 231 file_info.revision = 42
232 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 232 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
233 ).AndReturn(False) 233 ).AndReturn(False)
234 # Checkout. 234 # Checkout.
235 gclient_scm.os.path.exists(base_path).AndReturn(False) 235 gclient_scm.os.path.exists(base_path).AndReturn(False)
236 files_list = self.mox.CreateMockAnything() 236 files_list = self.mox.CreateMockAnything()
237 gclient_scm.scm.SVN.RunAndGetFileList(options, 237 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
238 ['checkout', self.url, base_path], 238 ['checkout', self.url, base_path],
239 self.root_dir, files_list) 239 self.root_dir, files_list)
240 self.mox.ReplayAll() 240 self.mox.ReplayAll()
241 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 241 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
242 relpath=self.relpath) 242 relpath=self.relpath)
243 scm.update(options, (), files_list) 243 scm.update(options, (), files_list)
244 244
245 def testUpdateUpdate(self): 245 def testUpdateUpdate(self):
246 options = self.Options(verbose=True) 246 options = self.Options(verbose=True)
247 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 247 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
(...skipping 19 matching lines...) Expand all
267 ).AndReturn(file_info) 267 ).AndReturn(file_info)
268 # Cheat a bit here. 268 # Cheat a bit here.
269 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) 269 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
270 additional_args = [] 270 additional_args = []
271 if options.manually_grab_svn_rev: 271 if options.manually_grab_svn_rev:
272 additional_args = ['--revision', str(file_info['Revision'])] 272 additional_args = ['--revision', str(file_info['Revision'])]
273 if options.force and gclient_scm.scm.SVN.AssertVersion("1.5")[0]: 273 if options.force and gclient_scm.scm.SVN.AssertVersion("1.5")[0]:
274 additional_args.append('--force') 274 additional_args.append('--force')
275 files_list = [] 275 files_list = []
276 gclient_scm.scm.SVN.RunAndGetFileList( 276 gclient_scm.scm.SVN.RunAndGetFileList(
277 options, 277 options.verbose,
278 ['update', base_path] + additional_args, 278 ['update', base_path] + additional_args,
279 self.root_dir, files_list) 279 self.root_dir, files_list)
280 280
281 self.mox.ReplayAll() 281 self.mox.ReplayAll()
282 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 282 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
283 relpath=self.relpath) 283 relpath=self.relpath)
284 scm.update(options, (), files_list) 284 scm.update(options, (), files_list)
285 285
286 def testUpdateSingleCheckout(self): 286 def testUpdateSingleCheckout(self):
287 options = self.Options(verbose=True) 287 options = self.Options(verbose=True)
(...skipping 13 matching lines...) Expand all
301 ).AndReturn(False) 301 ).AndReturn(False)
302 302
303 # Verify no locked files. 303 # Verify no locked files.
304 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') 304 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.')
305 ).AndReturn([]) 305 ).AndReturn([])
306 306
307 # When checking out a single file, we issue an svn checkout and svn update. 307 # When checking out a single file, we issue an svn checkout and svn update.
308 files_list = self.mox.CreateMockAnything() 308 files_list = self.mox.CreateMockAnything()
309 gclient_scm.scm.SVN.Run( 309 gclient_scm.scm.SVN.Run(
310 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir) 310 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir)
311 gclient_scm.scm.SVN.RunAndGetFileList(options, ['update', 'DEPS'], 311 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
312 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list) 312 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
313 313
314 # Now we fall back on scm.update(). 314 # Now we fall back on scm.update().
315 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 315 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
316 ).AndReturn(False) 316 ).AndReturn(False)
317 gclient_scm.os.path.exists(base_path).AndReturn(True) 317 gclient_scm.os.path.exists(base_path).AndReturn(True)
318 gclient_scm.scm.SVN.CaptureInfo( 318 gclient_scm.scm.SVN.CaptureInfo(
319 gclient_scm.os.path.join(base_path, "."), '.' 319 gclient_scm.os.path.join(base_path, "."), '.'
320 ).AndReturn(file_info) 320 ).AndReturn(file_info)
321 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) 321 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 gclient_scm.os.remove(gclient_scm.os.path.join(base_path, 'DEPS')) 373 gclient_scm.os.remove(gclient_scm.os.path.join(base_path, 'DEPS'))
374 374
375 # Verify no locked files. 375 # Verify no locked files.
376 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') 376 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.')
377 ).AndReturn([]) 377 ).AndReturn([])
378 378
379 # When checking out a single file, we issue an svn checkout and svn update. 379 # When checking out a single file, we issue an svn checkout and svn update.
380 files_list = self.mox.CreateMockAnything() 380 files_list = self.mox.CreateMockAnything()
381 gclient_scm.scm.SVN.Run( 381 gclient_scm.scm.SVN.Run(
382 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir) 382 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir)
383 gclient_scm.scm.SVN.RunAndGetFileList(options, ['update', 'DEPS'], 383 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
384 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list) 384 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list)
385 385
386 # Now we fall back on scm.update(). 386 # Now we fall back on scm.update().
387 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 387 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
388 ).AndReturn(False) 388 ).AndReturn(False)
389 gclient_scm.os.path.exists(base_path).AndReturn(True) 389 gclient_scm.os.path.exists(base_path).AndReturn(True)
390 gclient_scm.scm.SVN.CaptureInfo( 390 gclient_scm.scm.SVN.CaptureInfo(
391 gclient_scm.os.path.join(base_path, "."), '.' 391 gclient_scm.os.path.join(base_path, "."), '.'
392 ).AndReturn(file_info) 392 ).AndReturn(file_info)
393 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) 393 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 relpath=self.relpath) 752 relpath=self.relpath)
753 rev_info = scm.revinfo(options, (), None) 753 rev_info = scm.revinfo(options, (), None)
754 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 754 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
755 755
756 756
757 if __name__ == '__main__': 757 if __name__ == '__main__':
758 import unittest 758 import unittest
759 unittest.main() 759 unittest.main()
760 760
761 # vim: ts=2:sw=2:tw=80:et: 761 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« scm.py ('K') | « scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698