msb@chromium.org | e28e498 | 2009-09-25 20:51:45 +0000 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2008-2009 Google Inc. All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """Unit tests for gclient_scm.py.""" |
| 18 | |
| 19 | import os |
| 20 | import shutil |
| 21 | import subprocess |
| 22 | import tempfile |
| 23 | import unittest |
| 24 | |
| 25 | import gclient |
| 26 | import gclient_scm |
| 27 | import gclient_test |
| 28 | import gclient_utils |
| 29 | from super_mox import mox |
| 30 | |
| 31 | |
| 32 | class SVNWrapperTestCase(gclient_test.GClientBaseTestCase): |
| 33 | class OptionsObject(object): |
| 34 | def __init__(self, test_case, verbose=False, revision=None): |
| 35 | self.verbose = verbose |
| 36 | self.revision = revision |
| 37 | self.manually_grab_svn_rev = True |
| 38 | self.deps_os = None |
| 39 | self.force = False |
| 40 | self.nohooks = False |
| 41 | |
| 42 | def setUp(self): |
| 43 | gclient_test.GClientBaseTestCase.setUp(self) |
| 44 | self.root_dir = self.Dir() |
| 45 | self.args = self.Args() |
| 46 | self.url = self.Url() |
| 47 | self.relpath = 'asf' |
| 48 | |
| 49 | def testDir(self): |
| 50 | members = [ |
| 51 | 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
| 52 | 'pack', 'relpath', 'revert', 'runhooks', 'scm_name', 'status', |
| 53 | 'update', 'url', |
| 54 | ] |
| 55 | |
| 56 | # If you add a member, be sure to add the relevant test! |
| 57 | self.compareMembers(self._scm_wrapper(), members) |
| 58 | |
| 59 | def testUnsupportedSCM(self): |
| 60 | args = [self.url, self.root_dir, self.relpath] |
| 61 | kwargs = {'scm_name' : 'foo'} |
| 62 | exception_msg = 'Unsupported scm %(scm_name)s' % kwargs |
| 63 | self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs) |
| 64 | |
| 65 | def testFullUrlForRelativeUrl(self): |
| 66 | self.url = 'svn://a/b/c/d' |
| 67 | |
| 68 | self.mox.ReplayAll() |
| 69 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 70 | relpath=self.relpath) |
| 71 | self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') |
| 72 | |
| 73 | def testRunCommandException(self): |
| 74 | options = self.Options(verbose=False) |
| 75 | file_path = os.path.join(self.root_dir, self.relpath, '.git') |
| 76 | gclient.os.path.exists(file_path).AndReturn(False) |
| 77 | |
| 78 | self.mox.ReplayAll() |
| 79 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 80 | relpath=self.relpath) |
| 81 | exception = "Unsupported argument(s): %s" % ','.join(self.args) |
| 82 | self.assertRaisesError(exception, scm.RunCommand, |
| 83 | 'update', options, self.args) |
| 84 | |
| 85 | def testRunCommandUnknown(self): |
| 86 | # TODO(maruel): if ever used. |
| 87 | pass |
| 88 | |
| 89 | def testRevertMissing(self): |
| 90 | options = self.Options(verbose=True) |
| 91 | base_path = os.path.join(self.root_dir, self.relpath) |
| 92 | gclient.os.path.isdir(base_path).AndReturn(False) |
| 93 | # It'll to a checkout instead. |
| 94 | gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 95 | print("\n_____ %s is missing, synching instead" % self.relpath) |
| 96 | # Checkout. |
| 97 | gclient.os.path.exists(base_path).AndReturn(False) |
| 98 | files_list = self.mox.CreateMockAnything() |
| 99 | gclient_scm.RunSVNAndGetFileList(['checkout', self.url, base_path], |
| 100 | self.root_dir, files_list) |
| 101 | |
| 102 | self.mox.ReplayAll() |
| 103 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 104 | relpath=self.relpath) |
| 105 | scm.revert(options, self.args, files_list) |
| 106 | |
| 107 | def testRevertNone(self): |
| 108 | options = self.Options(verbose=True) |
| 109 | base_path = os.path.join(self.root_dir, self.relpath) |
| 110 | gclient.os.path.isdir(base_path).AndReturn(True) |
| 111 | gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) |
| 112 | gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 113 | base_path, mox.IgnoreArg()) |
| 114 | |
| 115 | self.mox.ReplayAll() |
| 116 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 117 | relpath=self.relpath) |
| 118 | file_list = [] |
| 119 | scm.revert(options, self.args, file_list) |
| 120 | |
| 121 | def testRevert2Files(self): |
| 122 | options = self.Options(verbose=True) |
| 123 | base_path = os.path.join(self.root_dir, self.relpath) |
| 124 | gclient.os.path.isdir(base_path).AndReturn(True) |
| 125 | items = [ |
| 126 | ('M ', 'a'), |
| 127 | ('A ', 'b'), |
| 128 | ] |
| 129 | file_path1 = os.path.join(base_path, 'a') |
| 130 | file_path2 = os.path.join(base_path, 'b') |
| 131 | gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
| 132 | gclient_scm.os.path.exists(file_path1).AndReturn(True) |
| 133 | gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
| 134 | gclient_scm.os.remove(file_path1) |
| 135 | gclient_scm.os.path.exists(file_path2).AndReturn(True) |
| 136 | gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
| 137 | gclient_scm.os.remove(file_path2) |
| 138 | gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 139 | base_path, mox.IgnoreArg()) |
| 140 | print(os.path.join(base_path, 'a')) |
| 141 | print(os.path.join(base_path, 'b')) |
| 142 | |
| 143 | self.mox.ReplayAll() |
| 144 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 145 | relpath=self.relpath) |
| 146 | file_list = [] |
| 147 | scm.revert(options, self.args, file_list) |
| 148 | |
| 149 | def testRevertDirectory(self): |
| 150 | options = self.Options(verbose=True) |
| 151 | base_path = os.path.join(self.root_dir, self.relpath) |
| 152 | gclient.os.path.isdir(base_path).AndReturn(True) |
| 153 | items = [ |
| 154 | ('~ ', 'a'), |
| 155 | ] |
| 156 | gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
| 157 | file_path = os.path.join(base_path, 'a') |
| 158 | print(file_path) |
| 159 | gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 160 | gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 161 | gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 162 | gclient_utils.RemoveDirectory(file_path) |
| 163 | file_list1 = [] |
| 164 | gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 165 | base_path, mox.IgnoreArg()) |
| 166 | |
| 167 | self.mox.ReplayAll() |
| 168 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 169 | relpath=self.relpath) |
| 170 | file_list2 = [] |
| 171 | scm.revert(options, self.args, file_list2) |
| 172 | |
| 173 | def testStatus(self): |
| 174 | options = self.Options(verbose=True) |
| 175 | base_path = os.path.join(self.root_dir, self.relpath) |
| 176 | gclient.os.path.isdir(base_path).AndReturn(True) |
| 177 | gclient_scm.RunSVNAndGetFileList(['status'] + self.args, base_path, |
| 178 | []).AndReturn(None) |
| 179 | |
| 180 | self.mox.ReplayAll() |
| 181 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 182 | relpath=self.relpath) |
| 183 | file_list = [] |
| 184 | self.assertEqual(scm.status(options, self.args, file_list), None) |
| 185 | |
| 186 | |
| 187 | # TODO(maruel): TEST REVISIONS!!! |
| 188 | # TODO(maruel): TEST RELOCATE!!! |
| 189 | def testUpdateCheckout(self): |
| 190 | options = self.Options(verbose=True) |
| 191 | base_path = os.path.join(self.root_dir, self.relpath) |
| 192 | file_info = gclient_utils.PrintableObject() |
| 193 | file_info.root = 'blah' |
| 194 | file_info.url = self.url |
| 195 | file_info.uuid = 'ABC' |
| 196 | file_info.revision = 42 |
| 197 | gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 198 | # Checkout. |
| 199 | gclient.os.path.exists(base_path).AndReturn(False) |
| 200 | files_list = self.mox.CreateMockAnything() |
| 201 | gclient_scm.RunSVNAndGetFileList(['checkout', self.url, base_path], |
| 202 | self.root_dir, files_list) |
| 203 | self.mox.ReplayAll() |
| 204 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 205 | relpath=self.relpath) |
| 206 | scm.update(options, (), files_list) |
| 207 | |
| 208 | def testUpdateUpdate(self): |
| 209 | options = self.Options(verbose=True) |
| 210 | base_path = os.path.join(self.root_dir, self.relpath) |
| 211 | options.force = True |
| 212 | options.nohooks = False |
| 213 | file_info = { |
| 214 | 'Repository Root': 'blah', |
| 215 | 'URL': self.url, |
| 216 | 'UUID': 'ABC', |
| 217 | 'Revision': 42, |
| 218 | } |
| 219 | gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 220 | # Checkout or update. |
| 221 | gclient.os.path.exists(base_path).AndReturn(True) |
| 222 | gclient_scm.CaptureSVNInfo(os.path.join(base_path, "."), '.' |
| 223 | ).AndReturn(file_info) |
| 224 | # Cheat a bit here. |
| 225 | gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) |
| 226 | additional_args = [] |
| 227 | if options.manually_grab_svn_rev: |
| 228 | additional_args = ['--revision', str(file_info['Revision'])] |
| 229 | files_list = [] |
| 230 | gclient_scm.RunSVNAndGetFileList(['update', base_path] + additional_args, |
| 231 | self.root_dir, files_list) |
| 232 | |
| 233 | self.mox.ReplayAll() |
| 234 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 235 | relpath=self.relpath) |
| 236 | scm.update(options, (), files_list) |
| 237 | |
| 238 | def testUpdateGit(self): |
| 239 | options = self.Options(verbose=True) |
| 240 | file_path = os.path.join(self.root_dir, self.relpath, '.git') |
| 241 | gclient.os.path.exists(file_path).AndReturn(True) |
| 242 | print("________ found .git directory; skipping %s" % self.relpath) |
| 243 | |
| 244 | self.mox.ReplayAll() |
| 245 | scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 246 | relpath=self.relpath) |
| 247 | file_list = [] |
| 248 | scm.update(options, self.args, file_list) |
| 249 | |
| 250 | def testGetSVNFileInfo(self): |
| 251 | xml_text = r"""<?xml version="1.0"?> |
| 252 | <info> |
| 253 | <entry kind="file" path="%s" revision="14628"> |
| 254 | <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
| 255 | <repository><root>http://src.chromium.org/svn</root></repository> |
| 256 | <wc-info> |
| 257 | <schedule>add</schedule> |
| 258 | <depth>infinity</depth> |
| 259 | <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-url> |
| 260 | <copy-from-rev>14628</copy-from-rev> |
| 261 | <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
| 262 | </wc-info> |
| 263 | </entry> |
| 264 | </info> |
| 265 | """ % self.url |
| 266 | gclient_scm.CaptureSVN(['info', '--xml', self.url], |
| 267 | '.', True).AndReturn(xml_text) |
| 268 | expected = { |
| 269 | 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
| 270 | 'UUID': None, |
| 271 | 'Repository Root': 'http://src.chromium.org/svn', |
| 272 | 'Schedule': 'add', |
| 273 | 'Copied From URL': |
| 274 | 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', |
| 275 | 'Copied From Rev': '14628', |
| 276 | 'Path': self.url, |
| 277 | 'Revision': 14628, |
| 278 | 'Node Kind': 'file', |
| 279 | } |
| 280 | self.mox.ReplayAll() |
| 281 | file_info = self._CaptureSVNInfo(self.url, '.', True) |
| 282 | self.assertEquals(sorted(file_info.items()), sorted(expected.items())) |
| 283 | |
| 284 | def testCaptureSvnInfo(self): |
| 285 | xml_text = """<?xml version="1.0"?> |
| 286 | <info> |
| 287 | <entry |
| 288 | kind="dir" |
| 289 | path="." |
| 290 | revision="35"> |
| 291 | <url>%s</url> |
| 292 | <repository> |
| 293 | <root>%s</root> |
| 294 | <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
| 295 | </repository> |
| 296 | <wc-info> |
| 297 | <schedule>normal</schedule> |
| 298 | <depth>infinity</depth> |
| 299 | </wc-info> |
| 300 | <commit |
| 301 | revision="35"> |
| 302 | <author>maruel</author> |
| 303 | <date>2008-12-04T20:12:19.685120Z</date> |
| 304 | </commit> |
| 305 | </entry> |
| 306 | </info> |
| 307 | """ % (self.url, self.root_dir) |
| 308 | gclient_scm.CaptureSVN(['info', '--xml', |
| 309 | self.url], '.', True).AndReturn(xml_text) |
| 310 | self.mox.ReplayAll() |
| 311 | file_info = self._CaptureSVNInfo(self.url, '.', True) |
| 312 | expected = { |
| 313 | 'URL': self.url, |
| 314 | 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', |
| 315 | 'Revision': 35, |
| 316 | 'Repository Root': self.root_dir, |
| 317 | 'Schedule': 'normal', |
| 318 | 'Copied From URL': None, |
| 319 | 'Copied From Rev': None, |
| 320 | 'Path': '.', |
| 321 | 'Node Kind': 'dir', |
| 322 | } |
| 323 | self.assertEqual(file_info, expected) |
| 324 | |
| 325 | |
| 326 | class GitWrapperTestCase(gclient_test.GClientBaseTestCase): |
| 327 | class OptionsObject(object): |
| 328 | def __init__(self, test_case, verbose=False, revision=None): |
| 329 | self.verbose = verbose |
| 330 | self.revision = revision |
| 331 | self.manually_grab_svn_rev = True |
| 332 | self.deps_os = None |
| 333 | self.force = False |
| 334 | self.nohooks = False |
| 335 | |
| 336 | sample_git_import = """blob |
| 337 | mark :1 |
| 338 | data 6 |
| 339 | Hello |
| 340 | |
| 341 | blob |
| 342 | mark :2 |
| 343 | data 4 |
| 344 | Bye |
| 345 | |
| 346 | reset refs/heads/master |
| 347 | commit refs/heads/master |
| 348 | mark :3 |
| 349 | author Bob <bob@example.com> 1253744361 -0700 |
| 350 | committer Bob <bob@example.com> 1253744361 -0700 |
| 351 | data 8 |
| 352 | A and B |
| 353 | M 100644 :1 a |
| 354 | M 100644 :2 b |
| 355 | |
| 356 | blob |
| 357 | mark :4 |
| 358 | data 10 |
| 359 | Hello |
| 360 | You |
| 361 | |
| 362 | blob |
| 363 | mark :5 |
| 364 | data 8 |
| 365 | Bye |
| 366 | You |
| 367 | |
| 368 | commit refs/heads/origin |
| 369 | mark :6 |
| 370 | author Alice <alice@example.com> 1253744424 -0700 |
| 371 | committer Alice <alice@example.com> 1253744424 -0700 |
| 372 | data 13 |
| 373 | Personalized |
| 374 | from :3 |
| 375 | M 100644 :4 a |
| 376 | M 100644 :5 b |
| 377 | |
| 378 | reset refs/heads/master |
| 379 | from :3 |
| 380 | """ |
| 381 | |
| 382 | def Options(self, *args, **kwargs): |
| 383 | return self.OptionsObject(self, *args, **kwargs) |
| 384 | |
| 385 | def CreateGitRepo(self, git_import, path): |
| 386 | subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, |
| 387 | stderr=subprocess.STDOUT, cwd=path).communicate() |
| 388 | subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, |
| 389 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 390 | cwd=path).communicate(input=git_import) |
| 391 | subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, |
| 392 | stderr=subprocess.STDOUT, cwd=path).communicate() |
| 393 | |
| 394 | def GetGitRev(self, path): |
| 395 | return subprocess.Popen(['git', 'rev-parse', 'HEAD'], |
| 396 | stdout=subprocess.PIPE, |
| 397 | stderr=subprocess.STDOUT, |
| 398 | cwd=path).communicate()[0].strip() |
| 399 | |
| 400 | def setUp(self): |
| 401 | gclient_test.BaseTestCase.setUp(self) |
| 402 | self.args = self.Args() |
| 403 | self.url = 'git://foo' |
| 404 | self.root_dir = tempfile.mkdtemp() |
| 405 | self.relpath = '.' |
| 406 | self.base_path = os.path.join(self.root_dir, self.relpath) |
| 407 | self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 408 | |
| 409 | def tearDown(self): |
| 410 | shutil.rmtree(self.root_dir) |
| 411 | gclient_test.BaseTestCase.tearDown(self) |
| 412 | |
| 413 | def testDir(self): |
| 414 | members = [ |
| 415 | 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
| 416 | 'relpath', 'revert', 'runhooks', 'scm_name', 'status', 'update', 'url', |
| 417 | ] |
| 418 | |
| 419 | # If you add a member, be sure to add the relevant test! |
| 420 | self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
| 421 | |
| 422 | def testRevertMissing(self): |
| 423 | options = self.Options() |
| 424 | file_path = os.path.join(self.base_path, 'a') |
| 425 | os.remove(file_path) |
| 426 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 427 | relpath=self.relpath) |
| 428 | file_list = [] |
| 429 | scm.revert(options, self.args, file_list) |
| 430 | self.assertEquals(file_list, [file_path]) |
| 431 | file_list = [] |
| 432 | scm.diff(options, self.args, file_list) |
| 433 | self.assertEquals(file_list, []) |
| 434 | |
| 435 | def testRevertNone(self): |
| 436 | options = self.Options() |
| 437 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 438 | relpath=self.relpath) |
| 439 | file_list = [] |
| 440 | scm.revert(options, self.args, file_list) |
| 441 | self.assertEquals(file_list, []) |
| 442 | self.assertEquals(self.GetGitRev(self.base_path), |
| 443 | '069c602044c5388d2d15c3f875b057c852003458') |
| 444 | |
| 445 | |
| 446 | def testRevertModified(self): |
| 447 | options = self.Options() |
| 448 | file_path = os.path.join(self.base_path, 'a') |
| 449 | open(file_path, 'a').writelines('touched\n') |
| 450 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 451 | relpath=self.relpath) |
| 452 | file_list = [] |
| 453 | scm.revert(options, self.args, file_list) |
| 454 | self.assertEquals(file_list, [file_path]) |
| 455 | file_list = [] |
| 456 | scm.diff(options, self.args, file_list) |
| 457 | self.assertEquals(file_list, []) |
| 458 | self.assertEquals(self.GetGitRev(self.base_path), |
| 459 | '069c602044c5388d2d15c3f875b057c852003458') |
| 460 | |
| 461 | def testRevertNew(self): |
| 462 | options = self.Options() |
| 463 | file_path = os.path.join(self.base_path, 'c') |
| 464 | f = open(file_path, 'w') |
| 465 | f.writelines('new\n') |
| 466 | f.close() |
| 467 | subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, |
| 468 | stderr=subprocess.STDOUT, cwd=self.base_path).communicate() |
| 469 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 470 | relpath=self.relpath) |
| 471 | file_list = [] |
| 472 | scm.revert(options, self.args, file_list) |
| 473 | self.assertEquals(file_list, [file_path]) |
| 474 | file_list = [] |
| 475 | scm.diff(options, self.args, file_list) |
| 476 | self.assertEquals(file_list, []) |
| 477 | self.assertEquals(self.GetGitRev(self.base_path), |
| 478 | '069c602044c5388d2d15c3f875b057c852003458') |
| 479 | |
| 480 | def testStatusNew(self): |
| 481 | options = self.Options() |
| 482 | file_path = os.path.join(self.base_path, 'a') |
| 483 | open(file_path, 'a').writelines('touched\n') |
| 484 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 485 | relpath=self.relpath) |
| 486 | file_list = [] |
| 487 | scm.status(options, self.args, file_list) |
| 488 | self.assertEquals(file_list, [file_path]) |
| 489 | |
| 490 | def testStatus2New(self): |
| 491 | options = self.Options() |
| 492 | expected_file_list = [] |
| 493 | for f in ['a', 'b']: |
| 494 | file_path = os.path.join(self.base_path, f) |
| 495 | open(file_path, 'a').writelines('touched\n') |
| 496 | expected_file_list.extend([file_path]) |
| 497 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 498 | relpath=self.relpath) |
| 499 | file_list = [] |
| 500 | scm.status(options, self.args, file_list) |
| 501 | expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] |
| 502 | self.assertEquals(sorted(file_list), expected_file_list) |
| 503 | |
| 504 | def testUpdateCheckout(self): |
| 505 | options = self.Options(verbose=True) |
| 506 | root_dir = tempfile.mkdtemp() |
| 507 | relpath = 'foo' |
| 508 | base_path = os.path.join(root_dir, relpath) |
| 509 | url = os.path.join(self.root_dir, self.relpath, '.git') |
| 510 | try: |
| 511 | scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
| 512 | relpath=relpath) |
| 513 | file_list = [] |
| 514 | scm.update(options, (), file_list) |
| 515 | self.assertEquals(len(file_list), 2) |
| 516 | self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) |
| 517 | self.assertEquals(self.GetGitRev(base_path), |
| 518 | '069c602044c5388d2d15c3f875b057c852003458') |
| 519 | finally: |
| 520 | shutil.rmtree(root_dir) |
| 521 | |
| 522 | def testUpdateUpdate(self): |
| 523 | options = self.Options() |
| 524 | expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] |
| 525 | scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 526 | relpath=self.relpath) |
| 527 | file_list = [] |
| 528 | scm.update(options, (), file_list) |
| 529 | self.assertEquals(self.GetGitRev(self.base_path), |
| 530 | 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 531 | |
| 532 | |
| 533 | class RunSVNTestCase(gclient_test.BaseTestCase): |
| 534 | def testRunSVN(self): |
| 535 | param2 = 'bleh' |
| 536 | self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') |
| 537 | gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) |
| 538 | self.mox.ReplayAll() |
| 539 | gclient_scm.RunSVN(['foo', 'bar'], param2) |
| 540 | |
| 541 | |
| 542 | if __name__ == '__main__': |
| 543 | unittest.main() |
| 544 | |
| 545 | # vim: ts=2:sw=2:tw=80:et: |