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 # |
11 # Unless required by applicable law or agreed to in writing, software | 11 # Unless required by applicable law or agreed to in writing, software |
12 # distributed under the License is distributed on an "AS IS" BASIS, | 12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and | 14 # See the License for the specific language governing permissions and |
15 # limitations under the License. | 15 # limitations under the License. |
16 | 16 |
17 """Unit tests for gclient.py.""" | 17 """Unit tests for gclient.py.""" |
18 | 18 |
19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' | 19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' |
20 | 20 |
21 import __builtin__ | 21 import __builtin__ |
22 import StringIO | 22 import StringIO |
23 | 23 |
24 import gclient | 24 import gclient |
| 25 # Temporary due to the "from scm import *" in gclient_scm. |
| 26 import scm |
25 from super_mox import mox, IsOneOf, SuperMoxTestBase | 27 from super_mox import mox, IsOneOf, SuperMoxTestBase |
26 | 28 |
27 | 29 |
28 class BaseTestCase(SuperMoxTestBase): | 30 class BaseTestCase(SuperMoxTestBase): |
29 # Like unittest's assertRaises, but checks for Gclient.Error. | 31 # Like unittest's assertRaises, but checks for Gclient.Error. |
30 def assertRaisesError(self, msg, fn, *args, **kwargs): | 32 def assertRaisesError(self, msg, fn, *args, **kwargs): |
31 try: | 33 try: |
32 fn(*args, **kwargs) | 34 fn(*args, **kwargs) |
33 except gclient.gclient_utils.Error, e: | 35 except gclient.gclient_utils.Error, e: |
34 self.assertEquals(e.args[0], msg) | 36 self.assertEquals(e.args[0], msg) |
35 else: | 37 else: |
36 self.fail('%s not raised' % msg) | 38 self.fail('%s not raised' % msg) |
37 | 39 |
38 | 40 |
39 class GClientBaseTestCase(BaseTestCase): | 41 class GClientBaseTestCase(BaseTestCase): |
40 def Options(self, *args, **kwargs): | 42 def Options(self, *args, **kwargs): |
41 return self.OptionsObject(self, *args, **kwargs) | 43 return self.OptionsObject(self, *args, **kwargs) |
42 | 44 |
43 def setUp(self): | 45 def setUp(self): |
44 BaseTestCase.setUp(self) | 46 BaseTestCase.setUp(self) |
45 # These are not tested. | 47 # These are not tested. |
46 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead') | 48 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead') |
47 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite') | 49 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite') |
48 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall') | 50 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall') |
49 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory') | 51 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory') |
50 # Mock them to be sure nothing bad happens. | 52 # Mock them to be sure nothing bad happens. |
51 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Capture') | 53 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVN') |
52 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureInfo') | 54 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNInfo') |
53 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureStatus') | 55 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNStatus') |
54 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Run') | 56 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVN') |
55 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'RunAndGetFileList') | 57 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVNAndGetFileList') |
| 58 self.mox.StubOutWithMock(scm, 'CaptureSVN') |
| 59 self.mox.StubOutWithMock(scm, 'CaptureSVNInfo') |
| 60 self.mox.StubOutWithMock(scm, 'CaptureSVNStatus') |
| 61 self.mox.StubOutWithMock(scm, 'RunSVN') |
| 62 self.mox.StubOutWithMock(scm, 'RunSVNAndGetFileList') |
56 self._gclient_gclient = gclient.GClient | 63 self._gclient_gclient = gclient.GClient |
57 gclient.GClient = self.mox.CreateMockAnything() | 64 gclient.GClient = self.mox.CreateMockAnything() |
58 self._scm_wrapper = gclient.gclient_scm.CreateSCM | 65 self._scm_wrapper = gclient.gclient_scm.CreateSCM |
59 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything() | 66 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything() |
60 | 67 |
61 def tearDown(self): | 68 def tearDown(self): |
62 gclient.GClient = self._gclient_gclient | 69 gclient.GClient = self._gclient_gclient |
63 gclient.gclient_scm.CreateSCM = self._scm_wrapper | 70 gclient.gclient_scm.CreateSCM = self._scm_wrapper |
64 BaseTestCase.tearDown(self) | 71 BaseTestCase.tearDown(self) |
65 | 72 |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 pass | 1071 pass |
1065 def test_VarImpl(self): | 1072 def test_VarImpl(self): |
1066 pass | 1073 pass |
1067 | 1074 |
1068 | 1075 |
1069 if __name__ == '__main__': | 1076 if __name__ == '__main__': |
1070 import unittest | 1077 import unittest |
1071 unittest.main() | 1078 unittest.main() |
1072 | 1079 |
1073 # vim: ts=2:sw=2:tw=80:et: | 1080 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |