blob: 99b4a9e1ce894d9e2659a538cadc8831fbeff2bb [file] [log] [blame]
[email protected]e28e4982009-09-25 20:51:451#!/usr/bin/python
2#
3# Copyright 2008-2009 Google Inc. All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (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
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Unit tests for gclient_scm.py."""
18
[email protected]e28e4982009-09-25 20:51:4519import shutil
[email protected]8ef5f542009-11-12 02:05:0220# Import it before super_mox to keep a valid reference.
21from subprocess import Popen, PIPE, STDOUT
[email protected]e28e4982009-09-25 20:51:4522import tempfile
[email protected]e28e4982009-09-25 20:51:4523
[email protected]e28e4982009-09-25 20:51:4524import gclient_scm
[email protected]8ef5f542009-11-12 02:05:0225from gclient_test import BaseTestCase as GCBaseTestCase
26from super_mox import mox, SuperMoxBaseTestBase
[email protected]e28e4982009-09-25 20:51:4527
28
[email protected]8ef5f542009-11-12 02:05:0229class BaseTestCase(GCBaseTestCase):
30 def setUp(self):
31 GCBaseTestCase.setUp(self)
32 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
33 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
34 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall')
35 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
[email protected]5aeb7dd2009-11-17 18:09:0136 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo
37 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
38 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo')
39 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
40 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Run')
41 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
[email protected]8ef5f542009-11-12 02:05:0242 self._scm_wrapper = gclient_scm.CreateSCM
43
44
45class SVNWrapperTestCase(BaseTestCase):
[email protected]e28e4982009-09-25 20:51:4546 class OptionsObject(object):
47 def __init__(self, test_case, verbose=False, revision=None):
48 self.verbose = verbose
49 self.revision = revision
50 self.manually_grab_svn_rev = True
51 self.deps_os = None
52 self.force = False
53 self.nohooks = False
54
[email protected]8ef5f542009-11-12 02:05:0255 def Options(self, *args, **kwargs):
56 return self.OptionsObject(self, *args, **kwargs)
57
[email protected]e28e4982009-09-25 20:51:4558 def setUp(self):
[email protected]8ef5f542009-11-12 02:05:0259 BaseTestCase.setUp(self)
[email protected]e28e4982009-09-25 20:51:4560 self.root_dir = self.Dir()
61 self.args = self.Args()
62 self.url = self.Url()
63 self.relpath = 'asf'
64
65 def testDir(self):
66 members = [
[email protected]5aeb7dd2009-11-17 18:09:0167 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
[email protected]c532e172009-12-15 17:18:3268 'CaptureStatus', 'DiffItem', 'GetEmail',
[email protected]37c629a2009-11-24 23:34:4369 'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run',
[email protected]c78f2462009-11-21 01:20:5770 'RunAndFilterOutput', 'RunAndGetFileList',
[email protected]5aeb7dd2009-11-17 18:09:0171 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
72 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
[email protected]e28e4982009-09-25 20:51:4573 ]
74
75 # If you add a member, be sure to add the relevant test!
76 self.compareMembers(self._scm_wrapper(), members)
77
78 def testUnsupportedSCM(self):
79 args = [self.url, self.root_dir, self.relpath]
80 kwargs = {'scm_name' : 'foo'}
81 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
82 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
83
[email protected]e28e4982009-09-25 20:51:4584 def testRunCommandException(self):
85 options = self.Options(verbose=False)
[email protected]8ef5f542009-11-12 02:05:0286 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
87 gclient_scm.os.path.exists(file_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:4588
89 self.mox.ReplayAll()
90 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
91 relpath=self.relpath)
92 exception = "Unsupported argument(s): %s" % ','.join(self.args)
93 self.assertRaisesError(exception, scm.RunCommand,
94 'update', options, self.args)
95
96 def testRunCommandUnknown(self):
97 # TODO(maruel): if ever used.
98 pass
99
100 def testRevertMissing(self):
101 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02102 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
103 gclient_scm.os.path.isdir(base_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45104 # It'll to a checkout instead.
[email protected]8ef5f542009-11-12 02:05:02105 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
106 ).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45107 print("\n_____ %s is missing, synching instead" % self.relpath)
108 # Checkout.
[email protected]8ef5f542009-11-12 02:05:02109 gclient_scm.os.path.exists(base_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45110 files_list = self.mox.CreateMockAnything()
[email protected]5aeb7dd2009-11-17 18:09:01111 gclient_scm.scm.SVN.RunAndGetFileList(options,
112 ['checkout', self.url, base_path],
113 self.root_dir, files_list)
[email protected]e28e4982009-09-25 20:51:45114
115 self.mox.ReplayAll()
116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
117 relpath=self.relpath)
118 scm.revert(options, self.args, files_list)
119
120 def testRevertNone(self):
121 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02122 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
123 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]5aeb7dd2009-11-17 18:09:01124 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([])
125 gclient_scm.scm.SVN.RunAndGetFileList(options,
126 ['update', '--revision', 'BASE'],
127 base_path, mox.IgnoreArg())
[email protected]e28e4982009-09-25 20:51:45128
129 self.mox.ReplayAll()
130 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
131 relpath=self.relpath)
132 file_list = []
133 scm.revert(options, self.args, file_list)
134
135 def testRevert2Files(self):
136 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02137 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
138 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45139 items = [
140 ('M ', 'a'),
141 ('A ', 'b'),
142 ]
[email protected]8ef5f542009-11-12 02:05:02143 file_path1 = gclient_scm.os.path.join(base_path, 'a')
144 file_path2 = gclient_scm.os.path.join(base_path, 'b')
[email protected]5aeb7dd2009-11-17 18:09:01145 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
[email protected]e28e4982009-09-25 20:51:45146 gclient_scm.os.path.exists(file_path1).AndReturn(True)
147 gclient_scm.os.path.isfile(file_path1).AndReturn(True)
148 gclient_scm.os.remove(file_path1)
149 gclient_scm.os.path.exists(file_path2).AndReturn(True)
150 gclient_scm.os.path.isfile(file_path2).AndReturn(True)
151 gclient_scm.os.remove(file_path2)
[email protected]5aeb7dd2009-11-17 18:09:01152 gclient_scm.scm.SVN.RunAndGetFileList(options,
153 ['update', '--revision', 'BASE'],
154 base_path, mox.IgnoreArg())
[email protected]8ef5f542009-11-12 02:05:02155 print(gclient_scm.os.path.join(base_path, 'a'))
156 print(gclient_scm.os.path.join(base_path, 'b'))
[email protected]e28e4982009-09-25 20:51:45157
158 self.mox.ReplayAll()
159 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
160 relpath=self.relpath)
161 file_list = []
162 scm.revert(options, self.args, file_list)
163
164 def testRevertDirectory(self):
165 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02166 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
167 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45168 items = [
169 ('~ ', 'a'),
170 ]
[email protected]5aeb7dd2009-11-17 18:09:01171 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
[email protected]8ef5f542009-11-12 02:05:02172 file_path = gclient_scm.os.path.join(base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45173 print(file_path)
174 gclient_scm.os.path.exists(file_path).AndReturn(True)
175 gclient_scm.os.path.isfile(file_path).AndReturn(False)
176 gclient_scm.os.path.isdir(file_path).AndReturn(True)
[email protected]8ef5f542009-11-12 02:05:02177 gclient_scm.gclient_utils.RemoveDirectory(file_path)
[email protected]e28e4982009-09-25 20:51:45178 file_list1 = []
[email protected]5aeb7dd2009-11-17 18:09:01179 gclient_scm.scm.SVN.RunAndGetFileList(options,
180 ['update', '--revision', 'BASE'],
181 base_path, mox.IgnoreArg())
[email protected]e28e4982009-09-25 20:51:45182
183 self.mox.ReplayAll()
184 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
185 relpath=self.relpath)
186 file_list2 = []
187 scm.revert(options, self.args, file_list2)
188
189 def testStatus(self):
190 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02191 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
192 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]5aeb7dd2009-11-17 18:09:01193 gclient_scm.scm.SVN.RunAndGetFileList(options,
194 ['status'] + self.args,
195 base_path, []).AndReturn(None)
[email protected]e28e4982009-09-25 20:51:45196
197 self.mox.ReplayAll()
198 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
199 relpath=self.relpath)
200 file_list = []
201 self.assertEqual(scm.status(options, self.args, file_list), None)
202
203
204 # TODO(maruel): TEST REVISIONS!!!
205 # TODO(maruel): TEST RELOCATE!!!
206 def testUpdateCheckout(self):
207 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02208 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
209 file_info = gclient_scm.gclient_utils.PrintableObject()
[email protected]e28e4982009-09-25 20:51:45210 file_info.root = 'blah'
211 file_info.url = self.url
212 file_info.uuid = 'ABC'
213 file_info.revision = 42
[email protected]8ef5f542009-11-12 02:05:02214 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
215 ).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45216 # Checkout.
[email protected]8ef5f542009-11-12 02:05:02217 gclient_scm.os.path.exists(base_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45218 files_list = self.mox.CreateMockAnything()
[email protected]5aeb7dd2009-11-17 18:09:01219 gclient_scm.scm.SVN.RunAndGetFileList(options,
220 ['checkout', self.url, base_path],
221 self.root_dir, files_list)
[email protected]e28e4982009-09-25 20:51:45222 self.mox.ReplayAll()
223 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
224 relpath=self.relpath)
225 scm.update(options, (), files_list)
226
227 def testUpdateUpdate(self):
228 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02229 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
[email protected]e28e4982009-09-25 20:51:45230 options.force = True
231 options.nohooks = False
232 file_info = {
233 'Repository Root': 'blah',
234 'URL': self.url,
235 'UUID': 'ABC',
236 'Revision': 42,
237 }
[email protected]8ef5f542009-11-12 02:05:02238 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
239 ).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45240 # Checkout or update.
[email protected]8ef5f542009-11-12 02:05:02241 gclient_scm.os.path.exists(base_path).AndReturn(True)
[email protected]5aeb7dd2009-11-17 18:09:01242 gclient_scm.scm.SVN.CaptureInfo(
243 gclient_scm.os.path.join(base_path, "."), '.'
244 ).AndReturn(file_info)
[email protected]e28e4982009-09-25 20:51:45245 # Cheat a bit here.
[email protected]5aeb7dd2009-11-17 18:09:01246 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
[email protected]e28e4982009-09-25 20:51:45247 additional_args = []
248 if options.manually_grab_svn_rev:
249 additional_args = ['--revision', str(file_info['Revision'])]
250 files_list = []
[email protected]5aeb7dd2009-11-17 18:09:01251 gclient_scm.scm.SVN.RunAndGetFileList(
252 options,
253 ['update', base_path] + additional_args,
254 self.root_dir, files_list)
[email protected]e28e4982009-09-25 20:51:45255
256 self.mox.ReplayAll()
257 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
258 relpath=self.relpath)
259 scm.update(options, (), files_list)
260
261 def testUpdateGit(self):
262 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02263 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
264 gclient_scm.os.path.exists(file_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45265 print("________ found .git directory; skipping %s" % self.relpath)
266
267 self.mox.ReplayAll()
268 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
269 relpath=self.relpath)
270 file_list = []
271 scm.update(options, self.args, file_list)
272
[email protected]e28e4982009-09-25 20:51:45273
[email protected]5bde4852009-12-14 16:47:12274class GitWrapperTestCase(BaseTestCase):
[email protected]8ef5f542009-11-12 02:05:02275 """This class doesn't use pymox."""
[email protected]e28e4982009-09-25 20:51:45276 class OptionsObject(object):
277 def __init__(self, test_case, verbose=False, revision=None):
278 self.verbose = verbose
279 self.revision = revision
280 self.manually_grab_svn_rev = True
281 self.deps_os = None
282 self.force = False
283 self.nohooks = False
284
285 sample_git_import = """blob
286mark :1
287data 6
288Hello
289
290blob
291mark :2
292data 4
293Bye
294
295reset refs/heads/master
296commit refs/heads/master
297mark :3
298author Bob <[email protected]> 1253744361 -0700
299committer Bob <[email protected]> 1253744361 -0700
300data 8
301A and B
302M 100644 :1 a
303M 100644 :2 b
304
305blob
306mark :4
307data 10
308Hello
309You
310
311blob
312mark :5
313data 8
314Bye
315You
316
317commit refs/heads/origin
318mark :6
319author Alice <[email protected]> 1253744424 -0700
320committer Alice <[email protected]> 1253744424 -0700
321data 13
322Personalized
323from :3
324M 100644 :4 a
325M 100644 :5 b
326
327reset refs/heads/master
328from :3
329"""
[email protected]e28e4982009-09-25 20:51:45330 def Options(self, *args, **kwargs):
331 return self.OptionsObject(self, *args, **kwargs)
332
333 def CreateGitRepo(self, git_import, path):
[email protected]d5800f12009-11-12 20:03:43334 """Do it for real."""
[email protected]ea6c2c52009-10-09 20:38:14335 try:
[email protected]8ef5f542009-11-12 02:05:02336 Popen(['git', 'init'], stdout=PIPE, stderr=STDOUT,
337 cwd=path).communicate()
338 except OSError:
[email protected]ea6c2c52009-10-09 20:38:14339 # git is not available, skip this test.
340 return False
[email protected]8ef5f542009-11-12 02:05:02341 Popen(['git', 'fast-import'], stdin=PIPE, stdout=PIPE, stderr=STDOUT,
342 cwd=path).communicate(input=git_import)
343 Popen(['git', 'checkout'], stdout=PIPE, stderr=STDOUT,
344 cwd=path).communicate()
[email protected]ea6c2c52009-10-09 20:38:14345 return True
[email protected]e28e4982009-09-25 20:51:45346
[email protected]e28e4982009-09-25 20:51:45347 def setUp(self):
[email protected]e28e4982009-09-25 20:51:45348 self.args = self.Args()
349 self.url = 'git://foo'
350 self.root_dir = tempfile.mkdtemp()
351 self.relpath = '.'
[email protected]8ef5f542009-11-12 02:05:02352 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
[email protected]ea6c2c52009-10-09 20:38:14353 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
[email protected]8ef5f542009-11-12 02:05:02354 SuperMoxBaseTestBase.setUp(self)
[email protected]e28e4982009-09-25 20:51:45355
356 def tearDown(self):
[email protected]8ef5f542009-11-12 02:05:02357 SuperMoxBaseTestBase.tearDown(self)
[email protected]e28e4982009-09-25 20:51:45358 shutil.rmtree(self.root_dir)
[email protected]e28e4982009-09-25 20:51:45359
360 def testDir(self):
361 members = [
[email protected]c532e172009-12-15 17:18:32362 'COMMAND', 'Capture', 'CaptureStatus', 'GetEmail',
[email protected]5aeb7dd2009-11-17 18:09:01363 'RunCommand', 'cleanup', 'diff', 'export', 'relpath', 'revert',
364 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
[email protected]e28e4982009-09-25 20:51:45365 ]
366
367 # If you add a member, be sure to add the relevant test!
368 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
369
370 def testRevertMissing(self):
[email protected]ea6c2c52009-10-09 20:38:14371 if not self.enabled:
372 return
[email protected]e28e4982009-09-25 20:51:45373 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02374 file_path = gclient_scm.os.path.join(self.base_path, 'a')
375 gclient_scm.os.remove(file_path)
[email protected]e28e4982009-09-25 20:51:45376 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
377 relpath=self.relpath)
378 file_list = []
379 scm.revert(options, self.args, file_list)
380 self.assertEquals(file_list, [file_path])
381 file_list = []
382 scm.diff(options, self.args, file_list)
383 self.assertEquals(file_list, [])
384
385 def testRevertNone(self):
[email protected]ea6c2c52009-10-09 20:38:14386 if not self.enabled:
387 return
[email protected]e28e4982009-09-25 20:51:45388 options = self.Options()
389 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
390 relpath=self.relpath)
391 file_list = []
392 scm.revert(options, self.args, file_list)
393 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02394 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45395 '069c602044c5388d2d15c3f875b057c852003458')
396
397
398 def testRevertModified(self):
[email protected]ea6c2c52009-10-09 20:38:14399 if not self.enabled:
400 return
[email protected]e28e4982009-09-25 20:51:45401 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02402 file_path = gclient_scm.os.path.join(self.base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45403 open(file_path, 'a').writelines('touched\n')
404 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
405 relpath=self.relpath)
406 file_list = []
407 scm.revert(options, self.args, file_list)
408 self.assertEquals(file_list, [file_path])
409 file_list = []
410 scm.diff(options, self.args, file_list)
411 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02412 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45413 '069c602044c5388d2d15c3f875b057c852003458')
414
415 def testRevertNew(self):
[email protected]ea6c2c52009-10-09 20:38:14416 if not self.enabled:
417 return
[email protected]e28e4982009-09-25 20:51:45418 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02419 file_path = gclient_scm.os.path.join(self.base_path, 'c')
[email protected]e28e4982009-09-25 20:51:45420 f = open(file_path, 'w')
421 f.writelines('new\n')
422 f.close()
[email protected]8ef5f542009-11-12 02:05:02423 Popen(['git', 'add', 'c'], stdout=PIPE,
424 stderr=STDOUT, cwd=self.base_path).communicate()
[email protected]e28e4982009-09-25 20:51:45425 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
426 relpath=self.relpath)
427 file_list = []
428 scm.revert(options, self.args, file_list)
429 self.assertEquals(file_list, [file_path])
430 file_list = []
431 scm.diff(options, self.args, file_list)
432 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02433 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45434 '069c602044c5388d2d15c3f875b057c852003458')
435
436 def testStatusNew(self):
[email protected]ea6c2c52009-10-09 20:38:14437 if not self.enabled:
438 return
[email protected]e28e4982009-09-25 20:51:45439 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02440 file_path = gclient_scm.os.path.join(self.base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45441 open(file_path, 'a').writelines('touched\n')
442 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
443 relpath=self.relpath)
444 file_list = []
445 scm.status(options, self.args, file_list)
446 self.assertEquals(file_list, [file_path])
447
448 def testStatus2New(self):
[email protected]ea6c2c52009-10-09 20:38:14449 if not self.enabled:
450 return
[email protected]e28e4982009-09-25 20:51:45451 options = self.Options()
452 expected_file_list = []
453 for f in ['a', 'b']:
[email protected]8ef5f542009-11-12 02:05:02454 file_path = gclient_scm.os.path.join(self.base_path, f)
[email protected]e28e4982009-09-25 20:51:45455 open(file_path, 'a').writelines('touched\n')
456 expected_file_list.extend([file_path])
457 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
458 relpath=self.relpath)
459 file_list = []
460 scm.status(options, self.args, file_list)
[email protected]8ef5f542009-11-12 02:05:02461 expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
462 for x in ['a', 'b']]
[email protected]e28e4982009-09-25 20:51:45463 self.assertEquals(sorted(file_list), expected_file_list)
464
465 def testUpdateCheckout(self):
[email protected]ea6c2c52009-10-09 20:38:14466 if not self.enabled:
467 return
[email protected]e28e4982009-09-25 20:51:45468 options = self.Options(verbose=True)
469 root_dir = tempfile.mkdtemp()
470 relpath = 'foo'
[email protected]8ef5f542009-11-12 02:05:02471 base_path = gclient_scm.os.path.join(root_dir, relpath)
472 url = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
[email protected]e28e4982009-09-25 20:51:45473 try:
474 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir,
475 relpath=relpath)
476 file_list = []
477 scm.update(options, (), file_list)
478 self.assertEquals(len(file_list), 2)
[email protected]8ef5f542009-11-12 02:05:02479 self.assert_(gclient_scm.os.path.isfile(
480 gclient_scm.os.path.join(base_path, 'a')))
[email protected]0f282062009-11-06 20:14:02481 self.assertEquals(scm.revinfo(options, (), None),
[email protected]e28e4982009-09-25 20:51:45482 '069c602044c5388d2d15c3f875b057c852003458')
483 finally:
484 shutil.rmtree(root_dir)
485
486 def testUpdateUpdate(self):
[email protected]ea6c2c52009-10-09 20:38:14487 if not self.enabled:
488 return
[email protected]e28e4982009-09-25 20:51:45489 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02490 expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
491 for x in ['a', 'b']]
[email protected]e28e4982009-09-25 20:51:45492 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
493 relpath=self.relpath)
494 file_list = []
495 scm.update(options, (), file_list)
[email protected]0f282062009-11-06 20:14:02496 self.assertEquals(file_list, expected_file_list)
497 self.assertEquals(scm.revinfo(options, (), None),
[email protected]e28e4982009-09-25 20:51:45498 'a7142dc9f0009350b96a11f372b6ea658592aa95')
499
[email protected]5bde4852009-12-14 16:47:12500 def testUpdateConflict(self):
501 if not self.enabled:
502 return
503 options = self.Options()
504 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
505 relpath=self.relpath)
506 file_path = gclient_scm.os.path.join(self.base_path, 'b')
507 f = open(file_path, 'w').writelines('conflict\n')
508 scm._Run(['commit', '-am', 'test'])
509 exception = \
510 '\n____ .\n' \
511 '\nConflict while rebasing this branch.\n' \
512 'Fix the conflict and run gclient again.\n' \
513 'See man git-rebase for details.\n'
514 self.assertRaisesError(exception, scm.update, options, (), [])
515 exception = \
516 '\n____ .\n' \
517 '\tAlready in a conflict, i.e. (no branch).\n' \
518 '\tFix the conflict and run gclient again.\n' \
519 '\tOr to abort run:\n\t\tgit-rebase --abort\n' \
520 '\tSee man git-rebase for details.\n'
521 self.assertRaisesError(exception, scm.update, options, (), [])
522
[email protected]0f282062009-11-06 20:14:02523 def testRevinfo(self):
524 if not self.enabled:
525 return
526 options = self.Options()
527 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
528 relpath=self.relpath)
529 rev_info = scm.revinfo(options, (), None)
530 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
531
[email protected]e28e4982009-09-25 20:51:45532
[email protected]e28e4982009-09-25 20:51:45533if __name__ == '__main__':
[email protected]8ef5f542009-11-12 02:05:02534 import unittest
[email protected]e28e4982009-09-25 20:51:45535 unittest.main()
536
537# vim: ts=2:sw=2:tw=80:et: