| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2008-2009 Google Inc. All Rights Reserved. | 3 # Copyright 2008-2009 Google Inc. All Rights Reserved. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with 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 | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 def setUp(self): | 42 def setUp(self): |
| 43 gclient_test.GClientBaseTestCase.setUp(self) | 43 gclient_test.GClientBaseTestCase.setUp(self) |
| 44 self.root_dir = self.Dir() | 44 self.root_dir = self.Dir() |
| 45 self.args = self.Args() | 45 self.args = self.Args() |
| 46 self.url = self.Url() | 46 self.url = self.Url() |
| 47 self.relpath = 'asf' | 47 self.relpath = 'asf' |
| 48 | 48 |
| 49 def testDir(self): | 49 def testDir(self): |
| 50 members = [ | 50 members = [ |
| 51 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', | 51 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
| 52 'pack', 'relpath', 'revert', 'runhooks', 'scm_name', 'status', | 52 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', |
| 53 'update', 'url', | 53 'update', 'url', |
| 54 ] | 54 ] |
| 55 | 55 |
| 56 # If you add a member, be sure to add the relevant test! | 56 # If you add a member, be sure to add the relevant test! |
| 57 self.compareMembers(self._scm_wrapper(), members) | 57 self.compareMembers(self._scm_wrapper(), members) |
| 58 | 58 |
| 59 def testUnsupportedSCM(self): | 59 def testUnsupportedSCM(self): |
| 60 args = [self.url, self.root_dir, self.relpath] | 60 args = [self.url, self.root_dir, self.relpath] |
| 61 kwargs = {'scm_name' : 'foo'} | 61 kwargs = {'scm_name' : 'foo'} |
| 62 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs | 62 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 'Revision': 35, | 316 'Revision': 35, |
| 317 'Repository Root': self.root_dir, | 317 'Repository Root': self.root_dir, |
| 318 'Schedule': 'normal', | 318 'Schedule': 'normal', |
| 319 'Copied From URL': None, | 319 'Copied From URL': None, |
| 320 'Copied From Rev': None, | 320 'Copied From Rev': None, |
| 321 'Path': '.', | 321 'Path': '.', |
| 322 'Node Kind': 'dir', | 322 'Node Kind': 'dir', |
| 323 } | 323 } |
| 324 self.assertEqual(file_info, expected) | 324 self.assertEqual(file_info, expected) |
| 325 | 325 |
| 326 def testRevinfo(self): |
| 327 options = self.Options(verbose=False) |
| 328 xml_text = """<?xml version="1.0"?> |
| 329 <info> |
| 330 <entry |
| 331 kind="dir" |
| 332 path="." |
| 333 revision="35"> |
| 334 <url>%s</url> |
| 335 <repository> |
| 336 <root>%s</root> |
| 337 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
| 338 </repository> |
| 339 <wc-info> |
| 340 <schedule>normal</schedule> |
| 341 <depth>infinity</depth> |
| 342 </wc-info> |
| 343 <commit |
| 344 revision="35"> |
| 345 <author>maruel</author> |
| 346 <date>2008-12-04T20:12:19.685120Z</date> |
| 347 </commit> |
| 348 </entry> |
| 349 </info> |
| 350 """ % (self.url, self.root_dir) |
| 351 gclient_scm.CaptureSVN(['info', '--xml', |
| 352 self.url], os.getcwd()).AndReturn(xml_text) |
| 353 self.mox.ReplayAll() |
| 354 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 355 relpath=self.relpath) |
| 356 rev_info = scm.revinfo(options, self.args, None) |
| 357 self.assertEqual(rev_info, '35') |
| 358 |
| 326 | 359 |
| 327 class GitWrapperTestCase(gclient_test.GClientBaseTestCase): | 360 class GitWrapperTestCase(gclient_test.GClientBaseTestCase): |
| 328 class OptionsObject(object): | 361 class OptionsObject(object): |
| 329 def __init__(self, test_case, verbose=False, revision=None): | 362 def __init__(self, test_case, verbose=False, revision=None): |
| 330 self.verbose = verbose | 363 self.verbose = verbose |
| 331 self.revision = revision | 364 self.revision = revision |
| 332 self.manually_grab_svn_rev = True | 365 self.manually_grab_svn_rev = True |
| 333 self.deps_os = None | 366 self.deps_os = None |
| 334 self.force = False | 367 self.force = False |
| 335 self.nohooks = False | 368 self.nohooks = False |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 except WindowsError: | 422 except WindowsError: |
| 390 # git is not available, skip this test. | 423 # git is not available, skip this test. |
| 391 return False | 424 return False |
| 392 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, | 425 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, |
| 393 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 426 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 394 cwd=path).communicate(input=git_import) | 427 cwd=path).communicate(input=git_import) |
| 395 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, | 428 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, |
| 396 stderr=subprocess.STDOUT, cwd=path).communicate() | 429 stderr=subprocess.STDOUT, cwd=path).communicate() |
| 397 return True | 430 return True |
| 398 | 431 |
| 399 def GetGitRev(self, path): | |
| 400 return subprocess.Popen(['git', 'rev-parse', 'HEAD'], | |
| 401 stdout=subprocess.PIPE, | |
| 402 stderr=subprocess.STDOUT, | |
| 403 cwd=path).communicate()[0].strip() | |
| 404 | |
| 405 def setUp(self): | 432 def setUp(self): |
| 406 gclient_test.BaseTestCase.setUp(self) | 433 gclient_test.BaseTestCase.setUp(self) |
| 407 self.args = self.Args() | 434 self.args = self.Args() |
| 408 self.url = 'git://foo' | 435 self.url = 'git://foo' |
| 409 self.root_dir = tempfile.mkdtemp() | 436 self.root_dir = tempfile.mkdtemp() |
| 410 self.relpath = '.' | 437 self.relpath = '.' |
| 411 self.base_path = os.path.join(self.root_dir, self.relpath) | 438 self.base_path = os.path.join(self.root_dir, self.relpath) |
| 412 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 439 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 413 | 440 |
| 414 def tearDown(self): | 441 def tearDown(self): |
| 415 shutil.rmtree(self.root_dir) | 442 shutil.rmtree(self.root_dir) |
| 416 gclient_test.BaseTestCase.tearDown(self) | 443 gclient_test.BaseTestCase.tearDown(self) |
| 417 | 444 |
| 418 def testDir(self): | 445 def testDir(self): |
| 419 members = [ | 446 members = [ |
| 420 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', | 447 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
| 421 'relpath', 'revert', 'runhooks', 'scm_name', 'status', 'update', 'url', | 448 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', |
| 449 'update', 'url', |
| 422 ] | 450 ] |
| 423 | 451 |
| 424 # If you add a member, be sure to add the relevant test! | 452 # If you add a member, be sure to add the relevant test! |
| 425 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) | 453 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
| 426 | 454 |
| 427 def testRevertMissing(self): | 455 def testRevertMissing(self): |
| 428 if not self.enabled: | 456 if not self.enabled: |
| 429 return | 457 return |
| 430 options = self.Options() | 458 options = self.Options() |
| 431 file_path = os.path.join(self.base_path, 'a') | 459 file_path = os.path.join(self.base_path, 'a') |
| 432 os.remove(file_path) | 460 os.remove(file_path) |
| 433 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 461 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 434 relpath=self.relpath) | 462 relpath=self.relpath) |
| 435 file_list = [] | 463 file_list = [] |
| 436 scm.revert(options, self.args, file_list) | 464 scm.revert(options, self.args, file_list) |
| 437 self.assertEquals(file_list, [file_path]) | 465 self.assertEquals(file_list, [file_path]) |
| 438 file_list = [] | 466 file_list = [] |
| 439 scm.diff(options, self.args, file_list) | 467 scm.diff(options, self.args, file_list) |
| 440 self.assertEquals(file_list, []) | 468 self.assertEquals(file_list, []) |
| 441 | 469 |
| 442 def testRevertNone(self): | 470 def testRevertNone(self): |
| 443 if not self.enabled: | 471 if not self.enabled: |
| 444 return | 472 return |
| 445 options = self.Options() | 473 options = self.Options() |
| 446 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 474 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 447 relpath=self.relpath) | 475 relpath=self.relpath) |
| 448 file_list = [] | 476 file_list = [] |
| 449 scm.revert(options, self.args, file_list) | 477 scm.revert(options, self.args, file_list) |
| 450 self.assertEquals(file_list, []) | 478 self.assertEquals(file_list, []) |
| 451 self.assertEquals(self.GetGitRev(self.base_path), | 479 self.assertEquals(scm.revinfo(options, self.args, None), |
| 452 '069c602044c5388d2d15c3f875b057c852003458') | 480 '069c602044c5388d2d15c3f875b057c852003458') |
| 453 | 481 |
| 454 | 482 |
| 455 def testRevertModified(self): | 483 def testRevertModified(self): |
| 456 if not self.enabled: | 484 if not self.enabled: |
| 457 return | 485 return |
| 458 options = self.Options() | 486 options = self.Options() |
| 459 file_path = os.path.join(self.base_path, 'a') | 487 file_path = os.path.join(self.base_path, 'a') |
| 460 open(file_path, 'a').writelines('touched\n') | 488 open(file_path, 'a').writelines('touched\n') |
| 461 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 489 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 462 relpath=self.relpath) | 490 relpath=self.relpath) |
| 463 file_list = [] | 491 file_list = [] |
| 464 scm.revert(options, self.args, file_list) | 492 scm.revert(options, self.args, file_list) |
| 465 self.assertEquals(file_list, [file_path]) | 493 self.assertEquals(file_list, [file_path]) |
| 466 file_list = [] | 494 file_list = [] |
| 467 scm.diff(options, self.args, file_list) | 495 scm.diff(options, self.args, file_list) |
| 468 self.assertEquals(file_list, []) | 496 self.assertEquals(file_list, []) |
| 469 self.assertEquals(self.GetGitRev(self.base_path), | 497 self.assertEquals(scm.revinfo(options, self.args, None), |
| 470 '069c602044c5388d2d15c3f875b057c852003458') | 498 '069c602044c5388d2d15c3f875b057c852003458') |
| 471 | 499 |
| 472 def testRevertNew(self): | 500 def testRevertNew(self): |
| 473 if not self.enabled: | 501 if not self.enabled: |
| 474 return | 502 return |
| 475 options = self.Options() | 503 options = self.Options() |
| 476 file_path = os.path.join(self.base_path, 'c') | 504 file_path = os.path.join(self.base_path, 'c') |
| 477 f = open(file_path, 'w') | 505 f = open(file_path, 'w') |
| 478 f.writelines('new\n') | 506 f.writelines('new\n') |
| 479 f.close() | 507 f.close() |
| 480 subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, | 508 subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, |
| 481 stderr=subprocess.STDOUT, cwd=self.base_path).communicate() | 509 stderr=subprocess.STDOUT, cwd=self.base_path).communicate() |
| 482 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 510 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 483 relpath=self.relpath) | 511 relpath=self.relpath) |
| 484 file_list = [] | 512 file_list = [] |
| 485 scm.revert(options, self.args, file_list) | 513 scm.revert(options, self.args, file_list) |
| 486 self.assertEquals(file_list, [file_path]) | 514 self.assertEquals(file_list, [file_path]) |
| 487 file_list = [] | 515 file_list = [] |
| 488 scm.diff(options, self.args, file_list) | 516 scm.diff(options, self.args, file_list) |
| 489 self.assertEquals(file_list, []) | 517 self.assertEquals(file_list, []) |
| 490 self.assertEquals(self.GetGitRev(self.base_path), | 518 self.assertEquals(scm.revinfo(options, self.args, None), |
| 491 '069c602044c5388d2d15c3f875b057c852003458') | 519 '069c602044c5388d2d15c3f875b057c852003458') |
| 492 | 520 |
| 493 def testStatusNew(self): | 521 def testStatusNew(self): |
| 494 if not self.enabled: | 522 if not self.enabled: |
| 495 return | 523 return |
| 496 options = self.Options() | 524 options = self.Options() |
| 497 file_path = os.path.join(self.base_path, 'a') | 525 file_path = os.path.join(self.base_path, 'a') |
| 498 open(file_path, 'a').writelines('touched\n') | 526 open(file_path, 'a').writelines('touched\n') |
| 499 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 527 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 500 relpath=self.relpath) | 528 relpath=self.relpath) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 526 relpath = 'foo' | 554 relpath = 'foo' |
| 527 base_path = os.path.join(root_dir, relpath) | 555 base_path = os.path.join(root_dir, relpath) |
| 528 url = os.path.join(self.root_dir, self.relpath, '.git') | 556 url = os.path.join(self.root_dir, self.relpath, '.git') |
| 529 try: | 557 try: |
| 530 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, | 558 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
| 531 relpath=relpath) | 559 relpath=relpath) |
| 532 file_list = [] | 560 file_list = [] |
| 533 scm.update(options, (), file_list) | 561 scm.update(options, (), file_list) |
| 534 self.assertEquals(len(file_list), 2) | 562 self.assertEquals(len(file_list), 2) |
| 535 self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) | 563 self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) |
| 536 self.assertEquals(self.GetGitRev(base_path), | 564 self.assertEquals(scm.revinfo(options, (), None), |
| 537 '069c602044c5388d2d15c3f875b057c852003458') | 565 '069c602044c5388d2d15c3f875b057c852003458') |
| 538 finally: | 566 finally: |
| 539 shutil.rmtree(root_dir) | 567 shutil.rmtree(root_dir) |
| 540 | 568 |
| 541 def testUpdateUpdate(self): | 569 def testUpdateUpdate(self): |
| 542 if not self.enabled: | 570 if not self.enabled: |
| 543 return | 571 return |
| 544 options = self.Options() | 572 options = self.Options() |
| 545 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] | 573 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] |
| 546 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 574 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 547 relpath=self.relpath) | 575 relpath=self.relpath) |
| 548 file_list = [] | 576 file_list = [] |
| 549 scm.update(options, (), file_list) | 577 scm.update(options, (), file_list) |
| 550 self.assertEquals(self.GetGitRev(self.base_path), | 578 self.assertEquals(file_list, expected_file_list) |
| 579 self.assertEquals(scm.revinfo(options, (), None), |
| 551 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 580 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 552 | 581 |
| 582 def testRevinfo(self): |
| 583 if not self.enabled: |
| 584 return |
| 585 options = self.Options() |
| 586 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 587 relpath=self.relpath) |
| 588 rev_info = scm.revinfo(options, (), None) |
| 589 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
| 590 |
| 553 | 591 |
| 554 class RunSVNTestCase(gclient_test.BaseTestCase): | 592 class RunSVNTestCase(gclient_test.BaseTestCase): |
| 555 def testRunSVN(self): | 593 def testRunSVN(self): |
| 556 param2 = 'bleh' | 594 param2 = 'bleh' |
| 557 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 595 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') |
| 558 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) | 596 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) |
| 559 self.mox.ReplayAll() | 597 self.mox.ReplayAll() |
| 560 gclient_scm.RunSVN(['foo', 'bar'], param2) | 598 gclient_scm.RunSVN(['foo', 'bar'], param2) |
| 561 | 599 |
| 562 | 600 |
| 563 if __name__ == '__main__': | 601 if __name__ == '__main__': |
| 564 unittest.main() | 602 unittest.main() |
| 565 | 603 |
| 566 # vim: ts=2:sw=2:tw=80:et: | 604 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |