| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 import shutil | 8 import shutil |
| 9 import tempfile | 9 import tempfile |
| 10 | 10 |
| 11 from gclient_test import BaseTestCase | 11 from gclient_test import BaseTestCase |
| 12 import scm | 12 import scm |
| 13 from super_mox import mox, SuperMoxBaseTestBase | 13 from super_mox import mox, SuperMoxBaseTestBase |
| 14 | 14 |
| 15 | 15 |
| 16 class BaseSCMTestCase(BaseTestCase): | 16 class BaseSCMTestCase(BaseTestCase): |
| 17 def setUp(self): | 17 def setUp(self): |
| 18 BaseTestCase.setUp(self) | 18 BaseTestCase.setUp(self) |
| 19 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall') | 19 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall') |
| 20 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') | 20 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') |
| 21 | 21 |
| 22 | 22 |
| 23 class RootTestCase(BaseSCMTestCase): | 23 class RootTestCase(BaseSCMTestCase): |
| 24 def testMembersChanged(self): | 24 def testMembersChanged(self): |
| 25 self.mox.ReplayAll() | 25 self.mox.ReplayAll() |
| 26 members = [ | 26 members = [ |
| 27 'GIT', 'SVN', | 27 'GIT', 'SVN', |
| 28 'gclient_utils', 'os', 're', 'subprocess', 'sys', 'tempfile', 'xml', | 28 'gclient_utils', 'os', 're', 'shutil', 'subprocess', 'sys', 'tempfile', |
| 29 'xml', |
| 29 ] | 30 ] |
| 30 # If this test fails, you should add the relevant test. | 31 # If this test fails, you should add the relevant test. |
| 31 self.compareMembers(scm, members) | 32 self.compareMembers(scm, members) |
| 32 | 33 |
| 33 | 34 |
| 34 class GitWrapperTestCase(SuperMoxBaseTestBase): | 35 class GitWrapperTestCase(SuperMoxBaseTestBase): |
| 35 sample_git_import = """blob | 36 sample_git_import = """blob |
| 36 mark :1 | 37 mark :1 |
| 37 data 6 | 38 data 6 |
| 38 Hello | 39 Hello |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 109 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 109 self.fake_root = self.Dir() | 110 self.fake_root = self.Dir() |
| 110 | 111 |
| 111 def tearDown(self): | 112 def tearDown(self): |
| 112 shutil.rmtree(self.root_dir) | 113 shutil.rmtree(self.root_dir) |
| 113 SuperMoxBaseTestBase.tearDown(self) | 114 SuperMoxBaseTestBase.tearDown(self) |
| 114 | 115 |
| 115 def testMembersChanged(self): | 116 def testMembersChanged(self): |
| 116 self.mox.ReplayAll() | 117 self.mox.ReplayAll() |
| 117 members = [ | 118 members = [ |
| 118 'COMMAND', 'Capture', 'CaptureStatus', 'GetEmail', | 119 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', |
| 120 'GenerateDiff', 'GetBranchRef', 'GetEmail', 'GetSVNBranch', |
| 121 'GetUpstream', 'IsGitSvn', 'ShortBranchName' |
| 119 ] | 122 ] |
| 120 # If this test fails, you should add the relevant test. | 123 # If this test fails, you should add the relevant test. |
| 121 self.compareMembers(scm.GIT, members) | 124 self.compareMembers(scm.GIT, members) |
| 122 | 125 |
| 123 def testGetEmail(self): | 126 def testGetEmail(self): |
| 124 self.mox.StubOutWithMock(scm.GIT, 'Capture') | 127 self.mox.StubOutWithMock(scm.GIT, 'Capture') |
| 125 scm.GIT.Capture(['config', 'user.email'], self.fake_root).AndReturn('mini@me
.com') | 128 scm.GIT.Capture(['config', 'user.email'], self.fake_root, error_ok=True |
| 129 ).AndReturn('mini@me.com') |
| 126 self.mox.ReplayAll() | 130 self.mox.ReplayAll() |
| 127 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') | 131 self.assertEqual(scm.GIT.GetEmail(self.fake_root), 'mini@me.com') |
| 128 | 132 |
| 129 | 133 |
| 130 class SVNTestCase(BaseSCMTestCase): | 134 class SVNTestCase(BaseSCMTestCase): |
| 131 def setUp(self): | 135 def setUp(self): |
| 132 BaseSCMTestCase.setUp(self) | 136 BaseSCMTestCase.setUp(self) |
| 133 self.root_dir = self.Dir() | 137 self.root_dir = self.Dir() |
| 134 self.args = self.Args() | 138 self.args = self.Args() |
| 135 self.url = self.Url() | 139 self.url = self.Url() |
| 136 self.relpath = 'asf' | 140 self.relpath = 'asf' |
| 137 | 141 |
| 138 def testMembersChanged(self): | 142 def testMembersChanged(self): |
| 139 self.mox.ReplayAll() | 143 self.mox.ReplayAll() |
| 140 members = [ | 144 members = [ |
| 141 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo', | 145 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo', |
| 142 'CaptureStatus', 'DiffItem', 'GetCheckoutRoot', 'GetEmail', | 146 'CaptureStatus', 'DiffItem', 'GenerateDiff', 'GetCheckoutRoot', |
| 143 'GetFileProperty', 'IsMoved', | 147 'GetEmail', 'GetFileProperty', 'IsMoved', |
| 144 'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList', | 148 'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList', |
| 145 ] | 149 ] |
| 146 # If this test fails, you should add the relevant test. | 150 # If this test fails, you should add the relevant test. |
| 147 self.compareMembers(scm.SVN, members) | 151 self.compareMembers(scm.SVN, members) |
| 148 | 152 |
| 149 def testGetFileInfo(self): | 153 def testGetFileInfo(self): |
| 150 xml_text = r"""<?xml version="1.0"?> | 154 xml_text = r"""<?xml version="1.0"?> |
| 151 <info> | 155 <info> |
| 152 <entry kind="file" path="%s" revision="14628"> | 156 <entry kind="file" path="%s" revision="14628"> |
| 153 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 157 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 self.mox.ReplayAll() | 306 self.mox.ReplayAll() |
| 303 info = scm.SVN.CaptureStatus(None) | 307 info = scm.SVN.CaptureStatus(None) |
| 304 self.assertEquals(info, []) | 308 self.assertEquals(info, []) |
| 305 | 309 |
| 306 | 310 |
| 307 if __name__ == '__main__': | 311 if __name__ == '__main__': |
| 308 import unittest | 312 import unittest |
| 309 unittest.main() | 313 unittest.main() |
| 310 | 314 |
| 311 # vim: ts=2:sw=2:tw=80:et: | 315 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |