OLD | NEW |
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 BaseTestCase.setUp(self) | 53 BaseTestCase.setUp(self) |
54 self.root_dir = self.Dir() | 54 self.root_dir = self.Dir() |
55 self.args = self.Args() | 55 self.args = self.Args() |
56 self.url = self.Url() | 56 self.url = self.Url() |
57 self.relpath = 'asf' | 57 self.relpath = 'asf' |
58 | 58 |
59 def testDir(self): | 59 def testDir(self): |
60 members = [ | 60 members = [ |
61 'FullUrlForRelativeUrl', 'RunCommand', | 61 'FullUrlForRelativeUrl', 'RunCommand', |
62 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', | 62 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', |
63 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', | 63 'revinfo', 'runhooks', 'scm_name', 'status', 'update', |
| 64 'updatesingle', 'url', |
64 ] | 65 ] |
65 | 66 |
66 # If you add a member, be sure to add the relevant test! | 67 # If you add a member, be sure to add the relevant test! |
67 self.compareMembers(self._scm_wrapper(), members) | 68 self.compareMembers(self._scm_wrapper(), members) |
68 | 69 |
69 def testUnsupportedSCM(self): | 70 def testUnsupportedSCM(self): |
70 args = [self.url, self.root_dir, self.relpath] | 71 args = [self.url, self.root_dir, self.relpath] |
71 kwargs = {'scm_name' : 'foo'} | 72 kwargs = {'scm_name' : 'foo'} |
72 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs | 73 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs |
73 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs) | 74 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs) |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 gclient_scm.scm.SVN.RunAndGetFileList( | 260 gclient_scm.scm.SVN.RunAndGetFileList( |
260 options, | 261 options, |
261 ['update', base_path] + additional_args, | 262 ['update', base_path] + additional_args, |
262 self.root_dir, files_list) | 263 self.root_dir, files_list) |
263 | 264 |
264 self.mox.ReplayAll() | 265 self.mox.ReplayAll() |
265 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 266 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
266 relpath=self.relpath) | 267 relpath=self.relpath) |
267 scm.update(options, (), files_list) | 268 scm.update(options, (), files_list) |
268 | 269 |
| 270 def testUpdateSingleCheckout(self): |
| 271 options = self.Options(verbose=True) |
| 272 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 273 file_info = { |
| 274 'URL': self.url, |
| 275 'Revision': 42, |
| 276 } |
| 277 # When checking out a single file, we issue an svn checkout and svn update. |
| 278 gclient_scm.os.path.exists(base_path).AndReturn(False) |
| 279 files_list = self.mox.CreateMockAnything() |
| 280 gclient_scm.scm.SVN.Run( |
| 281 ['checkout', '--depth', 'empty', self.url, base_path], self.root_dir) |
| 282 gclient_scm.scm.SVN.RunAndGetFileList(options, ['update', 'DEPS'], |
| 283 gclient_scm.os.path.join(self.root_dir, self.relpath), files_list) |
| 284 |
| 285 # Now we fall back on scm.update(). |
| 286 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 287 ).AndReturn(False) |
| 288 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 289 gclient_scm.scm.SVN.CaptureInfo( |
| 290 gclient_scm.os.path.join(base_path, "."), '.' |
| 291 ).AndReturn(file_info) |
| 292 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) |
| 293 print("\n_____ %s at 42" % self.relpath) |
| 294 |
| 295 self.mox.ReplayAll() |
| 296 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 297 relpath=self.relpath) |
| 298 scm.updatesingle(options, ['DEPS'], files_list) |
| 299 |
| 300 def testUpdateSingleUpdate(self): |
| 301 options = self.Options(verbose=True) |
| 302 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 303 file_info = { |
| 304 'URL': self.url, |
| 305 'Revision': 42, |
| 306 } |
| 307 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 308 |
| 309 # Now we fall back on scm.update(). |
| 310 files_list = self.mox.CreateMockAnything() |
| 311 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 312 ).AndReturn(False) |
| 313 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 314 gclient_scm.scm.SVN.CaptureInfo( |
| 315 gclient_scm.os.path.join(base_path, "."), '.' |
| 316 ).AndReturn(file_info) |
| 317 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) |
| 318 print("\n_____ %s at 42" % self.relpath) |
| 319 |
| 320 self.mox.ReplayAll() |
| 321 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 322 relpath=self.relpath) |
| 323 scm.updatesingle(options, ['DEPS'], files_list) |
| 324 |
269 def testUpdateGit(self): | 325 def testUpdateGit(self): |
270 options = self.Options(verbose=True) | 326 options = self.Options(verbose=True) |
271 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 327 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
272 gclient_scm.os.path.exists(file_path).AndReturn(True) | 328 gclient_scm.os.path.exists(file_path).AndReturn(True) |
273 print("________ found .git directory; skipping %s" % self.relpath) | 329 print("________ found .git directory; skipping %s" % self.relpath) |
274 | 330 |
275 self.mox.ReplayAll() | 331 self.mox.ReplayAll() |
276 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, |
277 relpath=self.relpath) | 333 relpath=self.relpath) |
278 file_list = [] | 334 file_list = [] |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 relpath=self.relpath) | 636 relpath=self.relpath) |
581 rev_info = scm.revinfo(options, (), None) | 637 rev_info = scm.revinfo(options, (), None) |
582 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 638 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
583 | 639 |
584 | 640 |
585 if __name__ == '__main__': | 641 if __name__ == '__main__': |
586 import unittest | 642 import unittest |
587 unittest.main() | 643 unittest.main() |
588 | 644 |
589 # vim: ts=2:sw=2:tw=80:et: | 645 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |