| 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 scm.py.""" | 6 """Unit tests for scm.py.""" |
| 7 | 7 |
| 8 # pylint: disable=E1101,W0403 | 8 # pylint: disable=E1101,W0403 |
| 9 from __future__ import with_statement | 9 from __future__ import with_statement |
| 10 import logging | 10 import logging |
| 11 import sys | 11 import sys |
| 12 import unittest | 12 import unittest |
| 13 | 13 |
| 14 # Fixes include path. | 14 # Fixes include path. |
| 15 from super_mox import SuperMoxTestBase | 15 from super_mox import SuperMoxTestBase |
| 16 | 16 |
| 17 import fake_repos | 17 import fake_repos |
| 18 import scm | 18 import scm |
| 19 import subprocess2 |
| 19 | 20 |
| 20 | 21 |
| 21 class BaseTestCase(SuperMoxTestBase): | 22 class BaseTestCase(SuperMoxTestBase): |
| 22 # Like unittest's assertRaises, but checks for Gclient.Error. | 23 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 23 def assertRaisesError(self, msg, fn, *args, **kwargs): | 24 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 24 try: | 25 try: |
| 25 fn(*args, **kwargs) | 26 fn(*args, **kwargs) |
| 26 except scm.gclient_utils.Error, e: | 27 except scm.gclient_utils.Error, e: |
| 27 self.assertEquals(e.args[0], msg) | 28 self.assertEquals(e.args[0], msg) |
| 28 else: | 29 else: |
| 29 self.fail('%s not raised' % msg) | 30 self.fail('%s not raised' % msg) |
| 30 | 31 |
| 31 | 32 |
| 32 class BaseSCMTestCase(BaseTestCase): | 33 class BaseSCMTestCase(BaseTestCase): |
| 33 def setUp(self): | 34 def setUp(self): |
| 34 BaseTestCase.setUp(self) | 35 BaseTestCase.setUp(self) |
| 35 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCall') | |
| 36 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter') | 36 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter') |
| 37 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader') | 37 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader') |
| 38 self.mox.StubOutWithMock(scm.gclient_utils, 'Popen') | 38 self.mox.StubOutWithMock(subprocess2, 'Popen') |
| 39 self.mox.StubOutWithMock(subprocess2, 'communicate') |
| 39 | 40 |
| 40 | 41 |
| 41 class RootTestCase(BaseSCMTestCase): | 42 class RootTestCase(BaseSCMTestCase): |
| 42 def testMembersChanged(self): | 43 def testMembersChanged(self): |
| 43 self.mox.ReplayAll() | 44 self.mox.ReplayAll() |
| 44 members = [ | 45 members = [ |
| 45 'ElementTree', 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', | 46 'ElementTree', 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', |
| 46 'ValidateEmail', | 47 'ValidateEmail', |
| 47 'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging', 'os', | 48 'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging', 'os', |
| 48 're', 'shutil', 'subprocess', 'subprocess2', 'sys', 'tempfile', 'time', | 49 're', 'subprocess2', 'sys', 'tempfile', 'time', |
| 49 ] | 50 ] |
| 50 # If this test fails, you should add the relevant test. | 51 # If this test fails, you should add the relevant test. |
| 51 self.compareMembers(scm, members) | 52 self.compareMembers(scm, members) |
| 52 | 53 |
| 53 | 54 |
| 54 class GitWrapperTestCase(BaseSCMTestCase): | 55 class GitWrapperTestCase(BaseSCMTestCase): |
| 55 def testMembersChanged(self): | 56 def testMembersChanged(self): |
| 56 members = [ | 57 members = [ |
| 57 'AssertVersion', 'Capture', 'CaptureStatus', | 58 'AssertVersion', 'Capture', 'CaptureStatus', |
| 58 'FetchUpstreamTuple', | 59 'FetchUpstreamTuple', |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 # Asserting the tree is not sufficient, svn status must come out clear too. | 335 # Asserting the tree is not sufficient, svn status must come out clear too. |
| 335 self.assertEquals('', self._capture(['status'])) | 336 self.assertEquals('', self._capture(['status'])) |
| 336 | 337 |
| 337 | 338 |
| 338 if __name__ == '__main__': | 339 if __name__ == '__main__': |
| 339 if '-v' in sys.argv: | 340 if '-v' in sys.argv: |
| 340 logging.basicConfig(level=logging.DEBUG) | 341 logging.basicConfig(level=logging.DEBUG) |
| 341 unittest.main() | 342 unittest.main() |
| 342 | 343 |
| 343 # vim: ts=2:sw=2:tw=80:et: | 344 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |