| 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 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 13 matching lines...) Expand all Loading... |
| 24 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase | 24 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase |
| 25 from testing_support.super_mox import TestCaseUtils | 25 from testing_support.super_mox import TestCaseUtils |
| 26 | 26 |
| 27 import gclient_scm | 27 import gclient_scm |
| 28 import subprocess2 | 28 import subprocess2 |
| 29 | 29 |
| 30 # Shortcut since this function is used often | 30 # Shortcut since this function is used often |
| 31 join = gclient_scm.os.path.join | 31 join = gclient_scm.os.path.join |
| 32 | 32 |
| 33 | 33 |
| 34 # Access to a protected member XXX of a client class |
| 35 # pylint: disable=W0212 |
| 36 |
| 37 |
| 34 class GCBaseTestCase(object): | 38 class GCBaseTestCase(object): |
| 35 def assertRaisesError(self, msg, fn, *args, **kwargs): | 39 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 36 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 40 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
| 37 # pylint: disable=E1101 | 41 # pylint: disable=E1101 |
| 38 try: | 42 try: |
| 39 fn(*args, **kwargs) | 43 fn(*args, **kwargs) |
| 40 except gclient_scm.gclient_utils.Error, e: | 44 except gclient_scm.gclient_utils.Error, e: |
| 41 self.assertEquals(e.args[0], msg) | 45 self.assertEquals(e.args[0], msg) |
| 42 else: | 46 else: |
| 43 self.fail('%s not raised' % msg) | 47 self.fail('%s not raised' % msg) |
| 44 | 48 |
| 45 | 49 |
| 46 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): | 50 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): |
| 47 def setUp(self): | 51 def setUp(self): |
| 48 SuperMoxTestBase.setUp(self) | 52 SuperMoxTestBase.setUp(self) |
| 49 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') | 53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') |
| 50 self.mox.StubOutWithMock(gclient_scm.gclient_utils, | 54 self.mox.StubOutWithMock(gclient_scm.gclient_utils, |
| 51 'CheckCallAndFilterAndHeader') | 55 'CheckCallAndFilterAndHeader') |
| 52 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') | 56 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') |
| 53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 57 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
| 54 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
| 55 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo | |
| 56 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') | 59 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') |
| 57 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') | 60 self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo') |
| 58 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') | 61 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') |
| 59 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') | 62 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') |
| 60 self.mox.StubOutWithMock(subprocess2, 'communicate') | 63 self.mox.StubOutWithMock(subprocess2, 'communicate') |
| 61 self.mox.StubOutWithMock(subprocess2, 'Popen') | 64 self.mox.StubOutWithMock(subprocess2, 'Popen') |
| 62 self._scm_wrapper = gclient_scm.CreateSCM | 65 self._scm_wrapper = gclient_scm.CreateSCM |
| 63 gclient_scm.scm.SVN.current_version = None | 66 gclient_scm.scm.SVN.current_version = None |
| 64 # Absolute path of the fake checkout directory. | 67 # Absolute path of the fake checkout directory. |
| 65 self.base_path = join(self.root_dir, self.relpath) | 68 self.base_path = join(self.root_dir, self.relpath) |
| 66 | 69 |
| 67 def tearDown(self): | 70 def tearDown(self): |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 'update', options, self.args) | 152 'update', options, self.args) |
| 150 | 153 |
| 151 def testRunCommandUnknown(self): | 154 def testRunCommandUnknown(self): |
| 152 # TODO(maruel): if ever used. | 155 # TODO(maruel): if ever used. |
| 153 pass | 156 pass |
| 154 | 157 |
| 155 def testRevertMissing(self): | 158 def testRevertMissing(self): |
| 156 options = self.Options(verbose=True) | 159 options = self.Options(verbose=True) |
| 157 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 160 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
| 158 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 161 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 159 gclient_scm.scm.SVN.Capture(['--version'] | 162 gclient_scm.scm.SVN.Capture(['--version'], None |
| 160 ).AndReturn('svn, version 1.5.1 (r32289)') | 163 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 161 # It'll to a checkout instead. | 164 # It'll to a checkout instead. |
| 162 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 165 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 163 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 166 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 164 # Checkout. | 167 # Checkout. |
| 165 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 168 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 166 parent = gclient_scm.os.path.dirname(self.base_path) | 169 parent = gclient_scm.os.path.dirname(self.base_path) |
| 167 gclient_scm.os.path.exists(parent).AndReturn(False) | 170 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 168 gclient_scm.os.makedirs(parent) | 171 gclient_scm.os.makedirs(parent) |
| 169 gclient_scm.os.path.exists(parent).AndReturn(True) | 172 gclient_scm.os.path.exists(parent).AndReturn(True) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 190 # Checkout. | 193 # Checkout. |
| 191 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 194 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 192 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 195 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 193 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 196 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 194 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 197 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 195 parent = gclient_scm.os.path.dirname(self.base_path) | 198 parent = gclient_scm.os.path.dirname(self.base_path) |
| 196 gclient_scm.os.path.exists(parent).AndReturn(False) | 199 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 197 gclient_scm.os.makedirs(parent) | 200 gclient_scm.os.makedirs(parent) |
| 198 gclient_scm.os.path.exists(parent).AndReturn(True) | 201 gclient_scm.os.path.exists(parent).AndReturn(True) |
| 199 files_list = self.mox.CreateMockAnything() | 202 files_list = self.mox.CreateMockAnything() |
| 200 gclient_scm.scm.SVN.Capture(['--version']).AndReturn('svn, version 1.6') | 203 gclient_scm.scm.SVN.Capture(['--version'], None |
| 204 ).AndReturn('svn, version 1.6') |
| 201 gclient_scm.scm.SVN.RunAndGetFileList( | 205 gclient_scm.scm.SVN.RunAndGetFileList( |
| 202 options.verbose, | 206 options.verbose, |
| 203 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 207 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
| 204 cwd=self.root_dir, | 208 cwd=self.root_dir, |
| 205 file_list=files_list) | 209 file_list=files_list) |
| 206 | 210 |
| 207 self.mox.ReplayAll() | 211 self.mox.ReplayAll() |
| 208 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 212 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 209 relpath=self.relpath) | 213 relpath=self.relpath) |
| 210 scm.revert(options, self.args, files_list) | 214 scm.revert(options, self.args, files_list) |
| 211 self.checkstdout( | 215 self.checkstdout( |
| 212 '\n_____ %s is not a valid svn checkout, synching instead\n' % | 216 '\n_____ %s is not a valid svn checkout, synching instead\n' % |
| 213 self.relpath) | 217 self.relpath) |
| 214 | 218 |
| 215 def testRevertNone(self): | 219 def testRevertNone(self): |
| 216 options = self.Options(verbose=True) | 220 options = self.Options(verbose=True) |
| 217 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 221 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 218 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | 222 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) |
| 219 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) | 223 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path).AndReturn([]) |
| 220 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 224 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 221 gclient_scm.scm.SVN.RunAndGetFileList( | 225 gclient_scm.scm.SVN.RunAndGetFileList( |
| 222 options.verbose, | 226 options.verbose, |
| 223 ['update', '--revision', 'BASE', '--ignore-externals'], | 227 ['update', '--revision', 'BASE', '--ignore-externals'], |
| 224 cwd=self.base_path, | 228 cwd=self.base_path, |
| 225 file_list=mox.IgnoreArg()) | 229 file_list=mox.IgnoreArg()) |
| 226 | 230 |
| 227 self.mox.ReplayAll() | 231 self.mox.ReplayAll() |
| 228 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 232 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 229 relpath=self.relpath) | 233 relpath=self.relpath) |
| 230 file_list = [] | 234 file_list = [] |
| 231 scm.revert(options, self.args, file_list) | 235 scm.revert(options, self.args, file_list) |
| 232 | 236 |
| 233 def testRevertDirectory(self): | 237 def testRevertDirectory(self): |
| 234 options = self.Options(verbose=True) | 238 options = self.Options(verbose=True) |
| 235 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 239 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 236 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | 240 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) |
| 237 items = [ | 241 items = [ |
| 238 ('~ ', 'a'), | 242 ('~ ', 'a'), |
| 239 ] | 243 ] |
| 240 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 244 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path).AndReturn(items) |
| 241 file_path = join(self.base_path, 'a') | 245 file_path = join(self.base_path, 'a') |
| 242 gclient_scm.os.path.exists(file_path).AndReturn(True) | 246 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 243 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 247 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 244 gclient_scm.os.path.islink(file_path).AndReturn(False) | 248 gclient_scm.os.path.islink(file_path).AndReturn(False) |
| 245 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 249 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 246 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 250 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
| 247 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 251 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 248 gclient_scm.scm.SVN.RunAndGetFileList( | 252 gclient_scm.scm.SVN.RunAndGetFileList( |
| 249 options.verbose, | 253 options.verbose, |
| 250 ['update', '--revision', 'BASE', '--ignore-externals'], | 254 ['update', '--revision', 'BASE', '--ignore-externals'], |
| 251 cwd=self.base_path, | 255 cwd=self.base_path, |
| 252 file_list=mox.IgnoreArg()) | 256 file_list=mox.IgnoreArg()) |
| 253 | 257 |
| 254 self.mox.ReplayAll() | 258 self.mox.ReplayAll() |
| 255 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 259 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 256 relpath=self.relpath) | 260 relpath=self.relpath) |
| 257 file_list2 = [] | 261 file_list2 = [] |
| 258 scm.revert(options, self.args, file_list2) | 262 scm.revert(options, self.args, file_list2) |
| 259 self.checkstdout(('%s\n' % file_path)) | 263 self.checkstdout(('%s\n' % file_path)) |
| 260 | 264 |
| 261 def testRevertDot(self): | 265 def testRevertDot(self): |
| 262 self.mox.StubOutWithMock(gclient_scm.SVNWrapper, 'update') | 266 self.mox.StubOutWithMock(gclient_scm.SVNWrapper, 'update') |
| 263 options = self.Options(verbose=True) | 267 options = self.Options(verbose=True) |
| 264 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 268 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
| 265 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | 269 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) |
| 266 items = [ | 270 items = [ |
| 267 ('~ ', '.'), | 271 ('~ ', '.'), |
| 268 ] | 272 ] |
| 269 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 273 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path).AndReturn(items) |
| 270 file_path = join(self.base_path, '.') | 274 file_path = join(self.base_path, '.') |
| 271 gclient_scm.os.path.exists(file_path).AndReturn(True) | 275 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 272 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 276 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 273 gclient_scm.os.path.islink(file_path).AndReturn(False) | 277 gclient_scm.os.path.islink(file_path).AndReturn(False) |
| 274 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 278 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 275 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 279 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
| 276 # pylint: disable=E1120 | 280 # pylint: disable=E1120 |
| 277 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 281 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
| 278 gclient_scm.SVNWrapper.update(options, [], ['.']) | 282 gclient_scm.SVNWrapper.update(options, [], ['.']) |
| 279 | 283 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 310 file_info.revision = 42 | 314 file_info.revision = 42 |
| 311 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 315 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 312 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 316 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 313 # Checkout. | 317 # Checkout. |
| 314 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 318 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
| 315 parent = gclient_scm.os.path.dirname(self.base_path) | 319 parent = gclient_scm.os.path.dirname(self.base_path) |
| 316 gclient_scm.os.path.exists(parent).AndReturn(False) | 320 gclient_scm.os.path.exists(parent).AndReturn(False) |
| 317 gclient_scm.os.makedirs(parent) | 321 gclient_scm.os.makedirs(parent) |
| 318 gclient_scm.os.path.exists(parent).AndReturn(True) | 322 gclient_scm.os.path.exists(parent).AndReturn(True) |
| 319 files_list = self.mox.CreateMockAnything() | 323 files_list = self.mox.CreateMockAnything() |
| 320 gclient_scm.scm.SVN.Capture(['--version'] | 324 gclient_scm.scm.SVN.Capture(['--version'], None |
| 321 ).AndReturn('svn, version 1.5.1 (r32289)') | 325 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 322 gclient_scm.scm.SVN.RunAndGetFileList( | 326 gclient_scm.scm.SVN.RunAndGetFileList( |
| 323 options.verbose, | 327 options.verbose, |
| 324 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 328 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], |
| 325 cwd=self.root_dir, | 329 cwd=self.root_dir, |
| 326 file_list=files_list) | 330 file_list=files_list) |
| 327 self.mox.ReplayAll() | 331 self.mox.ReplayAll() |
| 328 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 332 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 329 relpath=self.relpath) | 333 relpath=self.relpath) |
| 330 scm.update(options, (), files_list) | 334 scm.update(options, (), files_list) |
| 331 | 335 |
| 332 def testUpdateUpdate(self): | 336 def testUpdateUpdate(self): |
| 333 options = self.Options(verbose=True) | 337 options = self.Options(verbose=True) |
| 334 options.force = True | 338 options.force = True |
| 335 options.nohooks = False | 339 options.nohooks = False |
| 336 file_info = { | 340 file_info = { |
| 337 'Repository Root': 'blah', | 341 'Repository Root': 'blah', |
| 338 'URL': self.url, | 342 'URL': self.url, |
| 339 'UUID': 'ABC', | 343 'UUID': 'ABC', |
| 340 'Revision': 42, | 344 'Revision': 42, |
| 341 } | 345 } |
| 342 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 346 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 343 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 347 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 344 | 348 |
| 345 # Verify no locked files. | 349 # Verify no locked files. |
| 346 dotted_path = join(self.base_path, '.') | 350 dotted_path = join(self.base_path, '.') |
| 347 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) | 351 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
| 348 | 352 |
| 349 # Checkout or update. | 353 # Checkout or update. |
| 350 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 354 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 351 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) | 355 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 352 # Cheat a bit here. | 356 # Cheat a bit here. |
| 353 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 357 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 358 ).AndReturn(file_info) |
| 354 additional_args = [] | 359 additional_args = [] |
| 355 if options.manually_grab_svn_rev: | 360 if options.manually_grab_svn_rev: |
| 356 additional_args = ['--revision', str(file_info['Revision'])] | 361 additional_args = ['--revision', str(file_info['Revision'])] |
| 357 gclient_scm.scm.SVN.Capture(['--version'] | 362 gclient_scm.scm.SVN.Capture(['--version'], None |
| 358 ).AndReturn('svn, version 1.5.1 (r32289)') | 363 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 359 additional_args.extend(['--force', '--ignore-externals']) | 364 additional_args.extend(['--force', '--ignore-externals']) |
| 360 files_list = [] | 365 files_list = [] |
| 361 gclient_scm.scm.SVN.RunAndGetFileList( | 366 gclient_scm.scm.SVN.RunAndGetFileList( |
| 362 options.verbose, | 367 options.verbose, |
| 363 ['update', self.base_path] + additional_args, | 368 ['update', self.base_path] + additional_args, |
| 364 cwd=self.root_dir, file_list=files_list) | 369 cwd=self.root_dir, file_list=files_list) |
| 365 | 370 |
| 366 self.mox.ReplayAll() | 371 self.mox.ReplayAll() |
| 367 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 372 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 368 relpath=self.relpath) | 373 relpath=self.relpath) |
| 369 scm.update(options, (), files_list) | 374 scm.update(options, (), files_list) |
| 370 | 375 |
| 371 def testUpdateSingleCheckout(self): | 376 def testUpdateSingleCheckout(self): |
| 372 options = self.Options(verbose=True) | 377 options = self.Options(verbose=True) |
| 373 file_info = { | 378 file_info = { |
| 374 'URL': self.url, | 379 'URL': self.url, |
| 375 'Revision': 42, | 380 'Revision': 42, |
| 376 } | 381 } |
| 377 | 382 |
| 378 # Checks to make sure that we support svn co --depth. | 383 # Checks to make sure that we support svn co --depth. |
| 379 gclient_scm.scm.SVN.current_version = None | 384 gclient_scm.scm.SVN.current_version = None |
| 380 gclient_scm.scm.SVN.Capture(['--version'] | 385 gclient_scm.scm.SVN.Capture(['--version'], None |
| 381 ).AndReturn('svn, version 1.5.1 (r32289)') | 386 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 382 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) | 387 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) |
| 383 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) | 388 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) |
| 384 | 389 |
| 385 # Verify no locked files. | 390 # Verify no locked files. |
| 386 dotted_path = join(self.base_path, '.') | 391 dotted_path = join(self.base_path, '.') |
| 387 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) | 392 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) |
| 388 | 393 |
| 389 # When checking out a single file, we issue an svn checkout and svn update. | 394 # When checking out a single file, we issue an svn checkout and svn update. |
| 390 files_list = self.mox.CreateMockAnything() | 395 files_list = self.mox.CreateMockAnything() |
| 391 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 396 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
| 392 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 397 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
| 393 always=True, | 398 always=True, |
| 394 cwd=self.root_dir) | 399 cwd=self.root_dir) |
| 395 gclient_scm.scm.SVN.RunAndGetFileList( | 400 gclient_scm.scm.SVN.RunAndGetFileList( |
| 396 options.verbose, | 401 options.verbose, |
| 397 ['update', 'DEPS', '--ignore-externals'], | 402 ['update', 'DEPS', '--ignore-externals'], |
| 398 cwd=self.base_path, | 403 cwd=self.base_path, |
| 399 file_list=files_list) | 404 file_list=files_list) |
| 400 | 405 |
| 401 # Now we fall back on scm.update(). | 406 # Now we fall back on scm.update(). |
| 402 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 407 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 403 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 408 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 404 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 409 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 405 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) | 410 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) |
| 406 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 411 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 412 ).AndReturn(file_info) |
| 407 | 413 |
| 408 self.mox.ReplayAll() | 414 self.mox.ReplayAll() |
| 409 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 415 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 410 relpath=self.relpath) | 416 relpath=self.relpath) |
| 411 scm.updatesingle(options, ['DEPS'], files_list) | 417 scm.updatesingle(options, ['DEPS'], files_list) |
| 412 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 418 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
| 413 | 419 |
| 414 def testUpdateSingleCheckoutSVN14(self): | 420 def testUpdateSingleCheckoutSVN14(self): |
| 415 options = self.Options(verbose=True) | 421 options = self.Options(verbose=True) |
| 416 | 422 |
| 417 # Checks to make sure that we support svn co --depth. | 423 # Checks to make sure that we support svn co --depth. |
| 418 gclient_scm.scm.SVN.current_version = None | 424 gclient_scm.scm.SVN.current_version = None |
| 419 gclient_scm.scm.SVN.Capture(['--version'] | 425 gclient_scm.scm.SVN.Capture(['--version'], None |
| 420 ).AndReturn('svn, version 1.4.4 (r25188)') | 426 ).AndReturn('svn, version 1.4.4 (r25188)') |
| 421 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 427 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 422 | 428 |
| 423 # When checking out a single file with svn 1.4, we use svn export | 429 # When checking out a single file with svn 1.4, we use svn export |
| 424 files_list = self.mox.CreateMockAnything() | 430 files_list = self.mox.CreateMockAnything() |
| 425 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 431 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
| 426 ['svn', 'export', join(self.url, 'DEPS'), join(self.base_path, 'DEPS')], | 432 ['svn', 'export', join(self.url, 'DEPS'), join(self.base_path, 'DEPS')], |
| 427 always=True, cwd=self.root_dir) | 433 always=True, cwd=self.root_dir) |
| 428 | 434 |
| 429 self.mox.ReplayAll() | 435 self.mox.ReplayAll() |
| 430 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 436 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 431 relpath=self.relpath) | 437 relpath=self.relpath) |
| 432 scm.updatesingle(options, ['DEPS'], files_list) | 438 scm.updatesingle(options, ['DEPS'], files_list) |
| 433 | 439 |
| 434 def testUpdateSingleCheckoutSVNUpgrade(self): | 440 def testUpdateSingleCheckoutSVNUpgrade(self): |
| 435 options = self.Options(verbose=True) | 441 options = self.Options(verbose=True) |
| 436 file_info = { | 442 file_info = { |
| 437 'URL': self.url, | 443 'URL': self.url, |
| 438 'Revision': 42, | 444 'Revision': 42, |
| 439 } | 445 } |
| 440 | 446 |
| 441 # Checks to make sure that we support svn co --depth. | 447 # Checks to make sure that we support svn co --depth. |
| 442 gclient_scm.scm.SVN.current_version = None | 448 gclient_scm.scm.SVN.current_version = None |
| 443 gclient_scm.scm.SVN.Capture(['--version'] | 449 gclient_scm.scm.SVN.Capture(['--version'], None |
| 444 ).AndReturn('svn, version 1.5.1 (r32289)') | 450 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 445 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) | 451 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) |
| 446 # If DEPS already exists, assume we're upgrading from svn1.4, so delete | 452 # If DEPS already exists, assume we're upgrading from svn1.4, so delete |
| 447 # the old DEPS file. | 453 # the old DEPS file. |
| 448 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) | 454 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) |
| 449 gclient_scm.os.remove(join(self.base_path, 'DEPS')) | 455 gclient_scm.os.remove(join(self.base_path, 'DEPS')) |
| 450 | 456 |
| 451 # Verify no locked files. | 457 # Verify no locked files. |
| 452 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) | 458 gclient_scm.scm.SVN.CaptureStatus( |
| 459 None, join(self.base_path, '.')).AndReturn([]) |
| 453 | 460 |
| 454 # When checking out a single file, we issue an svn checkout and svn update. | 461 # When checking out a single file, we issue an svn checkout and svn update. |
| 455 files_list = self.mox.CreateMockAnything() | 462 files_list = self.mox.CreateMockAnything() |
| 456 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 463 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
| 457 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 464 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
| 458 always=True, | 465 always=True, |
| 459 cwd=self.root_dir) | 466 cwd=self.root_dir) |
| 460 gclient_scm.scm.SVN.RunAndGetFileList( | 467 gclient_scm.scm.SVN.RunAndGetFileList( |
| 461 options.verbose, | 468 options.verbose, |
| 462 ['update', 'DEPS', '--ignore-externals'], | 469 ['update', 'DEPS', '--ignore-externals'], |
| 463 cwd=self.base_path, | 470 cwd=self.base_path, |
| 464 file_list=files_list) | 471 file_list=files_list) |
| 465 | 472 |
| 466 # Now we fall back on scm.update(). | 473 # Now we fall back on scm.update(). |
| 467 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 474 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 468 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 475 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 469 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 476 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 470 gclient_scm.scm.SVN.CaptureInfo( | 477 gclient_scm.scm.SVN._CaptureInfo( |
| 471 join(self.base_path, ".")).AndReturn(file_info) | 478 [], join(self.base_path, ".")).AndReturn(file_info) |
| 472 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 479 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 480 ).AndReturn(file_info) |
| 473 | 481 |
| 474 self.mox.ReplayAll() | 482 self.mox.ReplayAll() |
| 475 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 483 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 476 relpath=self.relpath) | 484 relpath=self.relpath) |
| 477 scm.updatesingle(options, ['DEPS'], files_list) | 485 scm.updatesingle(options, ['DEPS'], files_list) |
| 478 self.checkstdout( | 486 self.checkstdout( |
| 479 ('\n_____ %s at 42\n' % self.relpath)) | 487 ('\n_____ %s at 42\n' % self.relpath)) |
| 480 | 488 |
| 481 def testUpdateSingleUpdate(self): | 489 def testUpdateSingleUpdate(self): |
| 482 options = self.Options(verbose=True) | 490 options = self.Options(verbose=True) |
| 483 file_info = { | 491 file_info = { |
| 484 'URL': self.url, | 492 'URL': self.url, |
| 485 'Revision': 42, | 493 'Revision': 42, |
| 486 } | 494 } |
| 487 # Checks to make sure that we support svn co --depth. | 495 # Checks to make sure that we support svn co --depth. |
| 488 gclient_scm.scm.SVN.current_version = None | 496 gclient_scm.scm.SVN.current_version = None |
| 489 gclient_scm.scm.SVN.Capture(['--version'] | 497 gclient_scm.scm.SVN.Capture(['--version'], None |
| 490 ).AndReturn('svn, version 1.5.1 (r32289)') | 498 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 491 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) | 499 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) |
| 492 | 500 |
| 493 # Verify no locked files. | 501 # Verify no locked files. |
| 494 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) | 502 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') |
| 503 ).AndReturn([]) |
| 495 | 504 |
| 496 # Now we fall back on scm.update(). | 505 # Now we fall back on scm.update(). |
| 497 files_list = self.mox.CreateMockAnything() | 506 files_list = self.mox.CreateMockAnything() |
| 498 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 507 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 499 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 508 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
| 500 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 509 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
| 501 gclient_scm.scm.SVN.CaptureInfo( | 510 gclient_scm.scm.SVN._CaptureInfo( |
| 502 join(self.base_path, '.')).AndReturn(file_info) | 511 [], join(self.base_path, '.')).AndReturn(file_info) |
| 503 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 512 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None |
| 513 ).AndReturn(file_info) |
| 504 | 514 |
| 505 self.mox.ReplayAll() | 515 self.mox.ReplayAll() |
| 506 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 516 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 507 relpath=self.relpath) | 517 relpath=self.relpath) |
| 508 scm.updatesingle(options, ['DEPS'], files_list) | 518 scm.updatesingle(options, ['DEPS'], files_list) |
| 509 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 519 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
| 510 | 520 |
| 511 def testUpdateGit(self): | 521 def testUpdateGit(self): |
| 512 options = self.Options(verbose=True) | 522 options = self.Options(verbose=True) |
| 513 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 523 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 sys.stdout.close() | 875 sys.stdout.close() |
| 866 | 876 |
| 867 def testUpdateConflict(self): | 877 def testUpdateConflict(self): |
| 868 if not self.enabled: | 878 if not self.enabled: |
| 869 return | 879 return |
| 870 options = self.Options() | 880 options = self.Options() |
| 871 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 881 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 872 relpath=self.relpath) | 882 relpath=self.relpath) |
| 873 file_path = join(self.base_path, 'b') | 883 file_path = join(self.base_path, 'b') |
| 874 open(file_path, 'w').writelines('conflict\n') | 884 open(file_path, 'w').writelines('conflict\n') |
| 875 # pylint: disable=W0212 | |
| 876 scm._Run(['commit', '-am', 'test'], options) | 885 scm._Run(['commit', '-am', 'test'], options) |
| 877 __builtin__.raw_input = lambda x: 'y' | 886 __builtin__.raw_input = lambda x: 'y' |
| 878 exception = ('Conflict while rebasing this branch.\n' | 887 exception = ('Conflict while rebasing this branch.\n' |
| 879 'Fix the conflict and run gclient again.\n' | 888 'Fix the conflict and run gclient again.\n' |
| 880 'See \'man git-rebase\' for details.\n') | 889 'See \'man git-rebase\' for details.\n') |
| 881 self.assertRaisesError(exception, scm.update, options, (), []) | 890 self.assertRaisesError(exception, scm.update, options, (), []) |
| 882 exception = ('\n____ . at refs/heads/master\n' | 891 exception = ('\n____ . at refs/heads/master\n' |
| 883 '\tYou have unstaged changes.\n' | 892 '\tYou have unstaged changes.\n' |
| 884 '\tPlease commit, stash, or reset.\n') | 893 '\tPlease commit, stash, or reset.\n') |
| 885 self.assertRaisesError(exception, scm.update, options, (), []) | 894 self.assertRaisesError(exception, scm.update, options, (), []) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 | 991 |
| 983 if __name__ == '__main__': | 992 if __name__ == '__main__': |
| 984 if '-v' in sys.argv: | 993 if '-v' in sys.argv: |
| 985 logging.basicConfig( | 994 logging.basicConfig( |
| 986 level=logging.DEBUG, | 995 level=logging.DEBUG, |
| 987 format='%(asctime).19s %(levelname)s %(filename)s:' | 996 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 988 '%(lineno)s %(message)s') | 997 '%(lineno)s %(message)s') |
| 989 unittest.main() | 998 unittest.main() |
| 990 | 999 |
| 991 # vim: ts=2:sw=2:tw=80:et: | 1000 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |