Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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=E1103 | 8 # pylint: disable=E1103 |
| 9 | 9 |
| 10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 import subprocess2 | 28 import subprocess2 |
| 29 | 29 |
| 30 # Shortcut since this function is used often | 30 # Shortcut since this function is used often |
| 31 join = gclient_scm.os.path.join | 31 join = gclient_scm.os.path.join |
| 32 | 32 |
| 33 | 33 |
| 34 # Access to a protected member XXX of a client class | 34 # Access to a protected member XXX of a client class |
| 35 # pylint: disable=W0212 | 35 # pylint: disable=W0212 |
| 36 | 36 |
| 37 | 37 |
| 38 def _DummyBinaryExists(unused): | |
| 39 """Dummy implementation for BinaryExists() of SCMWrapper.""" | |
| 40 return True | |
| 41 | |
| 42 | |
| 38 class GCBaseTestCase(object): | 43 class GCBaseTestCase(object): |
| 39 def assertRaisesError(self, msg, fn, *args, **kwargs): | 44 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 40 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 45 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
| 41 # pylint: disable=E1101 | 46 # pylint: disable=E1101 |
| 42 try: | 47 try: |
| 43 fn(*args, **kwargs) | 48 fn(*args, **kwargs) |
| 44 except gclient_scm.gclient_utils.Error, e: | 49 except gclient_scm.gclient_utils.Error, e: |
| 45 self.assertEquals(e.args[0], msg) | 50 self.assertEquals(e.args[0], msg) |
| 46 else: | 51 else: |
| 47 self.fail('%s not raised' % msg) | 52 self.fail('%s not raised' % msg) |
| 48 | 53 |
| 49 | 54 |
| 50 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): | 55 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): |
| 51 def setUp(self): | 56 def setUp(self): |
| 52 SuperMoxTestBase.setUp(self) | 57 SuperMoxTestBase.setUp(self) |
| 53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') | 58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') |
| 54 self.mox.StubOutWithMock(gclient_scm.gclient_utils, | 59 self.mox.StubOutWithMock(gclient_scm.gclient_utils, |
| 55 'CheckCallAndFilterAndHeader') | 60 'CheckCallAndFilterAndHeader') |
| 56 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') | 61 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') |
| 57 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 62 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
| 58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 63 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
| 59 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') | 64 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') |
| 60 self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo') | 65 self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo') |
| 61 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') | 66 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') |
| 62 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') | 67 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') |
| 63 self.mox.StubOutWithMock(subprocess2, 'communicate') | 68 self.mox.StubOutWithMock(subprocess2, 'communicate') |
| 64 self.mox.StubOutWithMock(subprocess2, 'Popen') | 69 self.mox.StubOutWithMock(subprocess2, 'Popen') |
| 65 self._scm_wrapper = gclient_scm.CreateSCM | 70 self._scm_wrapper = gclient_scm.CreateSCM |
| 66 gclient_scm.scm.SVN.current_version = None | 71 gclient_scm.scm.SVN.current_version = None |
| 72 self._original_BinaryExists = gclient_scm.SCMWrapper.BinaryExists | |
| 73 gclient_scm.SCMWrapper.BinaryExists = _DummyBinaryExists | |
|
M-A Ruel
2012/04/17 12:15:55
you can simplify to:
gclient_scm.SCMWrapper.Binary
Jun Mukai
2012/04/18 02:46:36
Done.
| |
| 67 # Absolute path of the fake checkout directory. | 74 # Absolute path of the fake checkout directory. |
| 68 self.base_path = join(self.root_dir, self.relpath) | 75 self.base_path = join(self.root_dir, self.relpath) |
| 69 | 76 |
| 70 def tearDown(self): | 77 def tearDown(self): |
| 71 SuperMoxTestBase.tearDown(self) | 78 SuperMoxTestBase.tearDown(self) |
| 79 gclient_scm.SCMWrapper.BinaryExists = self._original_BinaryExists | |
| 72 | 80 |
| 73 | 81 |
| 74 class SVNWrapperTestCase(BaseTestCase): | 82 class SVNWrapperTestCase(BaseTestCase): |
| 75 class OptionsObject(object): | 83 class OptionsObject(object): |
| 76 def __init__(self, verbose=False, revision=None, force=False): | 84 def __init__(self, verbose=False, revision=None, force=False): |
| 77 self.verbose = verbose | 85 self.verbose = verbose |
| 78 self.revision = revision | 86 self.revision = revision |
| 79 self.manually_grab_svn_rev = True | 87 self.manually_grab_svn_rev = True |
| 80 self.deps_os = None | 88 self.deps_os = None |
| 81 self.force = force | 89 self.force = force |
| 82 self.reset = False | 90 self.reset = False |
| 83 self.nohooks = False | 91 self.nohooks = False |
| 84 # TODO(maruel): Test --jobs > 1. | 92 # TODO(maruel): Test --jobs > 1. |
| 85 self.jobs = 1 | 93 self.jobs = 1 |
| 86 self.delete_unversioned_trees = False | 94 self.delete_unversioned_trees = False |
| 87 | 95 |
| 88 def Options(self, *args, **kwargs): | 96 def Options(self, *args, **kwargs): |
| 89 return self.OptionsObject(*args, **kwargs) | 97 return self.OptionsObject(*args, **kwargs) |
| 90 | 98 |
| 91 def setUp(self): | 99 def setUp(self): |
| 92 BaseTestCase.setUp(self) | 100 BaseTestCase.setUp(self) |
| 93 self.url = self.SvnUrl() | 101 self.url = self.SvnUrl() |
| 94 | 102 |
| 95 def testDir(self): | 103 def testDir(self): |
| 96 members = [ | 104 members = [ |
| 105 'BinaryExists', | |
| 97 'FullUrlForRelativeUrl', | 106 'FullUrlForRelativeUrl', |
| 98 'GetRevisionDate', | 107 'GetRevisionDate', |
| 99 'GetUsableRev', | 108 'GetUsableRev', |
| 100 'RunCommand', | 109 'RunCommand', |
| 101 'cleanup', | 110 'cleanup', |
| 102 'diff', | 111 'diff', |
| 103 'pack', | 112 'pack', |
| 104 'relpath', | 113 'relpath', |
| 105 'revert', | 114 'revert', |
| 106 'revinfo', | 115 'revinfo', |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 | 752 |
| 744 def setUp(self): | 753 def setUp(self): |
| 745 TestCaseUtils.setUp(self) | 754 TestCaseUtils.setUp(self) |
| 746 unittest.TestCase.setUp(self) | 755 unittest.TestCase.setUp(self) |
| 747 self.url = 'git://foo' | 756 self.url = 'git://foo' |
| 748 self.root_dir = tempfile.mkdtemp() | 757 self.root_dir = tempfile.mkdtemp() |
| 749 self.relpath = '.' | 758 self.relpath = '.' |
| 750 self.base_path = join(self.root_dir, self.relpath) | 759 self.base_path = join(self.root_dir, self.relpath) |
| 751 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 760 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 752 StdoutCheck.setUp(self) | 761 StdoutCheck.setUp(self) |
| 762 self._original_BinaryExists = gclient_scm.SCMWrapper.BinaryExists | |
| 763 gclient_scm.SCMWrapper.BinaryExists = _DummyBinaryExists | |
| 753 | 764 |
| 754 def tearDown(self): | 765 def tearDown(self): |
| 755 StdoutCheck.tearDown(self) | 766 StdoutCheck.tearDown(self) |
| 756 TestCaseUtils.tearDown(self) | 767 TestCaseUtils.tearDown(self) |
| 757 unittest.TestCase.tearDown(self) | 768 unittest.TestCase.tearDown(self) |
| 758 rmtree(self.root_dir) | 769 rmtree(self.root_dir) |
| 770 gclient_scm.SCMWrapper.BinaryExists = self._original_BinaryExists | |
| 759 | 771 |
| 760 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): | 772 class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): |
| 761 def testDir(self): | 773 def testDir(self): |
| 762 members = [ | 774 members = [ |
| 775 'BinaryExists', | |
| 763 'FullUrlForRelativeUrl', | 776 'FullUrlForRelativeUrl', |
| 764 'GetRevisionDate', | 777 'GetRevisionDate', |
| 765 'GetUsableRev', | 778 'GetUsableRev', |
| 766 'RunCommand', | 779 'RunCommand', |
| 767 'cleanup', | 780 'cleanup', |
| 768 'diff', | 781 'diff', |
| 769 'pack', | 782 'pack', |
| 770 'relpath', | 783 'relpath', |
| 771 'revert', | 784 'revert', |
| 772 'revinfo', | 785 'revinfo', |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1206 | 1219 |
| 1207 if __name__ == '__main__': | 1220 if __name__ == '__main__': |
| 1208 if '-v' in sys.argv: | 1221 if '-v' in sys.argv: |
| 1209 logging.basicConfig( | 1222 logging.basicConfig( |
| 1210 level=logging.DEBUG, | 1223 level=logging.DEBUG, |
| 1211 format='%(asctime).19s %(levelname)s %(filename)s:' | 1224 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 1212 '%(lineno)s %(message)s') | 1225 '%(lineno)s %(message)s') |
| 1213 unittest.main() | 1226 unittest.main() |
| 1214 | 1227 |
| 1215 # vim: ts=2:sw=2:tw=80:et: | 1228 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |