blob: e61101073f74cbc625bffc6228ad06fdc0613195 [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')
36 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo
37 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN')
38 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo')
39 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus')
40 self.mox.StubOutWithMock(gclient_scm, 'RunSVN')
41 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList')
42 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 = [
67 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
[email protected]0f282062009-11-06 20:14:0268 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status',
[email protected]e28e4982009-09-25 20:51:4569 'update', 'url',
70 ]
71
72 # If you add a member, be sure to add the relevant test!
73 self.compareMembers(self._scm_wrapper(), members)
74
75 def testUnsupportedSCM(self):
76 args = [self.url, self.root_dir, self.relpath]
77 kwargs = {'scm_name' : 'foo'}
78 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
79 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
80
81 def testFullUrlForRelativeUrl(self):
82 self.url = 'svn://a/b/c/d'
83
84 self.mox.ReplayAll()
85 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
86 relpath=self.relpath)
87 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
88
89 def testRunCommandException(self):
90 options = self.Options(verbose=False)
[email protected]8ef5f542009-11-12 02:05:0291 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
92 gclient_scm.os.path.exists(file_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:4593
94 self.mox.ReplayAll()
95 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
96 relpath=self.relpath)
97 exception = "Unsupported argument(s): %s" % ','.join(self.args)
98 self.assertRaisesError(exception, scm.RunCommand,
99 'update', options, self.args)
100
101 def testRunCommandUnknown(self):
102 # TODO(maruel): if ever used.
103 pass
104
105 def testRevertMissing(self):
106 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02107 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
108 gclient_scm.os.path.isdir(base_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45109 # It'll to a checkout instead.
[email protected]8ef5f542009-11-12 02:05:02110 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
111 ).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45112 print("\n_____ %s is missing, synching instead" % self.relpath)
113 # Checkout.
[email protected]8ef5f542009-11-12 02:05:02114 gclient_scm.os.path.exists(base_path).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45115 files_list = self.mox.CreateMockAnything()
[email protected]22e29d42009-10-28 00:48:26116 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path],
[email protected]e28e4982009-09-25 20:51:45117 self.root_dir, files_list)
118
119 self.mox.ReplayAll()
120 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
121 relpath=self.relpath)
122 scm.revert(options, self.args, files_list)
123
124 def testRevertNone(self):
125 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02126 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
127 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45128 gclient_scm.CaptureSVNStatus(base_path).AndReturn([])
[email protected]22e29d42009-10-28 00:48:26129 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
[email protected]e28e4982009-09-25 20:51:45130 base_path, mox.IgnoreArg())
131
132 self.mox.ReplayAll()
133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
134 relpath=self.relpath)
135 file_list = []
136 scm.revert(options, self.args, file_list)
137
138 def testRevert2Files(self):
139 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02140 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
141 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45142 items = [
143 ('M ', 'a'),
144 ('A ', 'b'),
145 ]
[email protected]8ef5f542009-11-12 02:05:02146 file_path1 = gclient_scm.os.path.join(base_path, 'a')
147 file_path2 = gclient_scm.os.path.join(base_path, 'b')
[email protected]e28e4982009-09-25 20:51:45148 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
149 gclient_scm.os.path.exists(file_path1).AndReturn(True)
150 gclient_scm.os.path.isfile(file_path1).AndReturn(True)
151 gclient_scm.os.remove(file_path1)
152 gclient_scm.os.path.exists(file_path2).AndReturn(True)
153 gclient_scm.os.path.isfile(file_path2).AndReturn(True)
154 gclient_scm.os.remove(file_path2)
[email protected]22e29d42009-10-28 00:48:26155 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
[email protected]e28e4982009-09-25 20:51:45156 base_path, mox.IgnoreArg())
[email protected]8ef5f542009-11-12 02:05:02157 print(gclient_scm.os.path.join(base_path, 'a'))
158 print(gclient_scm.os.path.join(base_path, 'b'))
[email protected]e28e4982009-09-25 20:51:45159
160 self.mox.ReplayAll()
161 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
162 relpath=self.relpath)
163 file_list = []
164 scm.revert(options, self.args, file_list)
165
166 def testRevertDirectory(self):
167 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02168 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
169 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45170 items = [
171 ('~ ', 'a'),
172 ]
173 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
[email protected]8ef5f542009-11-12 02:05:02174 file_path = gclient_scm.os.path.join(base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45175 print(file_path)
176 gclient_scm.os.path.exists(file_path).AndReturn(True)
177 gclient_scm.os.path.isfile(file_path).AndReturn(False)
178 gclient_scm.os.path.isdir(file_path).AndReturn(True)
[email protected]8ef5f542009-11-12 02:05:02179 gclient_scm.gclient_utils.RemoveDirectory(file_path)
[email protected]e28e4982009-09-25 20:51:45180 file_list1 = []
[email protected]22e29d42009-10-28 00:48:26181 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
[email protected]e28e4982009-09-25 20:51:45182 base_path, mox.IgnoreArg())
183
184 self.mox.ReplayAll()
185 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
186 relpath=self.relpath)
187 file_list2 = []
188 scm.revert(options, self.args, file_list2)
189
190 def testStatus(self):
191 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02192 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
193 gclient_scm.os.path.isdir(base_path).AndReturn(True)
[email protected]22e29d42009-10-28 00:48:26194 gclient_scm.RunSVNAndGetFileList(options, ['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]8ef5f542009-11-12 02:05:02219 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url,
[email protected]22e29d42009-10-28 00:48:26220 base_path], self.root_dir, files_list)
[email protected]e28e4982009-09-25 20:51:45221 self.mox.ReplayAll()
222 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
223 relpath=self.relpath)
224 scm.update(options, (), files_list)
225
226 def testUpdateUpdate(self):
227 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02228 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
[email protected]e28e4982009-09-25 20:51:45229 options.force = True
230 options.nohooks = False
231 file_info = {
232 'Repository Root': 'blah',
233 'URL': self.url,
234 'UUID': 'ABC',
235 'Revision': 42,
236 }
[email protected]8ef5f542009-11-12 02:05:02237 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
238 ).AndReturn(False)
[email protected]e28e4982009-09-25 20:51:45239 # Checkout or update.
[email protected]8ef5f542009-11-12 02:05:02240 gclient_scm.os.path.exists(base_path).AndReturn(True)
241 gclient_scm.CaptureSVNInfo(gclient_scm.os.path.join(base_path, "."), '.'
[email protected]e28e4982009-09-25 20:51:45242 ).AndReturn(file_info)
243 # Cheat a bit here.
244 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info)
245 additional_args = []
246 if options.manually_grab_svn_rev:
247 additional_args = ['--revision', str(file_info['Revision'])]
248 files_list = []
[email protected]22e29d42009-10-28 00:48:26249 gclient_scm.RunSVNAndGetFileList(options,
250 ['update', base_path] + additional_args,
[email protected]7753d242009-10-07 17:40:24251 self.root_dir, files_list)
[email protected]e28e4982009-09-25 20:51:45252
253 self.mox.ReplayAll()
254 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
255 relpath=self.relpath)
256 scm.update(options, (), files_list)
257
258 def testUpdateGit(self):
259 options = self.Options(verbose=True)
[email protected]8ef5f542009-11-12 02:05:02260 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
261 gclient_scm.os.path.exists(file_path).AndReturn(True)
[email protected]e28e4982009-09-25 20:51:45262 print("________ found .git directory; skipping %s" % self.relpath)
263
264 self.mox.ReplayAll()
265 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
266 relpath=self.relpath)
267 file_list = []
268 scm.update(options, self.args, file_list)
269
270 def testGetSVNFileInfo(self):
271 xml_text = r"""<?xml version="1.0"?>
272<info>
273<entry kind="file" path="%s" revision="14628">
274<url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
275<repository><root>http://src.chromium.org/svn</root></repository>
276<wc-info>
277<schedule>add</schedule>
278<depth>infinity</depth>
279<copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-url>
280<copy-from-rev>14628</copy-from-rev>
281<checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
282</wc-info>
283</entry>
284</info>
285""" % self.url
286 gclient_scm.CaptureSVN(['info', '--xml', self.url],
287 '.', True).AndReturn(xml_text)
288 expected = {
289 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
290 'UUID': None,
291 'Repository Root': 'http://src.chromium.org/svn',
292 'Schedule': 'add',
293 'Copied From URL':
294 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
295 'Copied From Rev': '14628',
296 'Path': self.url,
297 'Revision': 14628,
298 'Node Kind': 'file',
299 }
300 self.mox.ReplayAll()
301 file_info = self._CaptureSVNInfo(self.url, '.', True)
302 self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
303
304 def testCaptureSvnInfo(self):
305 xml_text = """<?xml version="1.0"?>
306<info>
307<entry
308 kind="dir"
309 path="."
310 revision="35">
311<url>%s</url>
312<repository>
313<root>%s</root>
314<uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
315</repository>
316<wc-info>
317<schedule>normal</schedule>
318<depth>infinity</depth>
319</wc-info>
320<commit
321 revision="35">
322<author>maruel</author>
323<date>2008-12-04T20:12:19.685120Z</date>
324</commit>
325</entry>
326</info>
327""" % (self.url, self.root_dir)
328 gclient_scm.CaptureSVN(['info', '--xml',
329 self.url], '.', True).AndReturn(xml_text)
330 self.mox.ReplayAll()
331 file_info = self._CaptureSVNInfo(self.url, '.', True)
332 expected = {
333 'URL': self.url,
334 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
335 'Revision': 35,
336 'Repository Root': self.root_dir,
337 'Schedule': 'normal',
338 'Copied From URL': None,
339 'Copied From Rev': None,
340 'Path': '.',
341 'Node Kind': 'dir',
342 }
343 self.assertEqual(file_info, expected)
344
[email protected]0f282062009-11-06 20:14:02345 def testRevinfo(self):
346 options = self.Options(verbose=False)
347 xml_text = """<?xml version="1.0"?>
348<info>
349<entry
350 kind="dir"
351 path="."
352 revision="35">
353<url>%s</url>
354<repository>
355<root>%s</root>
356<uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
357</repository>
358<wc-info>
359<schedule>normal</schedule>
360<depth>infinity</depth>
361</wc-info>
362<commit
363 revision="35">
364<author>maruel</author>
365<date>2008-12-04T20:12:19.685120Z</date>
366</commit>
367</entry>
368</info>
369""" % (self.url, self.root_dir)
[email protected]8ef5f542009-11-12 02:05:02370 gclient_scm.os.getcwd().AndReturn('bleh')
371 gclient_scm.CaptureSVN(['info', '--xml', self.url], 'bleh'
372 ).AndReturn(xml_text)
[email protected]0f282062009-11-06 20:14:02373 self.mox.ReplayAll()
374 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
375 relpath=self.relpath)
376 rev_info = scm.revinfo(options, self.args, None)
377 self.assertEqual(rev_info, '35')
378
[email protected]e28e4982009-09-25 20:51:45379
[email protected]8ef5f542009-11-12 02:05:02380class GitWrapperTestCase(SuperMoxBaseTestBase):
381 """This class doesn't use pymox."""
[email protected]e28e4982009-09-25 20:51:45382 class OptionsObject(object):
383 def __init__(self, test_case, verbose=False, revision=None):
384 self.verbose = verbose
385 self.revision = revision
386 self.manually_grab_svn_rev = True
387 self.deps_os = None
388 self.force = False
389 self.nohooks = False
390
391 sample_git_import = """blob
392mark :1
393data 6
394Hello
395
396blob
397mark :2
398data 4
399Bye
400
401reset refs/heads/master
402commit refs/heads/master
403mark :3
404author Bob <[email protected]> 1253744361 -0700
405committer Bob <[email protected]> 1253744361 -0700
406data 8
407A and B
408M 100644 :1 a
409M 100644 :2 b
410
411blob
412mark :4
413data 10
414Hello
415You
416
417blob
418mark :5
419data 8
420Bye
421You
422
423commit refs/heads/origin
424mark :6
425author Alice <[email protected]> 1253744424 -0700
426committer Alice <[email protected]> 1253744424 -0700
427data 13
428Personalized
429from :3
430M 100644 :4 a
431M 100644 :5 b
432
433reset refs/heads/master
434from :3
435"""
[email protected]e28e4982009-09-25 20:51:45436 def Options(self, *args, **kwargs):
437 return self.OptionsObject(self, *args, **kwargs)
438
439 def CreateGitRepo(self, git_import, path):
[email protected]ea6c2c52009-10-09 20:38:14440 try:
[email protected]8ef5f542009-11-12 02:05:02441 Popen(['git', 'init'], stdout=PIPE, stderr=STDOUT,
442 cwd=path).communicate()
443 except OSError:
[email protected]ea6c2c52009-10-09 20:38:14444 # git is not available, skip this test.
445 return False
[email protected]8ef5f542009-11-12 02:05:02446 Popen(['git', 'fast-import'], stdin=PIPE, stdout=PIPE, stderr=STDOUT,
447 cwd=path).communicate(input=git_import)
448 Popen(['git', 'checkout'], stdout=PIPE, stderr=STDOUT,
449 cwd=path).communicate()
[email protected]ea6c2c52009-10-09 20:38:14450 return True
[email protected]e28e4982009-09-25 20:51:45451
[email protected]e28e4982009-09-25 20:51:45452 def setUp(self):
[email protected]e28e4982009-09-25 20:51:45453 self.args = self.Args()
454 self.url = 'git://foo'
455 self.root_dir = tempfile.mkdtemp()
456 self.relpath = '.'
[email protected]8ef5f542009-11-12 02:05:02457 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
[email protected]ea6c2c52009-10-09 20:38:14458 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
[email protected]8ef5f542009-11-12 02:05:02459 SuperMoxBaseTestBase.setUp(self)
[email protected]e28e4982009-09-25 20:51:45460
461 def tearDown(self):
[email protected]8ef5f542009-11-12 02:05:02462 SuperMoxBaseTestBase.tearDown(self)
[email protected]e28e4982009-09-25 20:51:45463 shutil.rmtree(self.root_dir)
[email protected]e28e4982009-09-25 20:51:45464
465 def testDir(self):
466 members = [
467 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
[email protected]0f282062009-11-06 20:14:02468 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status',
469 'update', 'url',
[email protected]e28e4982009-09-25 20:51:45470 ]
471
472 # If you add a member, be sure to add the relevant test!
473 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
474
475 def testRevertMissing(self):
[email protected]ea6c2c52009-10-09 20:38:14476 if not self.enabled:
477 return
[email protected]e28e4982009-09-25 20:51:45478 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02479 file_path = gclient_scm.os.path.join(self.base_path, 'a')
480 gclient_scm.os.remove(file_path)
[email protected]e28e4982009-09-25 20:51:45481 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
482 relpath=self.relpath)
483 file_list = []
484 scm.revert(options, self.args, file_list)
485 self.assertEquals(file_list, [file_path])
486 file_list = []
487 scm.diff(options, self.args, file_list)
488 self.assertEquals(file_list, [])
489
490 def testRevertNone(self):
[email protected]ea6c2c52009-10-09 20:38:14491 if not self.enabled:
492 return
[email protected]e28e4982009-09-25 20:51:45493 options = self.Options()
494 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
495 relpath=self.relpath)
496 file_list = []
497 scm.revert(options, self.args, file_list)
498 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02499 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45500 '069c602044c5388d2d15c3f875b057c852003458')
501
502
503 def testRevertModified(self):
[email protected]ea6c2c52009-10-09 20:38:14504 if not self.enabled:
505 return
[email protected]e28e4982009-09-25 20:51:45506 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02507 file_path = gclient_scm.os.path.join(self.base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45508 open(file_path, 'a').writelines('touched\n')
509 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
510 relpath=self.relpath)
511 file_list = []
512 scm.revert(options, self.args, file_list)
513 self.assertEquals(file_list, [file_path])
514 file_list = []
515 scm.diff(options, self.args, file_list)
516 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02517 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45518 '069c602044c5388d2d15c3f875b057c852003458')
519
520 def testRevertNew(self):
[email protected]ea6c2c52009-10-09 20:38:14521 if not self.enabled:
522 return
[email protected]e28e4982009-09-25 20:51:45523 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02524 file_path = gclient_scm.os.path.join(self.base_path, 'c')
[email protected]e28e4982009-09-25 20:51:45525 f = open(file_path, 'w')
526 f.writelines('new\n')
527 f.close()
[email protected]8ef5f542009-11-12 02:05:02528 Popen(['git', 'add', 'c'], stdout=PIPE,
529 stderr=STDOUT, cwd=self.base_path).communicate()
[email protected]e28e4982009-09-25 20:51:45530 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
531 relpath=self.relpath)
532 file_list = []
533 scm.revert(options, self.args, file_list)
534 self.assertEquals(file_list, [file_path])
535 file_list = []
536 scm.diff(options, self.args, file_list)
537 self.assertEquals(file_list, [])
[email protected]0f282062009-11-06 20:14:02538 self.assertEquals(scm.revinfo(options, self.args, None),
[email protected]e28e4982009-09-25 20:51:45539 '069c602044c5388d2d15c3f875b057c852003458')
540
541 def testStatusNew(self):
[email protected]ea6c2c52009-10-09 20:38:14542 if not self.enabled:
543 return
[email protected]e28e4982009-09-25 20:51:45544 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02545 file_path = gclient_scm.os.path.join(self.base_path, 'a')
[email protected]e28e4982009-09-25 20:51:45546 open(file_path, 'a').writelines('touched\n')
547 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
548 relpath=self.relpath)
549 file_list = []
550 scm.status(options, self.args, file_list)
551 self.assertEquals(file_list, [file_path])
552
553 def testStatus2New(self):
[email protected]ea6c2c52009-10-09 20:38:14554 if not self.enabled:
555 return
[email protected]e28e4982009-09-25 20:51:45556 options = self.Options()
557 expected_file_list = []
558 for f in ['a', 'b']:
[email protected]8ef5f542009-11-12 02:05:02559 file_path = gclient_scm.os.path.join(self.base_path, f)
[email protected]e28e4982009-09-25 20:51:45560 open(file_path, 'a').writelines('touched\n')
561 expected_file_list.extend([file_path])
562 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
563 relpath=self.relpath)
564 file_list = []
565 scm.status(options, self.args, file_list)
[email protected]8ef5f542009-11-12 02:05:02566 expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
567 for x in ['a', 'b']]
[email protected]e28e4982009-09-25 20:51:45568 self.assertEquals(sorted(file_list), expected_file_list)
569
570 def testUpdateCheckout(self):
[email protected]ea6c2c52009-10-09 20:38:14571 if not self.enabled:
572 return
[email protected]e28e4982009-09-25 20:51:45573 options = self.Options(verbose=True)
574 root_dir = tempfile.mkdtemp()
575 relpath = 'foo'
[email protected]8ef5f542009-11-12 02:05:02576 base_path = gclient_scm.os.path.join(root_dir, relpath)
577 url = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
[email protected]e28e4982009-09-25 20:51:45578 try:
579 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir,
580 relpath=relpath)
581 file_list = []
582 scm.update(options, (), file_list)
583 self.assertEquals(len(file_list), 2)
[email protected]8ef5f542009-11-12 02:05:02584 self.assert_(gclient_scm.os.path.isfile(
585 gclient_scm.os.path.join(base_path, 'a')))
[email protected]0f282062009-11-06 20:14:02586 self.assertEquals(scm.revinfo(options, (), None),
[email protected]e28e4982009-09-25 20:51:45587 '069c602044c5388d2d15c3f875b057c852003458')
588 finally:
589 shutil.rmtree(root_dir)
590
591 def testUpdateUpdate(self):
[email protected]ea6c2c52009-10-09 20:38:14592 if not self.enabled:
593 return
[email protected]e28e4982009-09-25 20:51:45594 options = self.Options()
[email protected]8ef5f542009-11-12 02:05:02595 expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
596 for x in ['a', 'b']]
[email protected]e28e4982009-09-25 20:51:45597 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
598 relpath=self.relpath)
599 file_list = []
600 scm.update(options, (), file_list)
[email protected]0f282062009-11-06 20:14:02601 self.assertEquals(file_list, expected_file_list)
602 self.assertEquals(scm.revinfo(options, (), None),
[email protected]e28e4982009-09-25 20:51:45603 'a7142dc9f0009350b96a11f372b6ea658592aa95')
604
[email protected]0f282062009-11-06 20:14:02605 def testRevinfo(self):
606 if not self.enabled:
607 return
608 options = self.Options()
609 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
610 relpath=self.relpath)
611 rev_info = scm.revinfo(options, (), None)
612 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
613
[email protected]e28e4982009-09-25 20:51:45614
[email protected]8ef5f542009-11-12 02:05:02615class RunSVNTestCase(BaseTestCase):
[email protected]e28e4982009-09-25 20:51:45616 def testRunSVN(self):
[email protected]8ef5f542009-11-12 02:05:02617 self.UnMock(gclient_scm, 'RunSVN')
[email protected]e28e4982009-09-25 20:51:45618 param2 = 'bleh'
[email protected]8ef5f542009-11-12 02:05:02619 gclient_scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
620 param2).AndReturn(None)
[email protected]e28e4982009-09-25 20:51:45621 self.mox.ReplayAll()
622 gclient_scm.RunSVN(['foo', 'bar'], param2)
623
624
625if __name__ == '__main__':
[email protected]8ef5f542009-11-12 02:05:02626 import unittest
[email protected]e28e4982009-09-25 20:51:45627 unittest.main()
628
629# vim: ts=2:sw=2:tw=80:et: