Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: tests/gclient_scm_test.py

Issue 3473003: Add automated sys.stdout check. (Closed)
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/gcl_unittest.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import StringIO
12 from subprocess import Popen, PIPE, STDOUT 12 from subprocess import Popen, PIPE, STDOUT
13 import tempfile 13 import tempfile
14 import unittest 14 import unittest
15 import __builtin__ 15 import __builtin__
16 16
17 # Fixes include path. 17 # Fixes include path.
18 from super_mox import mox, TestCaseUtils, SuperMoxTestBase 18 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase
19 19
20 import gclient_scm 20 import gclient_scm
21 21
22 22
23 class GCBaseTestCase(object): 23 class GCBaseTestCase(object):
24 def assertRaisesError(self, msg, fn, *args, **kwargs): 24 def assertRaisesError(self, msg, fn, *args, **kwargs):
25 """Like unittest's assertRaises() but checks for Gclient.Error.""" 25 """Like unittest's assertRaises() but checks for Gclient.Error."""
26 try: 26 try:
27 fn(*args, **kwargs) 27 fn(*args, **kwargs)
28 except gclient_scm.gclient_utils.Error, e: 28 except gclient_scm.gclient_utils.Error, e:
29 self.assertEquals(e.args[0], msg) 29 self.assertEquals(e.args[0], msg)
30 else: 30 else:
31 self.fail('%s not raised' % msg) 31 self.fail('%s not raised' % msg)
32 32
33 def setUp(self):
34 self.stdout = StringIO.StringIO()
35
36 def tearDown(self):
37 try:
38 self.stdout.getvalue()
39 self.fail()
40 except AttributeError:
41 pass
42
43 def checkstdout(self, expected):
44 value = self.stdout.getvalue()
45 self.stdout.close()
46 self.assertEquals(expected, value)
47
48 33
49 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): 34 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase):
50 def setUp(self): 35 def setUp(self):
51 GCBaseTestCase.setUp(self)
52 SuperMoxTestBase.setUp(self) 36 SuperMoxTestBase.setUp(self)
53 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCall') 37 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCall')
54 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter') 38 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'CheckCallAndFilter')
55 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 39 self.mox.StubOutWithMock(gclient_scm.gclient_utils,
56 'CheckCallAndFilterAndHeader') 40 'CheckCallAndFilterAndHeader')
57 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') 41 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
58 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') 42 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
59 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'Popen') 43 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'Popen')
60 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') 44 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
61 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo 45 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo
62 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') 46 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
63 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') 47 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo')
64 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') 48 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
65 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') 49 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
66 self._scm_wrapper = gclient_scm.CreateSCM 50 self._scm_wrapper = gclient_scm.CreateSCM
67 gclient_scm.sys.stdout.flush = lambda: None
68 gclient_scm.scm.SVN.current_version = None 51 gclient_scm.scm.SVN.current_version = None
69 52
70 def tearDown(self): 53 def tearDown(self):
71 GCBaseTestCase.tearDown(self)
72 SuperMoxTestBase.tearDown(self) 54 SuperMoxTestBase.tearDown(self)
73 55
74 56
75 class SVNWrapperTestCase(BaseTestCase): 57 class SVNWrapperTestCase(BaseTestCase):
76 class OptionsObject(object): 58 class OptionsObject(object):
77 def __init__(self, test_case, verbose=False, revision=None): 59 def __init__(self, test_case, verbose=False, revision=None):
78 self.verbose = verbose 60 self.verbose = verbose
79 self.revision = revision 61 self.revision = revision
80 self.manually_grab_svn_rev = True 62 self.manually_grab_svn_rev = True
81 self.deps_os = None 63 self.deps_os = None
82 self.force = False 64 self.force = False
83 self.reset = False 65 self.reset = False
84 self.nohooks = False 66 self.nohooks = False
85 self.stdout = test_case.stdout 67 self.stdout = gclient_scm.sys.stdout
86 68
87 def Options(self, *args, **kwargs): 69 def Options(self, *args, **kwargs):
88 return self.OptionsObject(self, *args, **kwargs) 70 return self.OptionsObject(self, *args, **kwargs)
89 71
90 def setUp(self): 72 def setUp(self):
91 BaseTestCase.setUp(self) 73 BaseTestCase.setUp(self)
92 self.url = self.SvnUrl() 74 self.url = self.SvnUrl()
93 75
94 def testDir(self): 76 def testDir(self):
95 members = [ 77 members = [
96 'FullUrlForRelativeUrl', 'RunCommand', 78 'FullUrlForRelativeUrl', 'RunCommand',
97 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 79 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
98 'revinfo', 'runhooks', 'status', 'update', 80 'revinfo', 'runhooks', 'status', 'update',
99 'updatesingle', 'url', 81 'updatesingle', 'url',
100 ] 82 ]
101 83
102 # If you add a member, be sure to add the relevant test! 84 # If you add a member, be sure to add the relevant test!
103 self.compareMembers(self._scm_wrapper('svn://a'), members) 85 self.compareMembers(self._scm_wrapper('svn://a'), members)
104 self.checkstdout('')
105 86
106 def testUnsupportedSCM(self): 87 def testUnsupportedSCM(self):
107 args = ['gopher://foo', self.root_dir, self.relpath] 88 args = ['gopher://foo', self.root_dir, self.relpath]
108 exception_msg = 'No SCM found for url gopher://foo' 89 exception_msg = 'No SCM found for url gopher://foo'
109 self.assertRaisesError(exception_msg, self._scm_wrapper, *args) 90 self.assertRaisesError(exception_msg, self._scm_wrapper, *args)
110 self.checkstdout('')
111 91
112 def testSVNFullUrlForRelativeUrl(self): 92 def testSVNFullUrlForRelativeUrl(self):
113 self.url = 'svn://a/b/c/d' 93 self.url = 'svn://a/b/c/d'
114 94
115 self.mox.ReplayAll() 95 self.mox.ReplayAll()
116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 96 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
117 relpath=self.relpath) 97 relpath=self.relpath)
118 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') 98 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
119 self.checkstdout('')
120 99
121 def testGITFullUrlForRelativeUrl(self): 100 def testGITFullUrlForRelativeUrl(self):
122 self.url = 'git://a/b/c/d' 101 self.url = 'git://a/b/c/d'
123 102
124 self.mox.ReplayAll() 103 self.mox.ReplayAll()
125 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 104 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
126 relpath=self.relpath) 105 relpath=self.relpath)
127 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') 106 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap')
128 self.checkstdout('')
129 107
130 def testRunCommandException(self): 108 def testRunCommandException(self):
131 options = self.Options(verbose=False) 109 options = self.Options(verbose=False)
132 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 110 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
133 gclient_scm.os.path.exists(file_path).AndReturn(False) 111 gclient_scm.os.path.exists(file_path).AndReturn(False)
134 112
135 self.mox.ReplayAll() 113 self.mox.ReplayAll()
136 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 114 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
137 relpath=self.relpath) 115 relpath=self.relpath)
138 exception = "Unsupported argument(s): %s" % ','.join(self.args) 116 exception = "Unsupported argument(s): %s" % ','.join(self.args)
139 self.assertRaisesError(exception, scm.RunCommand, 117 self.assertRaisesError(exception, scm.RunCommand,
140 'update', options, self.args) 118 'update', options, self.args)
141 self.checkstdout('')
142 119
143 def testRunCommandUnknown(self): 120 def testRunCommandUnknown(self):
144 # TODO(maruel): if ever used. 121 # TODO(maruel): if ever used.
145 self.checkstdout('') 122 pass
146 123
147 def testRevertMissing(self): 124 def testRevertMissing(self):
148 options = self.Options(verbose=True) 125 options = self.Options(verbose=True)
149 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 126 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
150 gclient_scm.os.path.isdir(base_path).AndReturn(False) 127 gclient_scm.os.path.isdir(base_path).AndReturn(False)
151 gclient_scm.scm.SVN.Capture(['--version'] 128 gclient_scm.scm.SVN.Capture(['--version']
152 ).AndReturn('svn, version 1.5.1 (r32289)') 129 ).AndReturn('svn, version 1.5.1 (r32289)')
153 # It'll to a checkout instead. 130 # It'll to a checkout instead.
154 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 131 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
155 ).AndReturn(False) 132 ).AndReturn(False)
(...skipping 23 matching lines...) Expand all
179 ['update', '--revision', 'BASE'], 156 ['update', '--revision', 'BASE'],
180 cwd=base_path, 157 cwd=base_path,
181 file_list=mox.IgnoreArg(), 158 file_list=mox.IgnoreArg(),
182 stdout=options.stdout) 159 stdout=options.stdout)
183 160
184 self.mox.ReplayAll() 161 self.mox.ReplayAll()
185 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 162 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
186 relpath=self.relpath) 163 relpath=self.relpath)
187 file_list = [] 164 file_list = []
188 scm.revert(options, self.args, file_list) 165 scm.revert(options, self.args, file_list)
189 self.checkstdout('')
190 166
191 def testRevert2Files(self): 167 def testRevert2Files(self):
192 options = self.Options(verbose=True) 168 options = self.Options(verbose=True)
193 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)
194 gclient_scm.os.path.isdir(base_path).AndReturn(True) 170 gclient_scm.os.path.isdir(base_path).AndReturn(True)
195 items = [ 171 items = [
196 ('M ', 'a'), 172 ('M ', 'a'),
197 ('A ', 'b'), 173 ('A ', 'b'),
198 ] 174 ]
199 file_path1 = gclient_scm.os.path.join(base_path, 'a') 175 file_path1 = gclient_scm.os.path.join(base_path, 'a')
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, 231 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
256 ['status'] + self.args, 232 ['status'] + self.args,
257 cwd=base_path, file_list=[], 233 cwd=base_path, file_list=[],
258 stdout=options.stdout).AndReturn(None) 234 stdout=options.stdout).AndReturn(None)
259 235
260 self.mox.ReplayAll() 236 self.mox.ReplayAll()
261 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 237 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
262 relpath=self.relpath) 238 relpath=self.relpath)
263 file_list = [] 239 file_list = []
264 self.assertEqual(scm.status(options, self.args, file_list), None) 240 self.assertEqual(scm.status(options, self.args, file_list), None)
265 self.checkstdout('')
266 241
267 # TODO(maruel): TEST REVISIONS!!! 242 # TODO(maruel): TEST REVISIONS!!!
268 # TODO(maruel): TEST RELOCATE!!! 243 # TODO(maruel): TEST RELOCATE!!!
269 def testUpdateCheckout(self): 244 def testUpdateCheckout(self):
270 options = self.Options(verbose=True) 245 options = self.Options(verbose=True)
271 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 246 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
272 file_info = gclient_scm.gclient_utils.PrintableObject() 247 file_info = gclient_scm.gclient_utils.PrintableObject()
273 file_info.root = 'blah' 248 file_info.root = 'blah'
274 file_info.url = self.url 249 file_info.url = self.url
275 file_info.uuid = 'ABC' 250 file_info.uuid = 'ABC'
276 file_info.revision = 42 251 file_info.revision = 42
277 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 252 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
278 ).AndReturn(False) 253 ).AndReturn(False)
279 # Checkout. 254 # Checkout.
280 gclient_scm.os.path.exists(base_path).AndReturn(False) 255 gclient_scm.os.path.exists(base_path).AndReturn(False)
281 files_list = self.mox.CreateMockAnything() 256 files_list = self.mox.CreateMockAnything()
282 gclient_scm.scm.SVN.Capture(['--version'] 257 gclient_scm.scm.SVN.Capture(['--version']
283 ).AndReturn('svn, version 1.5.1 (r32289)') 258 ).AndReturn('svn, version 1.5.1 (r32289)')
284 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, 259 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose,
285 ['checkout', self.url, base_path, 260 ['checkout', self.url, base_path,
286 '--force'], 261 '--force'],
287 cwd=self.root_dir, 262 cwd=self.root_dir,
288 file_list=files_list, 263 file_list=files_list,
289 stdout=options.stdout) 264 stdout=options.stdout)
290 self.mox.ReplayAll() 265 self.mox.ReplayAll()
291 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 266 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
292 relpath=self.relpath) 267 relpath=self.relpath)
293 scm.update(options, (), files_list) 268 scm.update(options, (), files_list)
294 self.checkstdout('')
295 269
296 def testUpdateUpdate(self): 270 def testUpdateUpdate(self):
297 options = self.Options(verbose=True) 271 options = self.Options(verbose=True)
298 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 272 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
299 options.force = True 273 options.force = True
300 options.nohooks = False 274 options.nohooks = False
301 file_info = { 275 file_info = {
302 'Repository Root': 'blah', 276 'Repository Root': 'blah',
303 'URL': self.url, 277 'URL': self.url,
304 'UUID': 'ABC', 278 'UUID': 'ABC',
(...skipping 21 matching lines...) Expand all
326 files_list = [] 300 files_list = []
327 gclient_scm.scm.SVN.RunAndGetFileList( 301 gclient_scm.scm.SVN.RunAndGetFileList(
328 options.verbose, 302 options.verbose,
329 ['update', base_path] + additional_args, 303 ['update', base_path] + additional_args,
330 cwd=self.root_dir, file_list=files_list, stdout=options.stdout) 304 cwd=self.root_dir, file_list=files_list, stdout=options.stdout)
331 305
332 self.mox.ReplayAll() 306 self.mox.ReplayAll()
333 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 307 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
334 relpath=self.relpath) 308 relpath=self.relpath)
335 scm.update(options, (), files_list) 309 scm.update(options, (), files_list)
336 self.checkstdout('')
337 310
338 def testUpdateSingleCheckout(self): 311 def testUpdateSingleCheckout(self):
339 options = self.Options(verbose=True) 312 options = self.Options(verbose=True)
340 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 313 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
341 file_info = { 314 file_info = {
342 'URL': self.url, 315 'URL': self.url,
343 'Revision': 42, 316 'Revision': 42,
344 } 317 }
345 318
346 # Checks to make sure that we support svn co --depth. 319 # Checks to make sure that we support svn co --depth.
(...skipping 17 matching lines...) Expand all
364 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], 337 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'],
365 cwd=base_path, file_list=files_list, stdout=options.stdout) 338 cwd=base_path, file_list=files_list, stdout=options.stdout)
366 339
367 # Now we fall back on scm.update(). 340 # Now we fall back on scm.update().
368 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 341 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
369 ).AndReturn(False) 342 ).AndReturn(False)
370 gclient_scm.os.path.exists(base_path).AndReturn(True) 343 gclient_scm.os.path.exists(base_path).AndReturn(True)
371 gclient_scm.scm.SVN.CaptureInfo( 344 gclient_scm.scm.SVN.CaptureInfo(
372 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) 345 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info)
373 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) 346 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info)
374 options.stdout.write("\n_____ %s at 42" % self.relpath)
375 options.stdout.write('\n')
376 347
377 self.mox.ReplayAll() 348 self.mox.ReplayAll()
378 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 349 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
379 relpath=self.relpath) 350 relpath=self.relpath)
380 scm.updatesingle(options, ['DEPS'], files_list) 351 scm.updatesingle(options, ['DEPS'], files_list)
381 self.checkstdout( 352 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
382 2 * ('\n_____ %s at 42\n' % self.relpath))
383 353
384 def testUpdateSingleCheckoutSVN14(self): 354 def testUpdateSingleCheckoutSVN14(self):
385 options = self.Options(verbose=True) 355 options = self.Options(verbose=True)
386 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 356 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
387 file_info = { 357 file_info = {
388 'URL': self.url, 358 'URL': self.url,
389 'Revision': 42, 359 'Revision': 42,
390 } 360 }
391 361
392 # Checks to make sure that we support svn co --depth. 362 # Checks to make sure that we support svn co --depth.
393 gclient_scm.scm.SVN.current_version = None 363 gclient_scm.scm.SVN.current_version = None
394 gclient_scm.scm.SVN.Capture(['--version'] 364 gclient_scm.scm.SVN.Capture(['--version']
395 ).AndReturn('svn, version 1.4.4 (r25188)') 365 ).AndReturn('svn, version 1.4.4 (r25188)')
396 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path) 366 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path)
397 ).AndReturn(True) 367 ).AndReturn(True)
398 368
399 # When checking out a single file with svn 1.4, we use svn export 369 # When checking out a single file with svn 1.4, we use svn export
400 files_list = self.mox.CreateMockAnything() 370 files_list = self.mox.CreateMockAnything()
401 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( 371 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader(
402 ['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'), 372 ['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'),
403 gclient_scm.os.path.join(base_path, 'DEPS')], 373 gclient_scm.os.path.join(base_path, 'DEPS')],
404 always=True, cwd=self.root_dir, stdout=options.stdout) 374 always=True, cwd=self.root_dir, stdout=options.stdout)
405 375
406 self.mox.ReplayAll() 376 self.mox.ReplayAll()
407 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 377 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
408 relpath=self.relpath) 378 relpath=self.relpath)
409 scm.updatesingle(options, ['DEPS'], files_list) 379 scm.updatesingle(options, ['DEPS'], files_list)
410 self.checkstdout('')
411 380
412 def testUpdateSingleCheckoutSVNUpgrade(self): 381 def testUpdateSingleCheckoutSVNUpgrade(self):
413 options = self.Options(verbose=True) 382 options = self.Options(verbose=True)
414 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 383 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
415 file_info = { 384 file_info = {
416 'URL': self.url, 385 'URL': self.url,
417 'Revision': 42, 386 'Revision': 42,
418 } 387 }
419 388
420 # Checks to make sure that we support svn co --depth. 389 # Checks to make sure that we support svn co --depth.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 465
497 self.mox.ReplayAll() 466 self.mox.ReplayAll()
498 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 467 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
499 relpath=self.relpath) 468 relpath=self.relpath)
500 file_list = [] 469 file_list = []
501 scm.update(options, self.args, file_list) 470 scm.update(options, self.args, file_list)
502 self.checkstdout( 471 self.checkstdout(
503 ('________ found .git directory; skipping %s\n' % self.relpath)) 472 ('________ found .git directory; skipping %s\n' % self.relpath))
504 473
505 474
506 class GitWrapperTestCase(GCBaseTestCase, TestCaseUtils, unittest.TestCase): 475 class GitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils,
476 unittest.TestCase):
507 """This class doesn't use pymox.""" 477 """This class doesn't use pymox."""
508 class OptionsObject(object): 478 class OptionsObject(object):
509 def __init__(self, test_case, verbose=False, revision=None): 479 def __init__(self, test_case, verbose=False, revision=None):
510 self.verbose = verbose 480 self.verbose = verbose
511 self.revision = revision 481 self.revision = revision
512 self.manually_grab_svn_rev = True 482 self.manually_grab_svn_rev = True
513 self.deps_os = None 483 self.deps_os = None
514 self.force = False 484 self.force = False
515 self.reset = False 485 self.reset = False
516 self.nohooks = False 486 self.nohooks = False
517 self.stdout = test_case.stdout 487 self.stdout = gclient_scm.sys.stdout
518 488
519 sample_git_import = """blob 489 sample_git_import = """blob
520 mark :1 490 mark :1
521 data 6 491 data 6
522 Hello 492 Hello
523 493
524 blob 494 blob
525 mark :2 495 mark :2
526 data 4 496 data 4
527 Bye 497 Bye
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 stderr=STDOUT, cwd=path).communicate() 550 stderr=STDOUT, cwd=path).communicate()
581 Popen(['git', 'checkout', '-b', 'new', 'origin/master', '-q'], stdout=PIPE, 551 Popen(['git', 'checkout', '-b', 'new', 'origin/master', '-q'], stdout=PIPE,
582 stderr=STDOUT, cwd=path).communicate() 552 stderr=STDOUT, cwd=path).communicate()
583 Popen(['git', 'push', 'origin', 'origin/origin:origin/master', '-q'], 553 Popen(['git', 'push', 'origin', 'origin/origin:origin/master', '-q'],
584 stdout=PIPE, stderr=STDOUT, cwd=path).communicate() 554 stdout=PIPE, stderr=STDOUT, cwd=path).communicate()
585 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE, 555 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE,
586 stderr=STDOUT, cwd=path).communicate() 556 stderr=STDOUT, cwd=path).communicate()
587 return True 557 return True
588 558
589 def setUp(self): 559 def setUp(self):
590 GCBaseTestCase.setUp(self)
591 TestCaseUtils.setUp(self) 560 TestCaseUtils.setUp(self)
592 unittest.TestCase.setUp(self) 561 unittest.TestCase.setUp(self)
593 self.url = 'git://foo' 562 self.url = 'git://foo'
594 self.root_dir = tempfile.mkdtemp() 563 self.root_dir = tempfile.mkdtemp()
595 self.relpath = '.' 564 self.relpath = '.'
596 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 565 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
597 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 566 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
567 StdoutCheck.setUp(self)
598 568
599 def tearDown(self): 569 def tearDown(self):
600 if not self.enabled: 570 StdoutCheck.tearDown(self)
601 self.checkstdout('')
602 GCBaseTestCase.tearDown(self)
603 TestCaseUtils.tearDown(self) 571 TestCaseUtils.tearDown(self)
604 unittest.TestCase.tearDown(self) 572 unittest.TestCase.tearDown(self)
605 rmtree(self.root_dir) 573 rmtree(self.root_dir)
606 574
607 def testDir(self): 575 def testDir(self):
608 members = [ 576 members = [
609 'FullUrlForRelativeUrl', 'RunCommand', 577 'FullUrlForRelativeUrl', 'RunCommand',
610 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 578 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
611 'revinfo', 'runhooks', 'status', 'update', 'url', 579 'revinfo', 'runhooks', 'status', 'update', 'url',
612 ] 580 ]
613 581
614 # If you add a member, be sure to add the relevant test! 582 # If you add a member, be sure to add the relevant test!
615 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) 583 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
616 if self.enabled:
617 self.checkstdout('')
618 584
619 def testRevertMissing(self): 585 def testRevertMissing(self):
620 if not self.enabled: 586 if not self.enabled:
621 return 587 return
622 options = self.Options() 588 options = self.Options()
623 file_path = gclient_scm.os.path.join(self.base_path, 'a') 589 file_path = gclient_scm.os.path.join(self.base_path, 'a')
624 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 590 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
625 relpath=self.relpath) 591 relpath=self.relpath)
626 file_list = [] 592 file_list = []
627 scm.update(options, None, file_list) 593 scm.update(options, None, file_list)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 exception = ('\n____ . at refs/heads/master\n' 798 exception = ('\n____ . at refs/heads/master\n'
833 '\tYou have unstaged changes.\n' 799 '\tYou have unstaged changes.\n'
834 '\tPlease commit, stash, or reset.\n') 800 '\tPlease commit, stash, or reset.\n')
835 self.assertRaisesError(exception, scm.update, options, (), []) 801 self.assertRaisesError(exception, scm.update, options, (), [])
836 # The hash always changes. Use a cheap trick. 802 # The hash always changes. Use a cheap trick.
837 start = ('\n________ running \'git commit -am test\' in \'%s\'\n' 803 start = ('\n________ running \'git commit -am test\' in \'%s\'\n'
838 '[new ') % gclient_scm.os.path.join(self.root_dir, '.') 804 '[new ') % gclient_scm.os.path.join(self.root_dir, '.')
839 end = ('] test\n 1 files changed, 1 insertions(+), ' 805 end = ('] test\n 1 files changed, 1 insertions(+), '
840 '1 deletions(-)\n\n_____ . at refs/heads/master\n' 806 '1 deletions(-)\n\n_____ . at refs/heads/master\n'
841 'Attempting rebase onto refs/remotes/origin/master...\n') 807 'Attempting rebase onto refs/remotes/origin/master...\n')
842 self.assertTrue(self.stdout.getvalue().startswith(start)) 808 self.assertTrue(gclient_scm.sys.stdout.getvalue().startswith(start))
843 self.assertTrue(self.stdout.getvalue().endswith(end)) 809 self.assertTrue(gclient_scm.sys.stdout.getvalue().endswith(end))
844 self.assertEquals(len(self.stdout.getvalue()), len(start) + len(end) + 7) 810 self.assertEquals(len(gclient_scm.sys.stdout.getvalue()),
845 self.stdout.close() 811 len(start) + len(end) + 7)
812 gclient_scm.sys.stdout.close()
846 813
847 def testUpdateNotGit(self): 814 def testUpdateNotGit(self):
848 if not self.enabled: 815 if not self.enabled:
849 return 816 return
850 options = self.Options() 817 options = self.Options()
851 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 818 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
852 relpath=self.relpath) 819 relpath=self.relpath)
853 git_path = gclient_scm.os.path.join(self.base_path, '.git') 820 git_path = gclient_scm.os.path.join(self.base_path, '.git')
854 rename(git_path, git_path + 'foo') 821 rename(git_path, git_path + 'foo')
855 exception = ('\n____ . at refs/heads/master\n' 822 exception = ('\n____ . at refs/heads/master\n'
856 '\tPath is not a git repo. No .git dir.\n' 823 '\tPath is not a git repo. No .git dir.\n'
857 '\tTo resolve:\n' 824 '\tTo resolve:\n'
858 '\t\trm -rf .\n' 825 '\t\trm -rf .\n'
859 '\tAnd run gclient sync again\n') 826 '\tAnd run gclient sync again\n')
860 self.assertRaisesError(exception, scm.update, options, (), []) 827 self.assertRaisesError(exception, scm.update, options, (), [])
861 self.checkstdout('')
862 828
863 def testRevinfo(self): 829 def testRevinfo(self):
864 if not self.enabled: 830 if not self.enabled:
865 return 831 return
866 options = self.Options() 832 options = self.Options()
867 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 833 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
868 relpath=self.relpath) 834 relpath=self.relpath)
869 rev_info = scm.revinfo(options, (), None) 835 rev_info = scm.revinfo(options, (), None)
870 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 836 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
871 self.checkstdout('')
872 837
873 838
874 if __name__ == '__main__': 839 if __name__ == '__main__':
875 unittest.main() 840 unittest.main()
876 841
877 # vim: ts=2:sw=2:tw=80:et: 842 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gcl_unittest.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698