OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 # pylint: disable=E1101,E1103,W0403 | 8 # pylint: disable=E1101,E1103,W0403 |
9 | 9 |
10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
11 from os import rename | 11 from os import rename |
12 from shutil import rmtree | 12 from shutil import rmtree |
13 from subprocess import Popen, PIPE, STDOUT | 13 from subprocess import Popen, PIPE, STDOUT |
14 import tempfile | 14 import tempfile |
15 import unittest | 15 import unittest |
16 import __builtin__ | 16 import __builtin__ |
17 | 17 |
18 # Fixes include path. | 18 # Fixes include path. |
19 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase | 19 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase |
20 | 20 |
21 import logging | 21 import logging |
22 import sys | 22 import sys |
23 import gclient_scm | 23 import gclient_scm |
| 24 import subprocess2 |
24 | 25 |
25 # Shortcut since this function is used often | 26 # Shortcut since this function is used often |
26 join = gclient_scm.os.path.join | 27 join = gclient_scm.os.path.join |
27 | 28 |
28 | 29 |
29 class GCBaseTestCase(object): | 30 class GCBaseTestCase(object): |
30 def assertRaisesError(self, msg, fn, *args, **kwargs): | 31 def assertRaisesError(self, msg, fn, *args, **kwargs): |
31 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 32 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
32 try: | 33 try: |
33 fn(*args, **kwargs) | 34 fn(*args, **kwargs) |
34 except gclient_scm.gclient_utils.Error, e: | 35 except gclient_scm.gclient_utils.Error, e: |
35 self.assertEquals(e.args[0], msg) | 36 self.assertEquals(e.args[0], msg) |
36 else: | 37 else: |
37 self.fail('%s not raised' % msg) | 38 self.fail('%s not raised' % msg) |
38 | 39 |
39 | 40 |
40 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): | 41 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): |
41 def setUp(self): | 42 def setUp(self): |
42 SuperMoxTestBase.setUp(self) | 43 SuperMoxTestBase.setUp(self) |
43 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCall') | |
44 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') | 44 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') |
45 self.mox.StubOutWithMock(gclient_scm.gclient_utils, | 45 self.mox.StubOutWithMock(gclient_scm.gclient_utils, |
46 'CheckCallAndFilterAndHeader') | 46 'CheckCallAndFilterAndHeader') |
47 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') | 47 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') |
48 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 48 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
49 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'Popen') | |
50 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 49 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
51 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo | 50 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo |
52 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') | 51 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') |
53 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') | 52 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') |
54 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') | 53 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') |
55 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') | 54 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') |
| 55 self.mox.StubOutWithMock(subprocess2, 'communicate') |
| 56 self.mox.StubOutWithMock(subprocess2, 'Popen') |
56 self._scm_wrapper = gclient_scm.CreateSCM | 57 self._scm_wrapper = gclient_scm.CreateSCM |
57 gclient_scm.scm.SVN.current_version = None | 58 gclient_scm.scm.SVN.current_version = None |
58 # Absolute path of the fake checkout directory. | 59 # Absolute path of the fake checkout directory. |
59 self.base_path = join(self.root_dir, self.relpath) | 60 self.base_path = join(self.root_dir, self.relpath) |
60 | 61 |
61 def tearDown(self): | 62 def tearDown(self): |
62 SuperMoxTestBase.tearDown(self) | 63 SuperMoxTestBase.tearDown(self) |
63 | 64 |
64 | 65 |
65 class SVNWrapperTestCase(BaseTestCase): | 66 class SVNWrapperTestCase(BaseTestCase): |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 if not self.enabled: | 751 if not self.enabled: |
751 return | 752 return |
752 options = self.Options() | 753 options = self.Options() |
753 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 754 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
754 relpath=self.relpath) | 755 relpath=self.relpath) |
755 file_path = join(self.base_path, 'b') | 756 file_path = join(self.base_path, 'b') |
756 open(file_path, 'w').writelines('conflict\n') | 757 open(file_path, 'w').writelines('conflict\n') |
757 try: | 758 try: |
758 scm.update(options, (), []) | 759 scm.update(options, (), []) |
759 self.fail() | 760 self.fail() |
760 except gclient_scm.gclient_utils.Error: | 761 except (gclient_scm.gclient_utils.Error, subprocess2.CalledProcessError): |
761 # The exact exception text varies across git versions so it's not worth | 762 # The exact exception text varies across git versions so it's not worth |
762 # verifying it. It's fine as long as it throws. | 763 # verifying it. It's fine as long as it throws. |
763 pass | 764 pass |
764 # Manually flush stdout since we can't verify it's content accurately across | 765 # Manually flush stdout since we can't verify it's content accurately across |
765 # git versions. | 766 # git versions. |
766 sys.stdout.getvalue() | 767 sys.stdout.getvalue() |
767 sys.stdout.close() | 768 sys.stdout.close() |
768 | 769 |
769 def testUpdateConflict(self): | 770 def testUpdateConflict(self): |
770 if not self.enabled: | 771 if not self.enabled: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 825 |
825 if __name__ == '__main__': | 826 if __name__ == '__main__': |
826 if '-v' in sys.argv: | 827 if '-v' in sys.argv: |
827 logging.basicConfig( | 828 logging.basicConfig( |
828 level=logging.DEBUG, | 829 level=logging.DEBUG, |
829 format='%(asctime).19s %(levelname)s %(filename)s:' | 830 format='%(asctime).19s %(levelname)s %(filename)s:' |
830 '%(lineno)s %(message)s') | 831 '%(lineno)s %(message)s') |
831 unittest.main() | 832 unittest.main() |
832 | 833 |
833 # vim: ts=2:sw=2:tw=80:et: | 834 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |