| 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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 committer Alice <alice@example.com> 1253744424 -0700 | 371 committer Alice <alice@example.com> 1253744424 -0700 |
| 372 data 13 | 372 data 13 |
| 373 Personalized | 373 Personalized |
| 374 from :3 | 374 from :3 |
| 375 M 100644 :4 a | 375 M 100644 :4 a |
| 376 M 100644 :5 b | 376 M 100644 :5 b |
| 377 | 377 |
| 378 reset refs/heads/master | 378 reset refs/heads/master |
| 379 from :3 | 379 from :3 |
| 380 """ | 380 """ |
| 381 | |
| 382 def Options(self, *args, **kwargs): | 381 def Options(self, *args, **kwargs): |
| 383 return self.OptionsObject(self, *args, **kwargs) | 382 return self.OptionsObject(self, *args, **kwargs) |
| 384 | 383 |
| 385 def CreateGitRepo(self, git_import, path): | 384 def CreateGitRepo(self, git_import, path): |
| 386 subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, | 385 try: |
| 387 stderr=subprocess.STDOUT, cwd=path).communicate() | 386 subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, |
| 387 stderr=subprocess.STDOUT, cwd=path).communicate() |
| 388 except WindowsError: |
| 389 # git is not available, skip this test. |
| 390 return False |
| 388 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, | 391 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, |
| 389 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 392 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 390 cwd=path).communicate(input=git_import) | 393 cwd=path).communicate(input=git_import) |
| 391 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, | 394 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, |
| 392 stderr=subprocess.STDOUT, cwd=path).communicate() | 395 stderr=subprocess.STDOUT, cwd=path).communicate() |
| 396 return True |
| 393 | 397 |
| 394 def GetGitRev(self, path): | 398 def GetGitRev(self, path): |
| 395 return subprocess.Popen(['git', 'rev-parse', 'HEAD'], | 399 return subprocess.Popen(['git', 'rev-parse', 'HEAD'], |
| 396 stdout=subprocess.PIPE, | 400 stdout=subprocess.PIPE, |
| 397 stderr=subprocess.STDOUT, | 401 stderr=subprocess.STDOUT, |
| 398 cwd=path).communicate()[0].strip() | 402 cwd=path).communicate()[0].strip() |
| 399 | 403 |
| 400 def setUp(self): | 404 def setUp(self): |
| 401 gclient_test.BaseTestCase.setUp(self) | 405 gclient_test.BaseTestCase.setUp(self) |
| 402 self.args = self.Args() | 406 self.args = self.Args() |
| 403 self.url = 'git://foo' | 407 self.url = 'git://foo' |
| 404 self.root_dir = tempfile.mkdtemp() | 408 self.root_dir = tempfile.mkdtemp() |
| 405 self.relpath = '.' | 409 self.relpath = '.' |
| 406 self.base_path = os.path.join(self.root_dir, self.relpath) | 410 self.base_path = os.path.join(self.root_dir, self.relpath) |
| 407 self.CreateGitRepo(self.sample_git_import, self.base_path) | 411 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 408 | 412 |
| 409 def tearDown(self): | 413 def tearDown(self): |
| 410 shutil.rmtree(self.root_dir) | 414 shutil.rmtree(self.root_dir) |
| 411 gclient_test.BaseTestCase.tearDown(self) | 415 gclient_test.BaseTestCase.tearDown(self) |
| 412 | 416 |
| 413 def testDir(self): | 417 def testDir(self): |
| 414 members = [ | 418 members = [ |
| 415 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', | 419 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', |
| 416 'relpath', 'revert', 'runhooks', 'scm_name', 'status', 'update', 'url', | 420 'relpath', 'revert', 'runhooks', 'scm_name', 'status', 'update', 'url', |
| 417 ] | 421 ] |
| 418 | 422 |
| 419 # If you add a member, be sure to add the relevant test! | 423 # If you add a member, be sure to add the relevant test! |
| 420 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) | 424 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
| 421 | 425 |
| 422 def testRevertMissing(self): | 426 def testRevertMissing(self): |
| 427 if not self.enabled: |
| 428 return |
| 423 options = self.Options() | 429 options = self.Options() |
| 424 file_path = os.path.join(self.base_path, 'a') | 430 file_path = os.path.join(self.base_path, 'a') |
| 425 os.remove(file_path) | 431 os.remove(file_path) |
| 426 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 432 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 427 relpath=self.relpath) | 433 relpath=self.relpath) |
| 428 file_list = [] | 434 file_list = [] |
| 429 scm.revert(options, self.args, file_list) | 435 scm.revert(options, self.args, file_list) |
| 430 self.assertEquals(file_list, [file_path]) | 436 self.assertEquals(file_list, [file_path]) |
| 431 file_list = [] | 437 file_list = [] |
| 432 scm.diff(options, self.args, file_list) | 438 scm.diff(options, self.args, file_list) |
| 433 self.assertEquals(file_list, []) | 439 self.assertEquals(file_list, []) |
| 434 | 440 |
| 435 def testRevertNone(self): | 441 def testRevertNone(self): |
| 442 if not self.enabled: |
| 443 return |
| 436 options = self.Options() | 444 options = self.Options() |
| 437 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 445 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 438 relpath=self.relpath) | 446 relpath=self.relpath) |
| 439 file_list = [] | 447 file_list = [] |
| 440 scm.revert(options, self.args, file_list) | 448 scm.revert(options, self.args, file_list) |
| 441 self.assertEquals(file_list, []) | 449 self.assertEquals(file_list, []) |
| 442 self.assertEquals(self.GetGitRev(self.base_path), | 450 self.assertEquals(self.GetGitRev(self.base_path), |
| 443 '069c602044c5388d2d15c3f875b057c852003458') | 451 '069c602044c5388d2d15c3f875b057c852003458') |
| 444 | 452 |
| 445 | 453 |
| 446 def testRevertModified(self): | 454 def testRevertModified(self): |
| 455 if not self.enabled: |
| 456 return |
| 447 options = self.Options() | 457 options = self.Options() |
| 448 file_path = os.path.join(self.base_path, 'a') | 458 file_path = os.path.join(self.base_path, 'a') |
| 449 open(file_path, 'a').writelines('touched\n') | 459 open(file_path, 'a').writelines('touched\n') |
| 450 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 460 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 451 relpath=self.relpath) | 461 relpath=self.relpath) |
| 452 file_list = [] | 462 file_list = [] |
| 453 scm.revert(options, self.args, file_list) | 463 scm.revert(options, self.args, file_list) |
| 454 self.assertEquals(file_list, [file_path]) | 464 self.assertEquals(file_list, [file_path]) |
| 455 file_list = [] | 465 file_list = [] |
| 456 scm.diff(options, self.args, file_list) | 466 scm.diff(options, self.args, file_list) |
| 457 self.assertEquals(file_list, []) | 467 self.assertEquals(file_list, []) |
| 458 self.assertEquals(self.GetGitRev(self.base_path), | 468 self.assertEquals(self.GetGitRev(self.base_path), |
| 459 '069c602044c5388d2d15c3f875b057c852003458') | 469 '069c602044c5388d2d15c3f875b057c852003458') |
| 460 | 470 |
| 461 def testRevertNew(self): | 471 def testRevertNew(self): |
| 472 if not self.enabled: |
| 473 return |
| 462 options = self.Options() | 474 options = self.Options() |
| 463 file_path = os.path.join(self.base_path, 'c') | 475 file_path = os.path.join(self.base_path, 'c') |
| 464 f = open(file_path, 'w') | 476 f = open(file_path, 'w') |
| 465 f.writelines('new\n') | 477 f.writelines('new\n') |
| 466 f.close() | 478 f.close() |
| 467 subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, | 479 subprocess.Popen(['git', 'add', 'c'], stdout=subprocess.PIPE, |
| 468 stderr=subprocess.STDOUT, cwd=self.base_path).communicate() | 480 stderr=subprocess.STDOUT, cwd=self.base_path).communicate() |
| 469 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 481 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 470 relpath=self.relpath) | 482 relpath=self.relpath) |
| 471 file_list = [] | 483 file_list = [] |
| 472 scm.revert(options, self.args, file_list) | 484 scm.revert(options, self.args, file_list) |
| 473 self.assertEquals(file_list, [file_path]) | 485 self.assertEquals(file_list, [file_path]) |
| 474 file_list = [] | 486 file_list = [] |
| 475 scm.diff(options, self.args, file_list) | 487 scm.diff(options, self.args, file_list) |
| 476 self.assertEquals(file_list, []) | 488 self.assertEquals(file_list, []) |
| 477 self.assertEquals(self.GetGitRev(self.base_path), | 489 self.assertEquals(self.GetGitRev(self.base_path), |
| 478 '069c602044c5388d2d15c3f875b057c852003458') | 490 '069c602044c5388d2d15c3f875b057c852003458') |
| 479 | 491 |
| 480 def testStatusNew(self): | 492 def testStatusNew(self): |
| 493 if not self.enabled: |
| 494 return |
| 481 options = self.Options() | 495 options = self.Options() |
| 482 file_path = os.path.join(self.base_path, 'a') | 496 file_path = os.path.join(self.base_path, 'a') |
| 483 open(file_path, 'a').writelines('touched\n') | 497 open(file_path, 'a').writelines('touched\n') |
| 484 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 498 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 485 relpath=self.relpath) | 499 relpath=self.relpath) |
| 486 file_list = [] | 500 file_list = [] |
| 487 scm.status(options, self.args, file_list) | 501 scm.status(options, self.args, file_list) |
| 488 self.assertEquals(file_list, [file_path]) | 502 self.assertEquals(file_list, [file_path]) |
| 489 | 503 |
| 490 def testStatus2New(self): | 504 def testStatus2New(self): |
| 505 if not self.enabled: |
| 506 return |
| 491 options = self.Options() | 507 options = self.Options() |
| 492 expected_file_list = [] | 508 expected_file_list = [] |
| 493 for f in ['a', 'b']: | 509 for f in ['a', 'b']: |
| 494 file_path = os.path.join(self.base_path, f) | 510 file_path = os.path.join(self.base_path, f) |
| 495 open(file_path, 'a').writelines('touched\n') | 511 open(file_path, 'a').writelines('touched\n') |
| 496 expected_file_list.extend([file_path]) | 512 expected_file_list.extend([file_path]) |
| 497 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 513 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 498 relpath=self.relpath) | 514 relpath=self.relpath) |
| 499 file_list = [] | 515 file_list = [] |
| 500 scm.status(options, self.args, file_list) | 516 scm.status(options, self.args, file_list) |
| 501 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] | 517 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] |
| 502 self.assertEquals(sorted(file_list), expected_file_list) | 518 self.assertEquals(sorted(file_list), expected_file_list) |
| 503 | 519 |
| 504 def testUpdateCheckout(self): | 520 def testUpdateCheckout(self): |
| 521 if not self.enabled: |
| 522 return |
| 505 options = self.Options(verbose=True) | 523 options = self.Options(verbose=True) |
| 506 root_dir = tempfile.mkdtemp() | 524 root_dir = tempfile.mkdtemp() |
| 507 relpath = 'foo' | 525 relpath = 'foo' |
| 508 base_path = os.path.join(root_dir, relpath) | 526 base_path = os.path.join(root_dir, relpath) |
| 509 url = os.path.join(self.root_dir, self.relpath, '.git') | 527 url = os.path.join(self.root_dir, self.relpath, '.git') |
| 510 try: | 528 try: |
| 511 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, | 529 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
| 512 relpath=relpath) | 530 relpath=relpath) |
| 513 file_list = [] | 531 file_list = [] |
| 514 scm.update(options, (), file_list) | 532 scm.update(options, (), file_list) |
| 515 self.assertEquals(len(file_list), 2) | 533 self.assertEquals(len(file_list), 2) |
| 516 self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) | 534 self.assert_(os.path.isfile(os.path.join(base_path, 'a'))) |
| 517 self.assertEquals(self.GetGitRev(base_path), | 535 self.assertEquals(self.GetGitRev(base_path), |
| 518 '069c602044c5388d2d15c3f875b057c852003458') | 536 '069c602044c5388d2d15c3f875b057c852003458') |
| 519 finally: | 537 finally: |
| 520 shutil.rmtree(root_dir) | 538 shutil.rmtree(root_dir) |
| 521 | 539 |
| 522 def testUpdateUpdate(self): | 540 def testUpdateUpdate(self): |
| 541 if not self.enabled: |
| 542 return |
| 523 options = self.Options() | 543 options = self.Options() |
| 524 expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] | 544 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, | 545 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
| 526 relpath=self.relpath) | 546 relpath=self.relpath) |
| 527 file_list = [] | 547 file_list = [] |
| 528 scm.update(options, (), file_list) | 548 scm.update(options, (), file_list) |
| 529 self.assertEquals(self.GetGitRev(self.base_path), | 549 self.assertEquals(self.GetGitRev(self.base_path), |
| 530 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 550 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
| 531 | 551 |
| 532 | 552 |
| 533 class RunSVNTestCase(gclient_test.BaseTestCase): | 553 class RunSVNTestCase(gclient_test.BaseTestCase): |
| 534 def testRunSVN(self): | 554 def testRunSVN(self): |
| 535 param2 = 'bleh' | 555 param2 = 'bleh' |
| 536 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 556 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') |
| 537 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) | 557 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) |
| 538 self.mox.ReplayAll() | 558 self.mox.ReplayAll() |
| 539 gclient_scm.RunSVN(['foo', 'bar'], param2) | 559 gclient_scm.RunSVN(['foo', 'bar'], param2) |
| 540 | 560 |
| 541 | 561 |
| 542 if __name__ == '__main__': | 562 if __name__ == '__main__': |
| 543 unittest.main() | 563 unittest.main() |
| 544 | 564 |
| 545 # vim: ts=2:sw=2:tw=80:et: | 565 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |