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

Side by Side Diff: tests/gclient_scm_test.py

Issue 14134010: Remove gclient_utils.RemoveDirectory(). (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: RemoveDirectory() -> rmtree() Created 7 years, 8 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
« no previous file with comments | « testing_support/trial_dir.py ('k') | tests/gclient_utils_test.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) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 # pylint: disable=E1103 8 # pylint: disable=E1103
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 49
50 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): 50 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase):
51 def setUp(self): 51 def setUp(self):
52 SuperMoxTestBase.setUp(self) 52 SuperMoxTestBase.setUp(self)
53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') 53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter')
54 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 54 self.mox.StubOutWithMock(gclient_scm.gclient_utils,
55 'CheckCallAndFilterAndHeader') 55 'CheckCallAndFilterAndHeader')
56 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') 56 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
57 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') 57 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') 58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'rmtree')
59 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') 59 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
60 self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo') 60 self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo')
61 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') 61 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
62 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') 62 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
63 self.mox.StubOutWithMock(subprocess2, 'communicate') 63 self.mox.StubOutWithMock(subprocess2, 'communicate')
64 self.mox.StubOutWithMock(subprocess2, 'Popen') 64 self.mox.StubOutWithMock(subprocess2, 'Popen')
65 self._scm_wrapper = gclient_scm.CreateSCM 65 self._scm_wrapper = gclient_scm.CreateSCM
66 gclient_scm.scm.SVN.current_version = None 66 gclient_scm.scm.SVN.current_version = None
67 self._original_SVNBinaryExists = gclient_scm.SVNWrapper.BinaryExists 67 self._original_SVNBinaryExists = gclient_scm.SVNWrapper.BinaryExists
68 self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists 68 self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 self.checkstdout( 203 self.checkstdout(
204 ('\n_____ %s is missing, synching instead\n' % self.relpath)) 204 ('\n_____ %s is missing, synching instead\n' % self.relpath))
205 205
206 def testRevertNoDotSvn(self): 206 def testRevertNoDotSvn(self):
207 options = self.Options(verbose=True, force=True) 207 options = self.Options(verbose=True, force=True)
208 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 208 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
209 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 209 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
210 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) 210 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
211 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) 211 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
212 # Checkout. 212 # Checkout.
213 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
214 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 213 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
215 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 214 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
216 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 215 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
217 parent = gclient_scm.os.path.dirname(self.base_path) 216 parent = gclient_scm.os.path.dirname(self.base_path)
218 gclient_scm.os.path.exists(parent).AndReturn(False) 217 gclient_scm.os.path.exists(parent).AndReturn(False)
219 gclient_scm.os.makedirs(parent) 218 gclient_scm.os.makedirs(parent)
220 gclient_scm.os.path.exists(parent).AndReturn(True) 219 gclient_scm.os.path.exists(parent).AndReturn(True)
221 files_list = self.mox.CreateMockAnything() 220 files_list = self.mox.CreateMockAnything()
222 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 221 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
223 ).AndReturn('1.6') 222 ).AndReturn('1.6')
224 gclient_scm.scm.SVN.RunAndGetFileList( 223 gclient_scm.scm.SVN.RunAndGetFileList(
225 options.verbose, 224 options.verbose,
226 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], 225 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
227 cwd=self.root_dir, 226 cwd=self.root_dir,
228 file_list=files_list) 227 file_list=files_list)
229 228 gclient_scm.gclient_utils.rmtree(self.base_path)
230 self.mox.ReplayAll() 229 self.mox.ReplayAll()
231 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 230 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
232 relpath=self.relpath) 231 relpath=self.relpath)
233 scm.revert(options, self.args, files_list) 232 scm.revert(options, self.args, files_list)
234 self.checkstdout( 233 self.checkstdout(
235 '\n_____ %s is not a valid svn checkout, synching instead\n' % 234 '\n_____ %s is not a valid svn checkout, synching instead\n' %
236 self.relpath) 235 self.relpath)
237 236
238 def testRevertNone(self): 237 def testRevertNone(self):
239 options = self.Options(verbose=True) 238 options = self.Options(verbose=True)
(...skipping 21 matching lines...) Expand all
261 items = [ 260 items = [
262 ('~ ', 'a'), 261 ('~ ', 'a'),
263 ] 262 ]
264 gclient_scm.scm.SVN.CaptureStatus( 263 gclient_scm.scm.SVN.CaptureStatus(
265 None, self.base_path, no_ignore=False).AndReturn(items) 264 None, self.base_path, no_ignore=False).AndReturn(items)
266 file_path = join(self.base_path, 'a') 265 file_path = join(self.base_path, 'a')
267 gclient_scm.os.path.exists(file_path).AndReturn(True) 266 gclient_scm.os.path.exists(file_path).AndReturn(True)
268 gclient_scm.os.path.isfile(file_path).AndReturn(False) 267 gclient_scm.os.path.isfile(file_path).AndReturn(False)
269 gclient_scm.os.path.islink(file_path).AndReturn(False) 268 gclient_scm.os.path.islink(file_path).AndReturn(False)
270 gclient_scm.os.path.isdir(file_path).AndReturn(True) 269 gclient_scm.os.path.isdir(file_path).AndReturn(True)
271 gclient_scm.gclient_utils.RemoveDirectory(file_path) 270 gclient_scm.gclient_utils.rmtree(file_path)
272 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 271 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
273 gclient_scm.scm.SVN.RunAndGetFileList( 272 gclient_scm.scm.SVN.RunAndGetFileList(
274 options.verbose, 273 options.verbose,
275 ['update', '--revision', 'BASE', '--ignore-externals'], 274 ['update', '--revision', 'BASE', '--ignore-externals'],
276 cwd=self.base_path, 275 cwd=self.base_path,
277 file_list=mox.IgnoreArg()) 276 file_list=mox.IgnoreArg())
278 277
279 self.mox.ReplayAll() 278 self.mox.ReplayAll()
280 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 279 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
281 relpath=self.relpath) 280 relpath=self.relpath)
282 file_list2 = [] 281 file_list2 = []
283 scm.revert(options, self.args, file_list2) 282 scm.revert(options, self.args, file_list2)
284 self.checkstdout(('%s\n' % file_path)) 283 self.checkstdout(('%s\n' % file_path))
285 284
286 def testRevertDot(self): 285 def testRevertDot(self):
287 self.mox.StubOutWithMock(gclient_scm.SVNWrapper, 'update') 286 self.mox.StubOutWithMock(gclient_scm.SVNWrapper, 'update')
288 options = self.Options(verbose=True) 287 options = self.Options(verbose=True)
289 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 288 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
290 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) 289 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True)
291 items = [ 290 items = [
292 ('~ ', '.'), 291 ('~ ', '.'),
293 ] 292 ]
294 gclient_scm.scm.SVN.CaptureStatus( 293 gclient_scm.scm.SVN.CaptureStatus(
295 None, self.base_path, no_ignore=False).AndReturn(items) 294 None, self.base_path, no_ignore=False).AndReturn(items)
296 # RemoveDirectory() doesn't work on path ending with '.', like 'foo/.'. 295 # gclient_utils.rmtree() doesn't work on path ending with '.', like 'foo/.'.
297 file_path = self.base_path 296 file_path = self.base_path
298 gclient_scm.os.path.exists(file_path).AndReturn(True) 297 gclient_scm.os.path.exists(file_path).AndReturn(True)
299 gclient_scm.os.path.isfile(file_path).AndReturn(False) 298 gclient_scm.os.path.isfile(file_path).AndReturn(False)
300 gclient_scm.os.path.islink(file_path).AndReturn(False) 299 gclient_scm.os.path.islink(file_path).AndReturn(False)
301 gclient_scm.os.path.isdir(file_path).AndReturn(True) 300 gclient_scm.os.path.isdir(file_path).AndReturn(True)
302 gclient_scm.gclient_utils.RemoveDirectory(file_path) 301 gclient_scm.gclient_utils.rmtree(file_path)
303 # pylint: disable=E1120 302 # pylint: disable=E1120
304 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 303 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
305 gclient_scm.SVNWrapper.update(options, [], ['.']) 304 gclient_scm.SVNWrapper.update(options, [], ['.'])
306 305
307 self.mox.ReplayAll() 306 self.mox.ReplayAll()
308 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 307 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
309 relpath=self.relpath) 308 relpath=self.relpath)
310 file_list2 = [] 309 file_list2 = []
311 scm.revert(options, self.args, file_list2) 310 scm.revert(options, self.args, file_list2)
312 self.checkstdout(('%s\n' % os.path.join(file_path, '.'))) 311 self.checkstdout(('%s\n' % os.path.join(file_path, '.')))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 455
457 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 456 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
458 ).AndReturn(file_info) 457 ).AndReturn(file_info)
459 458
460 # Confirm that the untracked file is removed. 459 # Confirm that the untracked file is removed.
461 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path 460 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path
462 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 461 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
463 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True) 462 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
464 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False) 463 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
465 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False) 464 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False)
466 gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir')) 465 gclient_scm.gclient_utils.rmtree(join(self.base_path, 'dir'))
467 466
468 self.mox.ReplayAll() 467 self.mox.ReplayAll()
469 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 468 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
470 relpath=self.relpath) 469 relpath=self.relpath)
471 files_list = [] 470 files_list = []
472 scm.update(options, (), files_list) 471 scm.update(options, (), files_list)
473 self.checkstdout( 472 self.checkstdout(
474 ('\n_____ %s at 42\n' 473 ('\n_____ %s at 42\n'
475 '\n_____ removing unversioned directory dir\n') % self.relpath) 474 '\n_____ removing unversioned directory dir\n') % self.relpath)
476 475
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1181
1183 if __name__ == '__main__': 1182 if __name__ == '__main__':
1184 if '-v' in sys.argv: 1183 if '-v' in sys.argv:
1185 logging.basicConfig( 1184 logging.basicConfig(
1186 level=logging.DEBUG, 1185 level=logging.DEBUG,
1187 format='%(asctime).19s %(levelname)s %(filename)s:' 1186 format='%(asctime).19s %(levelname)s %(filename)s:'
1188 '%(lineno)s %(message)s') 1187 '%(lineno)s %(message)s')
1189 unittest.main() 1188 unittest.main()
1190 1189
1191 # vim: ts=2:sw=2:tw=80:et: 1190 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « testing_support/trial_dir.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698