Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 # Import before super_mox to keep valid references. | 8 # Import before super_mox to keep valid references. |
| 9 from os import rename | 9 from os import rename |
| 10 from shutil import rmtree | 10 from shutil import rmtree |
| 11 import StringIO | |
| 11 from subprocess import Popen, PIPE, STDOUT | 12 from subprocess import Popen, PIPE, STDOUT |
| 12 import tempfile | 13 import tempfile |
| 13 import __builtin__ | 14 import __builtin__ |
| 14 | 15 |
| 15 # Fixes include path. | 16 # Fixes include path. |
| 16 from super_mox import mox, SuperMoxBaseTestBase, SuperMoxTestBase | 17 from super_mox import mox, SuperMoxBaseTestBase, SuperMoxTestBase |
| 17 | 18 |
| 18 import gclient_scm | 19 import gclient_scm |
| 19 | 20 |
| 20 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 39 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 40 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
| 40 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 41 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
| 41 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo | 42 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo |
| 42 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') | 43 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') |
| 43 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') | 44 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') |
| 44 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') | 45 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') |
| 45 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') | 46 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') |
| 46 self._scm_wrapper = gclient_scm.CreateSCM | 47 self._scm_wrapper = gclient_scm.CreateSCM |
| 47 gclient_scm.sys.stdout.flush = lambda: None | 48 gclient_scm.sys.stdout.flush = lambda: None |
| 48 gclient_scm.scm.SVN.current_version = None | 49 gclient_scm.scm.SVN.current_version = None |
| 50 self.stdout = StringIO.StringIO() | |
| 51 | |
| 52 def tearDown(self): | |
| 53 GCBaseTestCase.tearDown(self) | |
| 54 try: | |
| 55 self.stdout.getvalue() | |
| 56 self.fail() | |
| 57 except AttributeError: | |
| 58 pass | |
| 59 | |
| 60 def checkstdout(self, expected): | |
| 61 value = self.stdout.getvalue() | |
| 62 self.stdout.close() | |
| 63 self.assertEquals(expected, value) | |
| 49 | 64 |
| 50 | 65 |
| 51 class SVNWrapperTestCase(BaseTestCase): | 66 class SVNWrapperTestCase(BaseTestCase): |
| 52 class OptionsObject(object): | 67 class OptionsObject(object): |
| 53 def __init__(self, test_case, verbose=False, revision=None): | 68 def __init__(self, test_case, verbose=False, revision=None): |
| 54 self.verbose = verbose | 69 self.verbose = verbose |
| 55 self.revision = revision | 70 self.revision = revision |
| 56 self.manually_grab_svn_rev = True | 71 self.manually_grab_svn_rev = True |
| 57 self.deps_os = None | 72 self.deps_os = None |
| 58 self.force = False | 73 self.force = False |
| 59 self.reset = False | 74 self.reset = False |
| 60 self.nohooks = False | 75 self.nohooks = False |
| 61 self.stdout = gclient_scm.sys.stdout | 76 self.stdout = test_case.stdout |
| 62 | 77 |
| 63 def Options(self, *args, **kwargs): | 78 def Options(self, *args, **kwargs): |
| 64 return self.OptionsObject(self, *args, **kwargs) | 79 return self.OptionsObject(self, *args, **kwargs) |
| 65 | 80 |
| 66 def setUp(self): | 81 def setUp(self): |
| 67 BaseTestCase.setUp(self) | 82 BaseTestCase.setUp(self) |
| 68 self.root_dir = self.Dir() | 83 self.root_dir = self.Dir() |
| 69 self.args = self.Args() | 84 self.args = self.Args() |
| 70 self.url = self.Url() | 85 self.url = self.Url() |
| 71 self.relpath = 'asf' | 86 self.relpath = 'asf' |
| 72 | 87 |
| 73 def testDir(self): | 88 def testDir(self): |
| 74 members = [ | 89 members = [ |
| 75 'FullUrlForRelativeUrl', 'RunCommand', | 90 'FullUrlForRelativeUrl', 'RunCommand', |
| 76 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', | 91 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', |
| 77 'revinfo', 'runhooks', 'status', 'update', | 92 'revinfo', 'runhooks', 'status', 'update', |
| 78 'updatesingle', 'url', | 93 'updatesingle', 'url', |
| 79 ] | 94 ] |
| 80 | 95 |
| 81 # If you add a member, be sure to add the relevant test! | 96 # If you add a member, be sure to add the relevant test! |
| 82 self.compareMembers(self._scm_wrapper('svn://a'), members) | 97 self.compareMembers(self._scm_wrapper('svn://a'), members) |
| 98 self.checkstdout('') | |
| 83 | 99 |
| 84 def testUnsupportedSCM(self): | 100 def testUnsupportedSCM(self): |
| 85 args = ['gopher://foo', self.root_dir, self.relpath] | 101 args = ['gopher://foo', self.root_dir, self.relpath] |
| 86 exception_msg = 'No SCM found for url gopher://foo' | 102 exception_msg = 'No SCM found for url gopher://foo' |
| 87 self.assertRaisesError(exception_msg, self._scm_wrapper, *args) | 103 self.assertRaisesError(exception_msg, self._scm_wrapper, *args) |
| 104 self.checkstdout('') | |
| 88 | 105 |
| 89 def testSVNFullUrlForRelativeUrl(self): | 106 def testSVNFullUrlForRelativeUrl(self): |
| 90 self.url = 'svn://a/b/c/d' | 107 self.url = 'svn://a/b/c/d' |
| 91 | 108 |
| 92 self.mox.ReplayAll() | 109 self.mox.ReplayAll() |
| 93 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 110 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 94 relpath=self.relpath) | 111 relpath=self.relpath) |
| 95 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') | 112 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') |
| 113 self.checkstdout('') | |
| 96 | 114 |
| 97 def testGITFullUrlForRelativeUrl(self): | 115 def testGITFullUrlForRelativeUrl(self): |
| 98 self.url = 'git://a/b/c/d' | 116 self.url = 'git://a/b/c/d' |
| 99 | 117 |
| 100 self.mox.ReplayAll() | 118 self.mox.ReplayAll() |
| 101 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 119 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 102 relpath=self.relpath) | 120 relpath=self.relpath) |
| 103 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') | 121 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') |
| 122 self.checkstdout('') | |
| 104 | 123 |
| 105 def testRunCommandException(self): | 124 def testRunCommandException(self): |
| 106 options = self.Options(verbose=False) | 125 options = self.Options(verbose=False) |
| 107 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 126 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
| 108 gclient_scm.os.path.exists(file_path).AndReturn(False) | 127 gclient_scm.os.path.exists(file_path).AndReturn(False) |
| 109 | 128 |
| 110 self.mox.ReplayAll() | 129 self.mox.ReplayAll() |
| 111 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 130 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 112 relpath=self.relpath) | 131 relpath=self.relpath) |
| 113 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 132 exception = "Unsupported argument(s): %s" % ','.join(self.args) |
| 114 self.assertRaisesError(exception, scm.RunCommand, | 133 self.assertRaisesError(exception, scm.RunCommand, |
| 115 'update', options, self.args) | 134 'update', options, self.args) |
| 135 self.checkstdout('') | |
| 116 | 136 |
| 117 def testRunCommandUnknown(self): | 137 def testRunCommandUnknown(self): |
| 118 # TODO(maruel): if ever used. | 138 # TODO(maruel): if ever used. |
| 119 pass | 139 self.checkstdout('') |
| 120 | 140 |
| 121 def testRevertMissing(self): | 141 def testRevertMissing(self): |
| 122 options = self.Options(verbose=True) | 142 options = self.Options(verbose=True) |
| 123 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 143 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 124 gclient_scm.os.path.isdir(base_path).AndReturn(False) | 144 gclient_scm.os.path.isdir(base_path).AndReturn(False) |
| 125 gclient_scm.scm.SVN.Capture(['--version'] | 145 gclient_scm.scm.SVN.Capture(['--version'] |
| 126 ).AndReturn('svn, version 1.5.1 (r32289)') | 146 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 127 # It'll to a checkout instead. | 147 # It'll to a checkout instead. |
| 128 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 148 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 129 ).AndReturn(False) | 149 ).AndReturn(False) |
| 130 print("\n_____ %s is missing, synching instead" % self.relpath) | |
| 131 # Checkout. | 150 # Checkout. |
| 132 gclient_scm.os.path.exists(base_path).AndReturn(False) | 151 gclient_scm.os.path.exists(base_path).AndReturn(False) |
| 133 files_list = self.mox.CreateMockAnything() | 152 files_list = self.mox.CreateMockAnything() |
| 134 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 153 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 135 ['checkout', self.url, base_path, | 154 ['checkout', self.url, base_path, |
| 136 '--force'], | 155 '--force'], |
| 137 cwd=self.root_dir, | 156 cwd=self.root_dir, |
| 138 file_list=files_list, | 157 file_list=files_list, |
| 139 stdout=options.stdout) | 158 stdout=options.stdout) |
| 140 | 159 |
| 141 self.mox.ReplayAll() | 160 self.mox.ReplayAll() |
| 142 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 161 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 143 relpath=self.relpath) | 162 relpath=self.relpath) |
| 144 scm.revert(options, self.args, files_list) | 163 scm.revert(options, self.args, files_list) |
| 164 self.checkstdout( | |
| 165 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | |
| 145 | 166 |
| 146 def testRevertNone(self): | 167 def testRevertNone(self): |
| 147 options = self.Options(verbose=True) | 168 options = self.Options(verbose=True) |
| 148 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 169 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 149 gclient_scm.os.path.isdir(base_path).AndReturn(True) | 170 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
| 150 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([]) | 171 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([]) |
| 151 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 172 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 152 ['update', '--revision', 'BASE'], | 173 ['update', '--revision', 'BASE'], |
| 153 cwd=base_path, | 174 cwd=base_path, |
| 154 file_list=mox.IgnoreArg(), | 175 file_list=mox.IgnoreArg(), |
| 155 stdout=options.stdout) | 176 stdout=options.stdout) |
| 156 | 177 |
| 157 self.mox.ReplayAll() | 178 self.mox.ReplayAll() |
| 158 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 179 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 159 relpath=self.relpath) | 180 relpath=self.relpath) |
| 160 file_list = [] | 181 file_list = [] |
| 161 scm.revert(options, self.args, file_list) | 182 scm.revert(options, self.args, file_list) |
| 183 self.checkstdout('') | |
| 162 | 184 |
| 163 def testRevert2Files(self): | 185 def testRevert2Files(self): |
| 164 options = self.Options(verbose=True) | 186 options = self.Options(verbose=True) |
| 165 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 187 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 166 gclient_scm.os.path.isdir(base_path).AndReturn(True) | 188 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
| 167 items = [ | 189 items = [ |
| 168 ('M ', 'a'), | 190 ('M ', 'a'), |
| 169 ('A ', 'b'), | 191 ('A ', 'b'), |
| 170 ] | 192 ] |
| 171 file_path1 = gclient_scm.os.path.join(base_path, 'a') | 193 file_path1 = gclient_scm.os.path.join(base_path, 'a') |
| 172 file_path2 = gclient_scm.os.path.join(base_path, 'b') | 194 file_path2 = gclient_scm.os.path.join(base_path, 'b') |
| 173 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) | 195 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) |
| 174 gclient_scm.os.path.exists(file_path1).AndReturn(True) | 196 gclient_scm.os.path.exists(file_path1).AndReturn(True) |
| 175 gclient_scm.os.path.isfile(file_path1).AndReturn(True) | 197 gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
| 176 gclient_scm.os.remove(file_path1) | 198 gclient_scm.os.remove(file_path1) |
| 177 gclient_scm.os.path.exists(file_path2).AndReturn(True) | 199 gclient_scm.os.path.exists(file_path2).AndReturn(True) |
| 178 gclient_scm.os.path.isfile(file_path2).AndReturn(True) | 200 gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
| 179 gclient_scm.os.remove(file_path2) | 201 gclient_scm.os.remove(file_path2) |
| 180 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 202 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 181 ['update', '--revision', 'BASE'], | 203 ['update', '--revision', 'BASE'], |
| 182 cwd=base_path, | 204 cwd=base_path, |
| 183 file_list=mox.IgnoreArg(), | 205 file_list=mox.IgnoreArg(), |
| 184 stdout=options.stdout) | 206 stdout=options.stdout) |
| 185 print(gclient_scm.os.path.join(base_path, 'a')) | |
| 186 print(gclient_scm.os.path.join(base_path, 'b')) | |
| 187 | 207 |
| 188 self.mox.ReplayAll() | 208 self.mox.ReplayAll() |
| 189 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 209 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 190 relpath=self.relpath) | 210 relpath=self.relpath) |
| 191 file_list = [] | 211 file_list = [] |
| 192 scm.revert(options, self.args, file_list) | 212 scm.revert(options, self.args, file_list) |
| 213 self.checkstdout( | |
| 214 ('%s\n%s\n' % (gclient_scm.os.path.join(base_path, 'a'), | |
| 215 gclient_scm.os.path.join(base_path, 'b')))) | |
| 193 | 216 |
| 194 def testRevertDirectory(self): | 217 def testRevertDirectory(self): |
| 195 options = self.Options(verbose=True) | 218 options = self.Options(verbose=True) |
| 196 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 219 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 197 gclient_scm.os.path.isdir(base_path).AndReturn(True) | 220 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
| 198 items = [ | 221 items = [ |
| 199 ('~ ', 'a'), | 222 ('~ ', 'a'), |
| 200 ] | 223 ] |
| 201 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) | 224 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) |
| 202 file_path = gclient_scm.os.path.join(base_path, 'a') | 225 file_path = gclient_scm.os.path.join(base_path, 'a') |
| 203 print(file_path) | |
| 204 gclient_scm.os.path.exists(file_path).AndReturn(True) | 226 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 205 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 227 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 206 gclient_scm.os.path.islink(file_path).AndReturn(False) | 228 gclient_scm.os.path.islink(file_path).AndReturn(False) |
| 207 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 229 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 208 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 230 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
| 209 file_list1 = [] | 231 file_list1 = [] |
| 210 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 232 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 211 ['update', '--revision', 'BASE'], | 233 ['update', '--revision', 'BASE'], |
| 212 cwd=base_path, | 234 cwd=base_path, |
| 213 file_list=mox.IgnoreArg(), | 235 file_list=mox.IgnoreArg(), |
| 214 stdout=options.stdout) | 236 stdout=options.stdout) |
| 215 | 237 |
| 216 self.mox.ReplayAll() | 238 self.mox.ReplayAll() |
| 217 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 239 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 218 relpath=self.relpath) | 240 relpath=self.relpath) |
| 219 file_list2 = [] | 241 file_list2 = [] |
| 220 scm.revert(options, self.args, file_list2) | 242 scm.revert(options, self.args, file_list2) |
| 243 self.checkstdout(('%s\n' % file_path)) | |
| 221 | 244 |
| 222 def testStatus(self): | 245 def testStatus(self): |
| 223 options = self.Options(verbose=True) | 246 options = self.Options(verbose=True) |
| 224 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 247 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 225 gclient_scm.os.path.isdir(base_path).AndReturn(True) | 248 gclient_scm.os.path.isdir(base_path).AndReturn(True) |
| 226 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 249 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 227 ['status'] + self.args, | 250 ['status'] + self.args, |
| 228 cwd=base_path, file_list=[], | 251 cwd=base_path, file_list=[], |
| 229 stdout=options.stdout).AndReturn(None) | 252 stdout=options.stdout).AndReturn(None) |
| 230 | 253 |
| 231 self.mox.ReplayAll() | 254 self.mox.ReplayAll() |
| 232 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 255 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 233 relpath=self.relpath) | 256 relpath=self.relpath) |
| 234 file_list = [] | 257 file_list = [] |
| 235 self.assertEqual(scm.status(options, self.args, file_list), None) | 258 self.assertEqual(scm.status(options, self.args, file_list), None) |
| 236 | 259 self.checkstdout('') |
| 237 | 260 |
| 238 # TODO(maruel): TEST REVISIONS!!! | 261 # TODO(maruel): TEST REVISIONS!!! |
| 239 # TODO(maruel): TEST RELOCATE!!! | 262 # TODO(maruel): TEST RELOCATE!!! |
| 240 def testUpdateCheckout(self): | 263 def testUpdateCheckout(self): |
| 241 options = self.Options(verbose=True) | 264 options = self.Options(verbose=True) |
| 242 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 265 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 243 file_info = gclient_scm.gclient_utils.PrintableObject() | 266 file_info = gclient_scm.gclient_utils.PrintableObject() |
| 244 file_info.root = 'blah' | 267 file_info.root = 'blah' |
| 245 file_info.url = self.url | 268 file_info.url = self.url |
| 246 file_info.uuid = 'ABC' | 269 file_info.uuid = 'ABC' |
| 247 file_info.revision = 42 | 270 file_info.revision = 42 |
| 248 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 271 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 249 ).AndReturn(False) | 272 ).AndReturn(False) |
| 250 # Checkout. | 273 # Checkout. |
| 251 gclient_scm.os.path.exists(base_path).AndReturn(False) | 274 gclient_scm.os.path.exists(base_path).AndReturn(False) |
| 252 files_list = self.mox.CreateMockAnything() | 275 files_list = self.mox.CreateMockAnything() |
| 253 gclient_scm.scm.SVN.Capture(['--version'] | 276 gclient_scm.scm.SVN.Capture(['--version'] |
| 254 ).AndReturn('svn, version 1.5.1 (r32289)') | 277 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 255 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 278 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
| 256 ['checkout', self.url, base_path, | 279 ['checkout', self.url, base_path, |
| 257 '--force'], | 280 '--force'], |
| 258 cwd=self.root_dir, | 281 cwd=self.root_dir, |
| 259 file_list=files_list, | 282 file_list=files_list, |
| 260 stdout=options.stdout) | 283 stdout=options.stdout) |
| 261 self.mox.ReplayAll() | 284 self.mox.ReplayAll() |
| 262 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 285 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 263 relpath=self.relpath) | 286 relpath=self.relpath) |
| 264 scm.update(options, (), files_list) | 287 scm.update(options, (), files_list) |
| 288 self.checkstdout('') | |
| 265 | 289 |
| 266 def testUpdateUpdate(self): | 290 def testUpdateUpdate(self): |
| 267 options = self.Options(verbose=True) | 291 options = self.Options(verbose=True) |
| 268 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 292 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 269 options.force = True | 293 options.force = True |
| 270 options.nohooks = False | 294 options.nohooks = False |
| 271 file_info = { | 295 file_info = { |
| 272 'Repository Root': 'blah', | 296 'Repository Root': 'blah', |
| 273 'URL': self.url, | 297 'URL': self.url, |
| 274 'UUID': 'ABC', | 298 'UUID': 'ABC', |
| 275 'Revision': 42, | 299 'Revision': 42, |
| 276 } | 300 } |
| 277 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 301 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 278 ).AndReturn(False) | 302 ).AndReturn(False) |
| 279 | 303 |
| 280 # Verify no locked files. | 304 # Verify no locked files. |
| 281 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 305 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') |
| 282 ).AndReturn([]) | 306 ).AndReturn([]) |
| 283 | 307 |
| 284 # Checkout or update. | 308 # Checkout or update. |
| 285 gclient_scm.os.path.exists(base_path).AndReturn(True) | 309 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 286 gclient_scm.scm.SVN.CaptureInfo( | 310 gclient_scm.scm.SVN.CaptureInfo( |
| 287 gclient_scm.os.path.join(base_path, "."), '.' | 311 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) |
| 288 ).AndReturn(file_info) | |
| 289 # Cheat a bit here. | 312 # Cheat a bit here. |
| 290 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) | 313 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
| 291 additional_args = [] | 314 additional_args = [] |
| 292 if options.manually_grab_svn_rev: | 315 if options.manually_grab_svn_rev: |
| 293 additional_args = ['--revision', str(file_info['Revision'])] | 316 additional_args = ['--revision', str(file_info['Revision'])] |
| 294 gclient_scm.scm.SVN.Capture(['--version'] | 317 gclient_scm.scm.SVN.Capture(['--version'] |
| 295 ).AndReturn('svn, version 1.5.1 (r32289)') | 318 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 296 additional_args.append('--force') | 319 additional_args.append('--force') |
| 297 files_list = [] | 320 files_list = [] |
| 298 gclient_scm.scm.SVN.RunAndGetFileList( | 321 gclient_scm.scm.SVN.RunAndGetFileList( |
| 299 options.verbose, | 322 options.verbose, |
| 300 ['update', base_path] + additional_args, | 323 ['update', base_path] + additional_args, |
| 301 cwd=self.root_dir, file_list=files_list, stdout=options.stdout) | 324 cwd=self.root_dir, file_list=files_list, stdout=options.stdout) |
| 302 | 325 |
| 303 self.mox.ReplayAll() | 326 self.mox.ReplayAll() |
| 304 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 327 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 305 relpath=self.relpath) | 328 relpath=self.relpath) |
| 306 scm.update(options, (), files_list) | 329 scm.update(options, (), files_list) |
| 330 self.checkstdout('') | |
| 307 | 331 |
| 308 def testUpdateSingleCheckout(self): | 332 def testUpdateSingleCheckout(self): |
| 309 options = self.Options(verbose=True) | 333 options = self.Options(verbose=True) |
| 310 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 334 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 311 file_info = { | 335 file_info = { |
| 312 'URL': self.url, | 336 'URL': self.url, |
| 313 'Revision': 42, | 337 'Revision': 42, |
| 314 } | 338 } |
| 315 | 339 |
| 316 # Checks to make sure that we support svn co --depth. | 340 # Checks to make sure that we support svn co --depth. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 332 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], | 356 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], |
| 333 always=True, cwd=self.root_dir, stdout=options.stdout) | 357 always=True, cwd=self.root_dir, stdout=options.stdout) |
| 334 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 358 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], |
| 335 cwd=base_path, file_list=files_list, stdout=options.stdout) | 359 cwd=base_path, file_list=files_list, stdout=options.stdout) |
| 336 | 360 |
| 337 # Now we fall back on scm.update(). | 361 # Now we fall back on scm.update(). |
| 338 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 362 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 339 ).AndReturn(False) | 363 ).AndReturn(False) |
| 340 gclient_scm.os.path.exists(base_path).AndReturn(True) | 364 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 341 gclient_scm.scm.SVN.CaptureInfo( | 365 gclient_scm.scm.SVN.CaptureInfo( |
| 342 gclient_scm.os.path.join(base_path, "."), '.' | 366 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) |
| 343 ).AndReturn(file_info) | 367 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
| 344 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) | |
| 345 options.stdout.write("\n_____ %s at 42" % self.relpath) | 368 options.stdout.write("\n_____ %s at 42" % self.relpath) |
| 346 options.stdout.write('\n') | 369 options.stdout.write('\n') |
| 347 | 370 |
| 348 self.mox.ReplayAll() | 371 self.mox.ReplayAll() |
| 349 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 372 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 350 relpath=self.relpath) | 373 relpath=self.relpath) |
| 351 scm.updatesingle(options, ['DEPS'], files_list) | 374 scm.updatesingle(options, ['DEPS'], files_list) |
| 375 self.checkstdout( | |
| 376 2 * ('\n_____ %s at 42\n' % self.relpath)) | |
| 352 | 377 |
| 353 def testUpdateSingleCheckoutSVN14(self): | 378 def testUpdateSingleCheckoutSVN14(self): |
| 354 options = self.Options(verbose=True) | 379 options = self.Options(verbose=True) |
| 355 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 380 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 356 file_info = { | 381 file_info = { |
| 357 'URL': self.url, | 382 'URL': self.url, |
| 358 'Revision': 42, | 383 'Revision': 42, |
| 359 } | 384 } |
| 360 | 385 |
| 361 # Checks to make sure that we support svn co --depth. | 386 # Checks to make sure that we support svn co --depth. |
| 362 gclient_scm.scm.SVN.current_version = None | 387 gclient_scm.scm.SVN.current_version = None |
| 363 gclient_scm.scm.SVN.Capture(['--version'] | 388 gclient_scm.scm.SVN.Capture(['--version'] |
| 364 ).AndReturn('svn, version 1.4.4 (r25188)') | 389 ).AndReturn('svn, version 1.4.4 (r25188)') |
| 365 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path) | 390 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path) |
| 366 ).AndReturn(True) | 391 ).AndReturn(True) |
| 367 | 392 |
| 368 # When checking out a single file with svn 1.4, we use svn export | 393 # When checking out a single file with svn 1.4, we use svn export |
| 369 files_list = self.mox.CreateMockAnything() | 394 files_list = self.mox.CreateMockAnything() |
| 370 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 395 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
| 371 ['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'), | 396 ['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'), |
| 372 gclient_scm.os.path.join(base_path, 'DEPS')], | 397 gclient_scm.os.path.join(base_path, 'DEPS')], |
| 373 always=True, cwd=self.root_dir, stdout=options.stdout) | 398 always=True, cwd=self.root_dir, stdout=options.stdout) |
| 374 | 399 |
| 375 self.mox.ReplayAll() | 400 self.mox.ReplayAll() |
| 376 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 401 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 377 relpath=self.relpath) | 402 relpath=self.relpath) |
| 378 scm.updatesingle(options, ['DEPS'], files_list) | 403 scm.updatesingle(options, ['DEPS'], files_list) |
| 404 self.checkstdout('') | |
| 379 | 405 |
| 380 def testUpdateSingleCheckoutSVNUpgrade(self): | 406 def testUpdateSingleCheckoutSVNUpgrade(self): |
| 381 options = self.Options(verbose=True) | 407 options = self.Options(verbose=True) |
| 382 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 408 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 383 file_info = { | 409 file_info = { |
| 384 'URL': self.url, | 410 'URL': self.url, |
| 385 'Revision': 42, | 411 'Revision': 42, |
| 386 } | 412 } |
| 387 | 413 |
| 388 # Checks to make sure that we support svn co --depth. | 414 # Checks to make sure that we support svn co --depth. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 407 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], | 433 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], |
| 408 always=True, cwd=self.root_dir, stdout=options.stdout) | 434 always=True, cwd=self.root_dir, stdout=options.stdout) |
| 409 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 435 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], |
| 410 cwd=base_path, file_list=files_list, stdout=options.stdout) | 436 cwd=base_path, file_list=files_list, stdout=options.stdout) |
| 411 | 437 |
| 412 # Now we fall back on scm.update(). | 438 # Now we fall back on scm.update(). |
| 413 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 439 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 414 ).AndReturn(False) | 440 ).AndReturn(False) |
| 415 gclient_scm.os.path.exists(base_path).AndReturn(True) | 441 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 416 gclient_scm.scm.SVN.CaptureInfo( | 442 gclient_scm.scm.SVN.CaptureInfo( |
| 417 gclient_scm.os.path.join(base_path, "."), '.' | 443 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) |
| 418 ).AndReturn(file_info) | 444 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
| 419 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) | |
| 420 print("\n_____ %s at 42" % self.relpath) | |
| 421 | 445 |
| 422 self.mox.ReplayAll() | 446 self.mox.ReplayAll() |
| 423 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 447 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 424 relpath=self.relpath) | 448 relpath=self.relpath) |
| 425 scm.updatesingle(options, ['DEPS'], files_list) | 449 scm.updatesingle(options, ['DEPS'], files_list) |
| 450 self.checkstdout( | |
| 451 ('\n_____ %s at 42\n' % self.relpath)) | |
| 426 | 452 |
| 427 def testUpdateSingleUpdate(self): | 453 def testUpdateSingleUpdate(self): |
| 428 options = self.Options(verbose=True) | 454 options = self.Options(verbose=True) |
| 429 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 455 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 430 file_info = { | 456 file_info = { |
| 431 'URL': self.url, | 457 'URL': self.url, |
| 432 'Revision': 42, | 458 'Revision': 42, |
| 433 } | 459 } |
| 434 # Checks to make sure that we support svn co --depth. | 460 # Checks to make sure that we support svn co --depth. |
| 435 gclient_scm.scm.SVN.current_version = None | 461 gclient_scm.scm.SVN.current_version = None |
| 436 gclient_scm.scm.SVN.Capture(['--version'] | 462 gclient_scm.scm.SVN.Capture(['--version'] |
| 437 ).AndReturn('svn, version 1.5.1 (r32289)') | 463 ).AndReturn('svn, version 1.5.1 (r32289)') |
| 438 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.svn') | 464 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.svn') |
| 439 ).AndReturn(True) | 465 ).AndReturn(True) |
| 440 | 466 |
| 441 # Verify no locked files. | 467 # Verify no locked files. |
| 442 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 468 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') |
| 443 ).AndReturn([]) | 469 ).AndReturn([]) |
| 444 | 470 |
| 445 # Now we fall back on scm.update(). | 471 # Now we fall back on scm.update(). |
| 446 files_list = self.mox.CreateMockAnything() | 472 files_list = self.mox.CreateMockAnything() |
| 447 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 473 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') |
| 448 ).AndReturn(False) | 474 ).AndReturn(False) |
| 449 gclient_scm.os.path.exists(base_path).AndReturn(True) | 475 gclient_scm.os.path.exists(base_path).AndReturn(True) |
| 450 gclient_scm.scm.SVN.CaptureInfo( | 476 gclient_scm.scm.SVN.CaptureInfo( |
| 451 gclient_scm.os.path.join(base_path, "."), '.' | 477 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) |
| 452 ).AndReturn(file_info) | 478 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
| 453 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info) | |
| 454 print("\n_____ %s at 42" % self.relpath) | |
| 455 | 479 |
| 456 self.mox.ReplayAll() | 480 self.mox.ReplayAll() |
| 457 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 481 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 458 relpath=self.relpath) | 482 relpath=self.relpath) |
| 459 scm.updatesingle(options, ['DEPS'], files_list) | 483 scm.updatesingle(options, ['DEPS'], files_list) |
| 484 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | |
| 460 | 485 |
| 461 def testUpdateGit(self): | 486 def testUpdateGit(self): |
| 462 options = self.Options(verbose=True) | 487 options = self.Options(verbose=True) |
| 463 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 488 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
| 464 gclient_scm.os.path.exists(file_path).AndReturn(True) | 489 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 465 print("________ found .git directory; skipping %s" % self.relpath) | |
| 466 | 490 |
| 467 self.mox.ReplayAll() | 491 self.mox.ReplayAll() |
| 468 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 492 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 469 relpath=self.relpath) | 493 relpath=self.relpath) |
| 470 file_list = [] | 494 file_list = [] |
| 471 scm.update(options, self.args, file_list) | 495 scm.update(options, self.args, file_list) |
|
bradn
2010/09/09 05:13:38
I suppose you could add self.expected_stdout defau
M-A Ruel
2010/09/09 13:24:15
scm.update() is the actual function being tested,
| |
| 496 self.checkstdout( | |
| 497 ('________ found .git directory; skipping %s\n' % self.relpath)) | |
| 472 | 498 |
| 473 | 499 |
| 474 class GitWrapperTestCase(BaseTestCase): | 500 class GitWrapperTestCase(BaseTestCase): |
| 475 """This class doesn't use pymox.""" | 501 """This class doesn't use pymox.""" |
| 476 class OptionsObject(object): | 502 class OptionsObject(object): |
| 477 def __init__(self, test_case, verbose=False, revision=None): | 503 def __init__(self, test_case, verbose=False, revision=None): |
| 478 self.verbose = verbose | 504 self.verbose = verbose |
| 479 self.revision = revision | 505 self.revision = revision |
| 480 self.manually_grab_svn_rev = True | 506 self.manually_grab_svn_rev = True |
| 481 self.deps_os = None | 507 self.deps_os = None |
| 482 self.force = False | 508 self.force = False |
| 483 self.reset = False | 509 self.reset = False |
| 484 self.nohooks = False | 510 self.nohooks = False |
| 511 self.stdout = StringIO.StringIO() | |
| 485 | 512 |
| 486 sample_git_import = """blob | 513 sample_git_import = """blob |
| 487 mark :1 | 514 mark :1 |
| 488 data 6 | 515 data 6 |
| 489 Hello | 516 Hello |
| 490 | 517 |
| 491 blob | 518 blob |
| 492 mark :2 | 519 mark :2 |
| 493 data 4 | 520 data 4 |
| 494 Bye | 521 Bye |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 stderr=STDOUT, cwd=path).communicate() | 580 stderr=STDOUT, cwd=path).communicate() |
| 554 return True | 581 return True |
| 555 | 582 |
| 556 def setUp(self): | 583 def setUp(self): |
| 557 self.args = self.Args() | 584 self.args = self.Args() |
| 558 self.url = 'git://foo' | 585 self.url = 'git://foo' |
| 559 self.root_dir = tempfile.mkdtemp() | 586 self.root_dir = tempfile.mkdtemp() |
| 560 self.relpath = '.' | 587 self.relpath = '.' |
| 561 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 588 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
| 562 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 589 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
| 563 SuperMoxBaseTestBase.setUp(self) | 590 BaseTestBase.setUp(self) |
| 564 | 591 |
| 565 def tearDown(self): | 592 def tearDown(self): |
| 566 SuperMoxBaseTestBase.tearDown(self) | 593 BaseTestBase.tearDown(self) |
| 567 rmtree(self.root_dir) | 594 rmtree(self.root_dir) |
| 568 | 595 |
| 569 def testDir(self): | 596 def testDir(self): |
| 570 members = [ | 597 members = [ |
| 571 'FullUrlForRelativeUrl', 'RunCommand', | 598 'FullUrlForRelativeUrl', 'RunCommand', |
| 572 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', | 599 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', |
| 573 'revinfo', 'runhooks', 'status', 'update', 'url', | 600 'revinfo', 'runhooks', 'status', 'update', 'url', |
| 574 ] | 601 ] |
| 575 | 602 |
| 576 # If you add a member, be sure to add the relevant test! | 603 # If you add a member, be sure to add the relevant test! |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 relpath=self.relpath) | 805 relpath=self.relpath) |
| 779 rev_info = scm.revinfo(options, (), None) | 806 rev_info = scm.revinfo(options, (), None) |
| 780 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 807 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
| 781 | 808 |
| 782 | 809 |
| 783 if __name__ == '__main__': | 810 if __name__ == '__main__': |
| 784 import unittest | 811 import unittest |
| 785 unittest.main() | 812 unittest.main() |
| 786 | 813 |
| 787 # vim: ts=2:sw=2:tw=80:et: | 814 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |