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 |
11 import StringIO | 11 import StringIO |
12 from subprocess import Popen, PIPE, STDOUT | 12 from subprocess import Popen, PIPE, STDOUT |
13 import tempfile | 13 import tempfile |
14 import unittest | 14 import unittest |
15 import __builtin__ | 15 import __builtin__ |
16 | 16 |
17 # Fixes include path. | 17 # Fixes include path. |
18 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase | 18 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase |
19 | 19 |
| 20 import sys |
20 import gclient_scm | 21 import gclient_scm |
21 | 22 |
22 # Shortcut since this function is used often | 23 # Shortcut since this function is used often |
23 join = gclient_scm.os.path.join | 24 join = gclient_scm.os.path.join |
24 | 25 |
25 | 26 |
26 class GCBaseTestCase(object): | 27 class GCBaseTestCase(object): |
27 def assertRaisesError(self, msg, fn, *args, **kwargs): | 28 def assertRaisesError(self, msg, fn, *args, **kwargs): |
28 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 29 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
29 try: | 30 try: |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 exception = ('\n____ . at refs/heads/master\n' | 783 exception = ('\n____ . at refs/heads/master\n' |
783 '\tYou have unstaged changes.\n' | 784 '\tYou have unstaged changes.\n' |
784 '\tPlease commit, stash, or reset.\n') | 785 '\tPlease commit, stash, or reset.\n') |
785 self.assertRaisesError(exception, scm.update, options, (), []) | 786 self.assertRaisesError(exception, scm.update, options, (), []) |
786 # The hash always changes. Use a cheap trick. | 787 # The hash always changes. Use a cheap trick. |
787 start = ('\n________ running \'git commit -am test\' in \'%s\'\n' | 788 start = ('\n________ running \'git commit -am test\' in \'%s\'\n' |
788 '[new ') % join(self.root_dir, '.') | 789 '[new ') % join(self.root_dir, '.') |
789 end = ('] test\n 1 files changed, 1 insertions(+), ' | 790 end = ('] test\n 1 files changed, 1 insertions(+), ' |
790 '1 deletions(-)\n\n_____ . at refs/heads/master\n' | 791 '1 deletions(-)\n\n_____ . at refs/heads/master\n' |
791 'Attempting rebase onto refs/remotes/origin/master...\n') | 792 'Attempting rebase onto refs/remotes/origin/master...\n') |
792 self.assertTrue(gclient_scm.sys.stdout.getvalue().startswith(start)) | 793 self.assertTrue(sys.stdout.getvalue().startswith(start)) |
793 self.assertTrue(gclient_scm.sys.stdout.getvalue().endswith(end)) | 794 self.assertTrue(sys.stdout.getvalue().endswith(end)) |
794 self.assertEquals(len(gclient_scm.sys.stdout.getvalue()), | 795 self.assertEquals(len(sys.stdout.getvalue()), |
795 len(start) + len(end) + 7) | 796 len(start) + len(end) + 7) |
796 gclient_scm.sys.stdout.close() | 797 sys.stdout.close() |
797 | 798 |
798 def testUpdateNotGit(self): | 799 def testUpdateNotGit(self): |
799 if not self.enabled: | 800 if not self.enabled: |
800 return | 801 return |
801 options = self.Options() | 802 options = self.Options() |
802 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 803 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
803 relpath=self.relpath) | 804 relpath=self.relpath) |
804 git_path = join(self.base_path, '.git') | 805 git_path = join(self.base_path, '.git') |
805 rename(git_path, git_path + 'foo') | 806 rename(git_path, git_path + 'foo') |
806 exception = ('\n____ . at refs/heads/master\n' | 807 exception = ('\n____ . at refs/heads/master\n' |
(...skipping 10 matching lines...) Expand all Loading... |
817 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 818 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
818 relpath=self.relpath) | 819 relpath=self.relpath) |
819 rev_info = scm.revinfo(options, (), None) | 820 rev_info = scm.revinfo(options, (), None) |
820 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 821 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
821 | 822 |
822 | 823 |
823 if __name__ == '__main__': | 824 if __name__ == '__main__': |
824 unittest.main() | 825 unittest.main() |
825 | 826 |
826 # vim: ts=2:sw=2:tw=80:et: | 827 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |