| 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 | |
| 27 from super_mox import mox, IsOneOf, SuperMoxTestBase | 25 from super_mox import mox, IsOneOf, SuperMoxTestBase |
| 28 | 26 |
| 29 | 27 |
| 30 class BaseTestCase(SuperMoxTestBase): | 28 class BaseTestCase(SuperMoxTestBase): |
| 31 # Like unittest's assertRaises, but checks for Gclient.Error. | 29 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 32 def assertRaisesError(self, msg, fn, *args, **kwargs): | 30 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 33 try: | 31 try: |
| 34 fn(*args, **kwargs) | 32 fn(*args, **kwargs) |
| 35 except gclient.gclient_utils.Error, e: | 33 except gclient.gclient_utils.Error, e: |
| 36 self.assertEquals(e.args[0], msg) | 34 self.assertEquals(e.args[0], msg) |
| 37 else: | 35 else: |
| 38 self.fail('%s not raised' % msg) | 36 self.fail('%s not raised' % msg) |
| 39 | 37 |
| 40 | 38 |
| 41 class GClientBaseTestCase(BaseTestCase): | 39 class GClientBaseTestCase(BaseTestCase): |
| 42 def Options(self, *args, **kwargs): | 40 def Options(self, *args, **kwargs): |
| 43 return self.OptionsObject(self, *args, **kwargs) | 41 return self.OptionsObject(self, *args, **kwargs) |
| 44 | 42 |
| 45 def setUp(self): | 43 def setUp(self): |
| 46 BaseTestCase.setUp(self) | 44 BaseTestCase.setUp(self) |
| 47 # These are not tested. | 45 # These are not tested. |
| 48 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead') | 46 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead') |
| 49 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite') | 47 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite') |
| 50 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall') | 48 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall') |
| 51 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory') | 49 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory') |
| 52 # Mock them to be sure nothing bad happens. | 50 # Mock them to be sure nothing bad happens. |
| 53 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVN') | 51 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Capture') |
| 54 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNInfo') | 52 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureInfo') |
| 55 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNStatus') | 53 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureStatus') |
| 56 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVN') | 54 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Run') |
| 57 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVNAndGetFileList') | 55 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'RunAndGetFileList') |
| 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') | |
| 63 self._gclient_gclient = gclient.GClient | 56 self._gclient_gclient = gclient.GClient |
| 64 gclient.GClient = self.mox.CreateMockAnything() | 57 gclient.GClient = self.mox.CreateMockAnything() |
| 65 self._scm_wrapper = gclient.gclient_scm.CreateSCM | 58 self._scm_wrapper = gclient.gclient_scm.CreateSCM |
| 66 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything() | 59 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything() |
| 67 | 60 |
| 68 def tearDown(self): | 61 def tearDown(self): |
| 69 gclient.GClient = self._gclient_gclient | 62 gclient.GClient = self._gclient_gclient |
| 70 gclient.gclient_scm.CreateSCM = self._scm_wrapper | 63 gclient.gclient_scm.CreateSCM = self._scm_wrapper |
| 71 BaseTestCase.tearDown(self) | 64 BaseTestCase.tearDown(self) |
| 72 | 65 |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 pass | 1064 pass |
| 1072 def test_VarImpl(self): | 1065 def test_VarImpl(self): |
| 1073 pass | 1066 pass |
| 1074 | 1067 |
| 1075 | 1068 |
| 1076 if __name__ == '__main__': | 1069 if __name__ == '__main__': |
| 1077 import unittest | 1070 import unittest |
| 1078 unittest.main() | 1071 unittest.main() |
| 1079 | 1072 |
| 1080 # vim: ts=2:sw=2:tw=80:et: | 1073 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |