OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 git_common.py""" | 6 """Unit tests for git_common.py""" |
7 | 7 |
8 import binascii | 8 import binascii |
9 import collections | 9 import collections |
10 import os | 10 import os |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 self.repo['B'], | 326 self.repo['B'], |
327 self.repo['E'], | 327 self.repo['E'], |
328 self.repo['C'], | 328 self.repo['C'], |
329 ])) | 329 ])) |
330 | 330 |
331 with self.assertRaisesRegexp(Exception, r"one of \('master', 'bananas'\)"): | 331 with self.assertRaisesRegexp(Exception, r"one of \('master', 'bananas'\)"): |
332 self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas') | 332 self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas') |
333 | 333 |
334 def testRepoRoot(self): | 334 def testRepoRoot(self): |
335 def cd_and_repo_root(path): | 335 def cd_and_repo_root(path): |
336 print(os.getcwd()) | |
337 os.chdir(path) | 336 os.chdir(path) |
338 return self.gc.repo_root() | 337 return self.gc.repo_root() |
339 | 338 |
340 self.assertEqual(self.repo.repo_path, self.repo.run(self.gc.repo_root)) | 339 self.assertEqual(self.repo.repo_path, self.repo.run(self.gc.repo_root)) |
341 # cd to a subdirectory; repo_root should still return the root dir. | 340 # cd to a subdirectory; repo_root should still return the root dir. |
342 self.assertEqual(self.repo.repo_path, | 341 self.assertEqual(self.repo.repo_path, |
343 self.repo.run(cd_and_repo_root, 'some/files')) | 342 self.repo.run(cd_and_repo_root, 'some/files')) |
344 | 343 |
345 def testTags(self): | 344 def testTags(self): |
346 self.assertEqual(set(self.repo.run(self.gc.tags)), | 345 self.assertEqual(set(self.repo.run(self.gc.tags)), |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 641 |
643 self.assertEqual(bottomup, [ | 642 self.assertEqual(bottomup, [ |
644 ('branch_L', 'branch_K'), | 643 ('branch_L', 'branch_K'), |
645 ('branch_Z', 'root_X'), | 644 ('branch_Z', 'root_X'), |
646 ('branch_K', 'branch_G'), | 645 ('branch_K', 'branch_G'), |
647 ('branch_G', 'root_A'), | 646 ('branch_G', 'root_A'), |
648 ('root_A', 'root_X'), | 647 ('root_A', 'root_X'), |
649 ]) | 648 ]) |
650 | 649 |
651 def testIsGitTreeDirty(self): | 650 def testIsGitTreeDirty(self): |
652 self.assertEquals(False, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) | 651 retval = [] |
| 652 self.repo.capture_stdio( |
| 653 lambda: retval.append(self.repo.run(self.gc.is_dirty_git_tree, 'foo'))) |
| 654 |
| 655 self.assertEquals(False, retval[0]) |
653 self.repo.open('test.file', 'w').write('test data') | 656 self.repo.open('test.file', 'w').write('test data') |
654 self.repo.git('add', 'test.file') | 657 self.repo.git('add', 'test.file') |
655 self.assertEquals(True, self.repo.run(self.gc.is_dirty_git_tree, 'foo')) | 658 |
| 659 retval = [] |
| 660 self.repo.capture_stdio( |
| 661 lambda: retval.append(self.repo.run(self.gc.is_dirty_git_tree, 'foo'))) |
| 662 self.assertEquals(True, retval[0]) |
656 | 663 |
657 def testSquashBranch(self): | 664 def testSquashBranch(self): |
658 self.repo.git('checkout', 'branch_K') | 665 self.repo.git('checkout', 'branch_K') |
659 | 666 |
660 self.assertEquals(True, self.repo.run(self.gc.squash_current_branch, | 667 self.assertEquals(True, self.repo.run(self.gc.squash_current_branch, |
661 'cool message')) | 668 'cool message')) |
662 | 669 |
663 lines = ['cool message', ''] | 670 lines = ['cool message', ''] |
664 for l in 'HIJK': | 671 for l in 'HIJK': |
665 lines.extend((self.repo[l], l, '')) | 672 lines.extend((self.repo[l], l, '')) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 def setUp(self): | 895 def setUp(self): |
889 self._tempdir = tempfile.mkdtemp() | 896 self._tempdir = tempfile.mkdtemp() |
890 | 897 |
891 def tearDown(self): | 898 def tearDown(self): |
892 shutil.rmtree(self._tempdir) | 899 shutil.rmtree(self._tempdir) |
893 | 900 |
894 REPO_SCHEMA = """ | 901 REPO_SCHEMA = """ |
895 A | 902 A |
896 """ | 903 """ |
897 | 904 |
| 905 @unittest.skipIf(not hasattr(os, 'symlink'), "OS doesn't support symlink") |
898 def testMakeWorkdir(self): | 906 def testMakeWorkdir(self): |
899 if not hasattr(os, 'symlink'): | |
900 return | |
901 | |
902 workdir = os.path.join(self._tempdir, 'workdir') | 907 workdir = os.path.join(self._tempdir, 'workdir') |
903 self.gc.make_workdir(os.path.join(self.repo.repo_path, '.git'), | 908 self.gc.make_workdir(os.path.join(self.repo.repo_path, '.git'), |
904 os.path.join(workdir, '.git')) | 909 os.path.join(workdir, '.git')) |
905 EXPECTED_LINKS = [ | 910 EXPECTED_LINKS = [ |
906 'config', 'info', 'hooks', 'logs/refs', 'objects', 'refs', | 911 'config', 'info', 'hooks', 'logs/refs', 'objects', 'refs', |
907 ] | 912 ] |
908 for path in EXPECTED_LINKS: | 913 for path in EXPECTED_LINKS: |
909 self.assertTrue(os.path.islink(os.path.join(workdir, '.git', path))) | 914 self.assertTrue(os.path.islink(os.path.join(workdir, '.git', path))) |
910 self.assertEqual(os.path.realpath(os.path.join(workdir, '.git', path)), | 915 self.assertEqual(os.path.realpath(os.path.join(workdir, '.git', path)), |
911 os.path.join(self.repo.repo_path, '.git', path)) | 916 os.path.join(self.repo.repo_path, '.git', path)) |
(...skipping 24 matching lines...) Expand all Loading... |
936 self.repo.show_commit('A', format_string='%cn %ci')) | 941 self.repo.show_commit('A', format_string='%cn %ci')) |
937 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', | 942 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', |
938 self.repo.show_commit('B', format_string='%an %ai')) | 943 self.repo.show_commit('B', format_string='%an %ai')) |
939 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', | 944 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', |
940 self.repo.show_commit('B', format_string='%cn %ci')) | 945 self.repo.show_commit('B', format_string='%cn %ci')) |
941 | 946 |
942 | 947 |
943 if __name__ == '__main__': | 948 if __name__ == '__main__': |
944 sys.exit(coverage_utils.covered_main( | 949 sys.exit(coverage_utils.covered_main( |
945 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) | 950 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) |
OLD | NEW |