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

Side by Side Diff: tests/gclient_test.py

Issue 118014: Convert gclient_test.py to mox.MoxTestBase and saves 40+ lines (Closed)
Patch Set: Created 11 years, 6 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 | « no previous file | no next file » | 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 # 2 #
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. 3 # Copyright 2008-2009 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with 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 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return random.choice((os.sep, '')) + _DirElts(max_elt_count, max_elt_length) 57 return random.choice((os.sep, '')) + _DirElts(max_elt_count, max_elt_length)
58 58
59 def Url(max_elt_count=4, max_elt_length=8): 59 def Url(max_elt_count=4, max_elt_length=8):
60 return ('svn://random_host:port/a' + 60 return ('svn://random_host:port/a' +
61 _DirElts(max_elt_count, max_elt_length).replace(os.sep, '/')) 61 _DirElts(max_elt_count, max_elt_length).replace(os.sep, '/'))
62 62
63 def RootDir(max_elt_count=4, max_elt_length=8): 63 def RootDir(max_elt_count=4, max_elt_length=8):
64 return os.sep + _DirElts(max_elt_count, max_elt_length) 64 return os.sep + _DirElts(max_elt_count, max_elt_length)
65 65
66 66
67 class BaseTestCase(unittest.TestCase): 67 class BaseTestCase(mox.MoxTestBase):
68 # Like unittest's assertRaises, but checks for Gclient.Error. 68 # Like unittest's assertRaises, but checks for Gclient.Error.
69 def assertRaisesError(self, msg, fn, *args, **kwargs): 69 def assertRaisesError(self, msg, fn, *args, **kwargs):
70 try: 70 try:
71 fn(*args, **kwargs) 71 fn(*args, **kwargs)
72 except gclient.Error, e: 72 except gclient.Error, e:
73 self.assertEquals(e.args[0], msg) 73 self.assertEquals(e.args[0], msg)
74 else: 74 else:
75 self.fail('%s not raised' % msg) 75 self.fail('%s not raised' % msg)
76 76
77 def compareMembers(self, object, members): 77 def compareMembers(self, object, members):
78 """If you add a member, be sure to add the relevant test!""" 78 """If you add a member, be sure to add the relevant test!"""
79 # Skip over members starting with '_' since they are usually not meant to 79 # Skip over members starting with '_' since they are usually not meant to
80 # be for public use. 80 # be for public use.
81 actual_members = [x for x in sorted(dir(object)) 81 actual_members = [x for x in sorted(dir(object))
82 if not x.startswith('_')] 82 if not x.startswith('_')]
83 expected_members = sorted(members) 83 expected_members = sorted(members)
84 if actual_members != expected_members: 84 if actual_members != expected_members:
85 diff = ([i for i in actual_members if i not in expected_members] + 85 diff = ([i for i in actual_members if i not in expected_members] +
86 [i for i in expected_members if i not in actual_members]) 86 [i for i in expected_members if i not in actual_members])
87 print diff 87 print diff
88 self.assertEqual(actual_members, expected_members) 88 self.assertEqual(actual_members, expected_members)
89 89
90 90
91 class GClientBaseTestCase(BaseTestCase): 91 class GClientBaseTestCase(BaseTestCase):
92 def Options(self, *args, **kwargs): 92 def Options(self, *args, **kwargs):
93 return self.OptionsObject(self, *args, **kwargs) 93 return self.OptionsObject(self, *args, **kwargs)
94 94
95 def setUp(self): 95 def setUp(self):
96 self.mox = mox.Mox() 96 BaseTestCase.setUp(self)
97 # Mock them to be sure nothing bad happens. 97 # Mock them to be sure nothing bad happens.
98 self._CaptureSVN = gclient.CaptureSVN 98 self._CaptureSVN = gclient.CaptureSVN
99 gclient.CaptureSVN = self.mox.CreateMockAnything() 99 gclient.CaptureSVN = self.mox.CreateMockAnything()
100 self._CaptureSVNInfo = gclient.CaptureSVNInfo 100 self._CaptureSVNInfo = gclient.CaptureSVNInfo
101 gclient.CaptureSVNInfo = self.mox.CreateMockAnything() 101 gclient.CaptureSVNInfo = self.mox.CreateMockAnything()
102 self._CaptureSVNStatus = gclient.CaptureSVNStatus 102 self._CaptureSVNStatus = gclient.CaptureSVNStatus
103 gclient.CaptureSVNStatus = self.mox.CreateMockAnything() 103 gclient.CaptureSVNStatus = self.mox.CreateMockAnything()
104 self._FileRead = gclient.FileRead 104 self._FileRead = gclient.FileRead
105 gclient.FileRead = self.mox.CreateMockAnything() 105 gclient.FileRead = self.mox.CreateMockAnything()
106 self._FileWrite = gclient.FileWrite 106 self._FileWrite = gclient.FileWrite
(...skipping 22 matching lines...) Expand all
129 gclient.FileRead = self._FileRead 129 gclient.FileRead = self._FileRead
130 gclient.FileWrite = self._FileWrite 130 gclient.FileWrite = self._FileWrite
131 gclient.RemoveDirectory = self._RemoveDirectory 131 gclient.RemoveDirectory = self._RemoveDirectory
132 gclient.RunSVN = self._RunSVN 132 gclient.RunSVN = self._RunSVN
133 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList 133 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList
134 gclient.sys.stdout = self._sys_stdout 134 gclient.sys.stdout = self._sys_stdout
135 gclient.subprocess = self._subprocess 135 gclient.subprocess = self._subprocess
136 gclient.os.path.exists = self._os_path_exists 136 gclient.os.path.exists = self._os_path_exists
137 gclient.GClient = self._gclient_gclient 137 gclient.GClient = self._gclient_gclient
138 gclient.SCMWrapper = self._scm_wrapper 138 gclient.SCMWrapper = self._scm_wrapper
139 BaseTestCase.tearDown(self)
139 140
140 141
141 class GclientTestCase(GClientBaseTestCase): 142 class GclientTestCase(GClientBaseTestCase):
142 class OptionsObject(object): 143 class OptionsObject(object):
143 def __init__(self, test_case, verbose=False, spec=None, 144 def __init__(self, test_case, verbose=False, spec=None,
144 config_filename='a_file_name', 145 config_filename='a_file_name',
145 entries_filename='a_entry_file_name', 146 entries_filename='a_entry_file_name',
146 deps_file='a_deps_file_name', force=False): 147 deps_file='a_deps_file_name', force=False):
147 self.verbose = verbose 148 self.verbose = verbose
148 self.spec = spec 149 self.spec = spec
(...skipping 20 matching lines...) Expand all
169 170
170 class GClientCommandsTestCase(GClientBaseTestCase): 171 class GClientCommandsTestCase(GClientBaseTestCase):
171 def testCommands(self): 172 def testCommands(self):
172 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, 173 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff,
173 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate, 174 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate,
174 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo] 175 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo]
175 for (k,v) in gclient.gclient_command_map.iteritems(): 176 for (k,v) in gclient.gclient_command_map.iteritems():
176 # If it fails, you need to add a test case for the new command. 177 # If it fails, you need to add a test case for the new command.
177 self.assert_(v in known_commands) 178 self.assert_(v in known_commands)
178 self.mox.ReplayAll() 179 self.mox.ReplayAll()
179 self.mox.VerifyAll()
180 180
181 class TestDoConfig(GclientTestCase): 181 class TestDoConfig(GclientTestCase):
182 def setUp(self):
183 GclientTestCase.setUp(self)
184
185 def testMissingArgument(self): 182 def testMissingArgument(self):
186 exception_msg = "required argument missing; see 'gclient help config'" 183 exception_msg = "required argument missing; see 'gclient help config'"
187 184
188 self.mox.ReplayAll() 185 self.mox.ReplayAll()
189 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ()) 186 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ())
190 self.mox.VerifyAll()
191 187
192 def testExistingClientFile(self): 188 def testExistingClientFile(self):
193 options = self.Options() 189 options = self.Options()
194 exception_msg = ('%s file already exists in the current directory' % 190 exception_msg = ('%s file already exists in the current directory' %
195 options.config_filename) 191 options.config_filename)
196 gclient.os.path.exists(options.config_filename).AndReturn(True) 192 gclient.os.path.exists(options.config_filename).AndReturn(True)
197 193
198 self.mox.ReplayAll() 194 self.mox.ReplayAll()
199 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,)) 195 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,))
200 self.mox.VerifyAll()
201 196
202 def testFromText(self): 197 def testFromText(self):
203 options = self.Options(spec='config_source_content') 198 options = self.Options(spec='config_source_content')
204 gclient.os.path.exists(options.config_filename).AndReturn(False) 199 gclient.os.path.exists(options.config_filename).AndReturn(False)
205 gclient.GClient('.', options).AndReturn(gclient.GClient) 200 gclient.GClient('.', options).AndReturn(gclient.GClient)
206 gclient.GClient.SetConfig(options.spec) 201 gclient.GClient.SetConfig(options.spec)
207 gclient.GClient.SaveConfig() 202 gclient.GClient.SaveConfig()
208 203
209 self.mox.ReplayAll() 204 self.mox.ReplayAll()
210 gclient.DoConfig(options, (1,),) 205 gclient.DoConfig(options, (1,),)
211 self.mox.VerifyAll()
212 206
213 def testCreateClientFile(self): 207 def testCreateClientFile(self):
214 options = self.Options() 208 options = self.Options()
215 gclient.os.path.exists(options.config_filename).AndReturn(False) 209 gclient.os.path.exists(options.config_filename).AndReturn(False)
216 gclient.GClient('.', options).AndReturn(gclient.GClient) 210 gclient.GClient('.', options).AndReturn(gclient.GClient)
217 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name', 211 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
218 'other') 212 'other')
219 gclient.GClient.SaveConfig() 213 gclient.GClient.SaveConfig()
220 214
221 self.mox.ReplayAll() 215 self.mox.ReplayAll()
222 gclient.DoConfig(options, 216 gclient.DoConfig(options,
223 ('http://svn/url/the_name', 'other', 'args', 'ignored')) 217 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
224 self.mox.VerifyAll()
225 218
226 219
227 class TestDoHelp(GclientTestCase): 220 class TestDoHelp(GclientTestCase):
228 def testGetUsage(self): 221 def testGetUsage(self):
229 print(gclient.COMMAND_USAGE_TEXT['config']) 222 print(gclient.COMMAND_USAGE_TEXT['config'])
230 self.mox.ReplayAll() 223 self.mox.ReplayAll()
231 options = self.Options() 224 options = self.Options()
232 gclient.DoHelp(options, ('config',)) 225 gclient.DoHelp(options, ('config',))
233 self.mox.VerifyAll()
234 226
235 def testTooManyArgs(self): 227 def testTooManyArgs(self):
236 self.mox.ReplayAll() 228 self.mox.ReplayAll()
237 options = self.Options() 229 options = self.Options()
238 self.assertRaisesError("unknown subcommand 'config'; see 'gclient help'", 230 self.assertRaisesError("unknown subcommand 'config'; see 'gclient help'",
239 gclient.DoHelp, options, ('config', 231 gclient.DoHelp, options, ('config',
240 'another argument')) 232 'another argument'))
241 self.mox.VerifyAll()
242 233
243 def testUnknownSubcommand(self): 234 def testUnknownSubcommand(self):
244 self.mox.ReplayAll() 235 self.mox.ReplayAll()
245 options = self.Options() 236 options = self.Options()
246 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'", 237 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'",
247 gclient.DoHelp, options, ('xyzzy',)) 238 gclient.DoHelp, options, ('xyzzy',))
248 self.mox.VerifyAll()
249 239
250 240
251 class GenericCommandTestCase(GclientTestCase): 241 class GenericCommandTestCase(GclientTestCase):
252 def ReturnValue(self, command, function, return_value): 242 def ReturnValue(self, command, function, return_value):
253 options = self.Options() 243 options = self.Options()
254 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 244 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
255 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 245 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
256 246
257 self.mox.ReplayAll() 247 self.mox.ReplayAll()
258 result = function(options, self.args) 248 result = function(options, self.args)
259 self.assertEquals(result, return_value) 249 self.assertEquals(result, return_value)
260 self.mox.VerifyAll()
261 250
262 def BadClient(self, function): 251 def BadClient(self, function):
263 options = self.Options() 252 options = self.Options()
264 gclient.GClient.LoadCurrentConfig(options).AndReturn(None) 253 gclient.GClient.LoadCurrentConfig(options).AndReturn(None)
265 254
266 self.mox.ReplayAll() 255 self.mox.ReplayAll()
267 self.assertRaisesError( 256 self.assertRaisesError(
268 "client not configured; see 'gclient config'", 257 "client not configured; see 'gclient config'",
269 function, options, self.args) 258 function, options, self.args)
270 self.mox.VerifyAll()
271 259
272 def Verbose(self, command, function): 260 def Verbose(self, command, function):
273 options = self.Options(verbose=True) 261 options = self.Options(verbose=True)
274 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 262 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
275 text = "# Dummy content\nclient = 'my client'" 263 text = "# Dummy content\nclient = 'my client'"
276 gclient.GClient.ConfigContent().AndReturn(text) 264 gclient.GClient.ConfigContent().AndReturn(text)
277 print(text) 265 print(text)
278 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 266 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
279 267
280 self.mox.ReplayAll() 268 self.mox.ReplayAll()
281 result = function(options, self.args) 269 result = function(options, self.args)
282 self.assertEquals(result, 0) 270 self.assertEquals(result, 0)
283 self.mox.VerifyAll()
284 271
285 class TestDoCleanup(GenericCommandTestCase): 272 class TestDoCleanup(GenericCommandTestCase):
286 def testGoodClient(self): 273 def testGoodClient(self):
287 self.ReturnValue('cleanup', gclient.DoCleanup, 0) 274 self.ReturnValue('cleanup', gclient.DoCleanup, 0)
288 def testError(self): 275 def testError(self):
289 self.ReturnValue('cleanup', gclient.DoCleanup, 42) 276 self.ReturnValue('cleanup', gclient.DoCleanup, 42)
290 def testBadClient(self): 277 def testBadClient(self):
291 self.BadClient(gclient.DoCleanup) 278 self.BadClient(gclient.DoCleanup)
292 279
293 class TestDoStatus(GenericCommandTestCase): 280 class TestDoStatus(GenericCommandTestCase):
(...skipping 23 matching lines...) Expand all
317 304
318 def ReturnValue(self, command, function, return_value): 305 def ReturnValue(self, command, function, return_value):
319 options = self.Options() 306 options = self.Options()
320 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 307 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
321 gclient.GClient.GetVar("solutions") 308 gclient.GClient.GetVar("solutions")
322 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 309 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
323 310
324 self.mox.ReplayAll() 311 self.mox.ReplayAll()
325 result = function(options, self.args) 312 result = function(options, self.args)
326 self.assertEquals(result, return_value) 313 self.assertEquals(result, return_value)
327 self.mox.VerifyAll()
328 314
329 def Verbose(self, command, function): 315 def Verbose(self, command, function):
330 options = self.Options(verbose=True) 316 options = self.Options(verbose=True)
331 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 317 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
332 gclient.GClient.GetVar("solutions") 318 gclient.GClient.GetVar("solutions")
333 text = "# Dummy content\nclient = 'my client'" 319 text = "# Dummy content\nclient = 'my client'"
334 gclient.GClient.ConfigContent().AndReturn(text) 320 gclient.GClient.ConfigContent().AndReturn(text)
335 print(text) 321 print(text)
336 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 322 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
337 323
338 self.mox.ReplayAll() 324 self.mox.ReplayAll()
339 result = function(options, self.args) 325 result = function(options, self.args)
340 self.assertEquals(result, 0) 326 self.assertEquals(result, 0)
341 self.mox.VerifyAll()
342 327
343 def Options(self, verbose=False, *args, **kwargs): 328 def Options(self, verbose=False, *args, **kwargs):
344 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 329 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
345 330
346 def testBasic(self): 331 def testBasic(self):
347 self.ReturnValue('update', gclient.DoUpdate, 0) 332 self.ReturnValue('update', gclient.DoUpdate, 0)
348 def testError(self): 333 def testError(self):
349 self.ReturnValue('update', gclient.DoUpdate, 42) 334 self.ReturnValue('update', gclient.DoUpdate, 42)
350 def testBadClient(self): 335 def testBadClient(self):
351 self.BadClient(gclient.DoUpdate) 336 self.BadClient(gclient.DoUpdate)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 client.SetDefaultConfig(solution_name, solution_url, safesync_url) 395 client.SetDefaultConfig(solution_name, solution_url, safesync_url)
411 self.assertEqual(client.ConfigContent(), default_text) 396 self.assertEqual(client.ConfigContent(), default_text)
412 solutions = [{ 397 solutions = [{
413 'name': solution_name, 398 'name': solution_name,
414 'url': solution_url, 399 'url': solution_url,
415 'custom_deps': {}, 400 'custom_deps': {},
416 'safesync_url': safesync_url 401 'safesync_url': safesync_url
417 }] 402 }]
418 self.assertEqual(client.GetVar('solutions'), solutions) 403 self.assertEqual(client.GetVar('solutions'), solutions)
419 self.assertEqual(client.GetVar('foo'), None) 404 self.assertEqual(client.GetVar('foo'), None)
420 self.mox.VerifyAll()
421 405
422 def testLoadCurrentConfig(self): 406 def testLoadCurrentConfig(self):
423 options = self.Options() 407 options = self.Options()
424 path = os.path.realpath(self.root_dir) 408 path = os.path.realpath(self.root_dir)
425 gclient.os.path.exists(os.path.join(path, options.config_filename) 409 gclient.os.path.exists(os.path.join(path, options.config_filename)
426 ).AndReturn(True) 410 ).AndReturn(True)
427 gclient.GClient(path, options).AndReturn(gclient.GClient) 411 gclient.GClient(path, options).AndReturn(gclient.GClient)
428 gclient.GClient._LoadConfig() 412 gclient.GClient._LoadConfig()
429 413
430 self.mox.ReplayAll() 414 self.mox.ReplayAll()
431 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir) 415 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir)
432 self.mox.VerifyAll()
433 416
434 def testRunOnDepsNoDeps(self): 417 def testRunOnDepsNoDeps(self):
435 solution_name = 'testRunOnDepsNoDeps_solution_name' 418 solution_name = 'testRunOnDepsNoDeps_solution_name'
436 gclient_config = ( 419 gclient_config = (
437 "solutions = [ {\n" 420 "solutions = [ {\n"
438 " 'name': '%s',\n" 421 " 'name': '%s',\n"
439 " 'url': '%s',\n" 422 " 'url': '%s',\n"
440 " 'custom_deps': {},\n" 423 " 'custom_deps': {},\n"
441 "} ]\n" 424 "} ]\n"
442 ) % (solution_name, self.url) 425 ) % (solution_name, self.url)
(...skipping 25 matching lines...) Expand all
468 451
469 # After everything is done, an attempt is made to write an entries 452 # After everything is done, an attempt is made to write an entries
470 # file. 453 # file.
471 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 454 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
472 entries_content) 455 entries_content)
473 456
474 self.mox.ReplayAll() 457 self.mox.ReplayAll()
475 client = self._gclient_gclient(self.root_dir, options) 458 client = self._gclient_gclient(self.root_dir, options)
476 client.SetConfig(gclient_config) 459 client.SetConfig(gclient_config)
477 client.RunOnDeps('update', self.args) 460 client.RunOnDeps('update', self.args)
478 self.mox.VerifyAll()
479 461
480 def testRunOnDepsRelativePaths(self): 462 def testRunOnDepsRelativePaths(self):
481 solution_name = 'testRunOnDepsRelativePaths_solution_name' 463 solution_name = 'testRunOnDepsRelativePaths_solution_name'
482 gclient_config = ( 464 gclient_config = (
483 "solutions = [ {\n" 465 "solutions = [ {\n"
484 " 'name': '%s',\n" 466 " 'name': '%s',\n"
485 " 'url': '%s',\n" 467 " 'url': '%s',\n"
486 " 'custom_deps': {},\n" 468 " 'custom_deps': {},\n"
487 "} ]\n" 469 "} ]\n"
488 ) % (solution_name, self.url) 470 ) % (solution_name, self.url)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 517
536 # After everything is done, an attempt is made to write an entries 518 # After everything is done, an attempt is made to write an entries
537 # file. 519 # file.
538 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 520 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
539 entries_content) 521 entries_content)
540 522
541 self.mox.ReplayAll() 523 self.mox.ReplayAll()
542 client = self._gclient_gclient(self.root_dir, options) 524 client = self._gclient_gclient(self.root_dir, options)
543 client.SetConfig(gclient_config) 525 client.SetConfig(gclient_config)
544 client.RunOnDeps('update', self.args) 526 client.RunOnDeps('update', self.args)
545 self.mox.VerifyAll()
546 527
547 def testRunOnDepsCustomDeps(self): 528 def testRunOnDepsCustomDeps(self):
548 solution_name = 'testRunOnDepsCustomDeps_solution_name' 529 solution_name = 'testRunOnDepsCustomDeps_solution_name'
549 gclient_config = ( 530 gclient_config = (
550 "solutions = [ {\n" 531 "solutions = [ {\n"
551 " 'name': '%s',\n" 532 " 'name': '%s',\n"
552 " 'url': '%s',\n" 533 " 'url': '%s',\n"
553 " 'custom_deps': {\n" 534 " 'custom_deps': {\n"
554 " 'src/b': None,\n" 535 " 'src/b': None,\n"
555 " 'src/n': 'svn://custom.n/trunk',\n" 536 " 'src/n': 'svn://custom.n/trunk',\n"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 598
618 # After everything is done, an attempt is made to write an entries 599 # After everything is done, an attempt is made to write an entries
619 # file. 600 # file.
620 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 601 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
621 entries_content) 602 entries_content)
622 603
623 self.mox.ReplayAll() 604 self.mox.ReplayAll()
624 client = self._gclient_gclient(self.root_dir, options) 605 client = self._gclient_gclient(self.root_dir, options)
625 client.SetConfig(gclient_config) 606 client.SetConfig(gclient_config)
626 client.RunOnDeps('update', self.args) 607 client.RunOnDeps('update', self.args)
627 self.mox.VerifyAll()
628 608
629 # Regression test for Issue #11. 609 # Regression test for Issue #11.
630 # http://code.google.com/p/gclient/issues/detail?id=11 610 # http://code.google.com/p/gclient/issues/detail?id=11
631 def testRunOnDepsSharedDependency(self): 611 def testRunOnDepsSharedDependency(self):
632 name_a = 'testRunOnDepsSharedDependency_a' 612 name_a = 'testRunOnDepsSharedDependency_a'
633 name_b = 'testRunOnDepsSharedDependency_b' 613 name_b = 'testRunOnDepsSharedDependency_b'
634 614
635 url_a = self.url + '/a' 615 url_a = self.url + '/a'
636 url_b = self.url + '/b' 616 url_b = self.url + '/b'
637 617
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 scm_wrapper_dep.RunCommand('update', options, self.args, []) 681 scm_wrapper_dep.RunCommand('update', options, self.args, [])
702 682
703 # After everything is done, an attempt is made to write an entries file. 683 # After everything is done, an attempt is made to write an entries file.
704 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 684 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
705 entries_content) 685 entries_content)
706 686
707 self.mox.ReplayAll() 687 self.mox.ReplayAll()
708 client = self._gclient_gclient(self.root_dir, options) 688 client = self._gclient_gclient(self.root_dir, options)
709 client.SetConfig(gclient_config) 689 client.SetConfig(gclient_config)
710 client.RunOnDeps('update', self.args) 690 client.RunOnDeps('update', self.args)
711 self.mox.VerifyAll()
712 691
713 def testRunOnDepsSuccess(self): 692 def testRunOnDepsSuccess(self):
714 # Fake .gclient file. 693 # Fake .gclient file.
715 name = 'testRunOnDepsSuccess_solution_name' 694 name = 'testRunOnDepsSuccess_solution_name'
716 gclient_config = """solutions = [ { 695 gclient_config = """solutions = [ {
717 'name': '%s', 696 'name': '%s',
718 'url': '%s', 697 'url': '%s',
719 'custom_deps': {}, 698 'custom_deps': {},
720 }, ]""" % (name, self.url) 699 }, ]""" % (name, self.url)
721 700
722 options = self.Options() 701 options = self.Options()
723 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') 702 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
724 ).AndReturn(False) 703 ).AndReturn(False)
725 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 704 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
726 ).AndReturn(False) 705 ).AndReturn(False)
727 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn( 706 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
728 gclient.SCMWrapper) 707 gclient.SCMWrapper)
729 gclient.SCMWrapper.RunCommand('update', options, self.args, []) 708 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
730 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 709 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
731 ).AndReturn("Boo = 'a'") 710 ).AndReturn("Boo = 'a'")
732 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 711 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
733 'entries = [\n "%s",\n]\n' % name) 712 'entries = [\n "%s",\n]\n' % name)
734 713
735 self.mox.ReplayAll() 714 self.mox.ReplayAll()
736 client = self._gclient_gclient(self.root_dir, options) 715 client = self._gclient_gclient(self.root_dir, options)
737 client.SetConfig(gclient_config) 716 client.SetConfig(gclient_config)
738 client.RunOnDeps('update', self.args) 717 client.RunOnDeps('update', self.args)
739 self.mox.VerifyAll()
740 718
741 def testRunOnDepsRevisions(self): 719 def testRunOnDepsRevisions(self):
742 def OptIsRev(options, rev): 720 def OptIsRev(options, rev):
743 if not options.revision == str(rev): 721 if not options.revision == str(rev):
744 print("options.revision = %s" % options.revision) 722 print("options.revision = %s" % options.revision)
745 return options.revision == str(rev) 723 return options.revision == str(rev)
746 def OptIsRevNone(options): 724 def OptIsRevNone(options):
747 if options.revision: 725 if options.revision:
748 print("options.revision = %s" % options.revision) 726 print("options.revision = %s" % options.revision)
749 return options.revision == None 727 return options.revision == None
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 self.root_dir, 830 self.root_dir,
853 'src/third_party/python_24').AndReturn( 831 'src/third_party/python_24').AndReturn(
854 scm_wrapper_python) 832 scm_wrapper_python)
855 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args, 833 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args,
856 []) 834 [])
857 835
858 self.mox.ReplayAll() 836 self.mox.ReplayAll()
859 client = self._gclient_gclient(self.root_dir, options) 837 client = self._gclient_gclient(self.root_dir, options)
860 client.SetConfig(gclient_config) 838 client.SetConfig(gclient_config)
861 client.RunOnDeps('update', self.args) 839 client.RunOnDeps('update', self.args)
862 self.mox.VerifyAll()
863 840
864 def testRunOnDepsConflictingRevisions(self): 841 def testRunOnDepsConflictingRevisions(self):
865 # Fake .gclient file. 842 # Fake .gclient file.
866 name = 'testRunOnDepsConflictingRevisions_solution_name' 843 name = 'testRunOnDepsConflictingRevisions_solution_name'
867 gclient_config = """solutions = [ { 844 gclient_config = """solutions = [ {
868 'name': '%s', 845 'name': '%s',
869 'url': '%s', 846 'url': '%s',
870 'custom_deps': {}, 847 'custom_deps': {},
871 'custom_vars': {}, 848 'custom_vars': {},
872 }, ]""" % (name, self.url) 849 }, ]""" % (name, self.url)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 ).AndReturn(webkit_path) 912 ).AndReturn(webkit_path)
936 913
937 gclient.SCMWrapper(webkit_path, self.root_dir, 914 gclient.SCMWrapper(webkit_path, self.root_dir,
938 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper) 915 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper)
939 gclient.SCMWrapper.RunCommand('update', options, self.args, []) 916 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
940 917
941 self.mox.ReplayAll() 918 self.mox.ReplayAll()
942 client = self._gclient_gclient(self.root_dir, options) 919 client = self._gclient_gclient(self.root_dir, options)
943 client.SetConfig(gclient_config) 920 client.SetConfig(gclient_config)
944 client.RunOnDeps('update', self.args) 921 client.RunOnDeps('update', self.args)
945 self.mox.VerifyAll()
946 922
947 def testRunOnDepsSuccessCustomVars(self): 923 def testRunOnDepsSuccessCustomVars(self):
948 # Fake .gclient file. 924 # Fake .gclient file.
949 name = 'testRunOnDepsSuccessCustomVars_solution_name' 925 name = 'testRunOnDepsSuccessCustomVars_solution_name'
950 gclient_config = """solutions = [ { 926 gclient_config = """solutions = [ {
951 'name': '%s', 927 'name': '%s',
952 'url': '%s', 928 'url': '%s',
953 'custom_deps': {}, 929 'custom_deps': {},
954 'custom_vars': {'webkit': '/trunk/bar_custom/'}, 930 'custom_vars': {'webkit': '/trunk/bar_custom/'},
955 }, ]""" % (name, self.url) 931 }, ]""" % (name, self.url)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 ).AndReturn(webkit_path) 968 ).AndReturn(webkit_path)
993 969
994 gclient.SCMWrapper(webkit_path, self.root_dir, 970 gclient.SCMWrapper(webkit_path, self.root_dir,
995 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper) 971 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper)
996 gclient.SCMWrapper.RunCommand('update', options, self.args, []) 972 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
997 973
998 self.mox.ReplayAll() 974 self.mox.ReplayAll()
999 client = self._gclient_gclient(self.root_dir, options) 975 client = self._gclient_gclient(self.root_dir, options)
1000 client.SetConfig(gclient_config) 976 client.SetConfig(gclient_config)
1001 client.RunOnDeps('update', self.args) 977 client.RunOnDeps('update', self.args)
1002 self.mox.VerifyAll()
1003 978
1004 def testRunOnDepsFailueVars(self): 979 def testRunOnDepsFailureVars(self):
1005 # Fake .gclient file. 980 # Fake .gclient file.
1006 name = 'testRunOnDepsFailureVars_solution_name' 981 name = 'testRunOnDepsFailureVars_solution_name'
1007 gclient_config = """solutions = [ { 982 gclient_config = """solutions = [ {
1008 'name': '%s', 983 'name': '%s',
1009 'url': '%s', 984 'url': '%s',
1010 'custom_deps': {}, 985 'custom_deps': {},
1011 'custom_vars': {}, 986 'custom_vars': {},
1012 }, ]""" % (name, self.url) 987 }, ]""" % (name, self.url)
1013 # Fake DEPS file. 988 # Fake DEPS file.
1014 deps_content = """deps = { 989 deps_content = """deps = {
1015 'foo/third_party/WebKit': Var('webkit') + 'WebKit', 990 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
1016 }""" 991 }"""
1017 992
1018 options = self.Options() 993 options = self.Options()
1019 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 994 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
1020 ).AndReturn(deps_content) 995 ).AndReturn(deps_content)
1021 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
1022 'dummy entries content')
1023
1024 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
1025 ).AndReturn(False)
1026 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn( 996 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
1027 gclient.SCMWrapper) 997 gclient.SCMWrapper)
1028 gclient.SCMWrapper.RunCommand('update', options, self.args, []) 998 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
1029 999
1030 self.mox.ReplayAll() 1000 self.mox.ReplayAll()
1031 client = self._gclient_gclient(self.root_dir, options) 1001 client = self._gclient_gclient(self.root_dir, options)
1032 client.SetConfig(gclient_config) 1002 client.SetConfig(gclient_config)
1033 exception = "Var is not defined: webkit" 1003 exception = "Var is not defined: webkit"
1034 try: 1004 try:
1035 client.RunOnDeps('update', self.args) 1005 client.RunOnDeps('update', self.args)
1036 except gclient.Error, e: 1006 except gclient.Error, e:
1037 self.assertEquals(e.args[0], exception) 1007 self.assertEquals(e.args[0], exception)
1038 else: 1008 else:
1039 self.fail('%s not raised' % exception) 1009 self.fail('%s not raised' % exception)
1040 1010
1041 def testRunOnDepsFailureInvalidCommand(self): 1011 def testRunOnDepsFailureInvalidCommand(self):
1042 options = self.Options() 1012 options = self.Options()
1043 1013
1044 self.mox.ReplayAll() 1014 self.mox.ReplayAll()
1045 client = self._gclient_gclient(self.root_dir, options) 1015 client = self._gclient_gclient(self.root_dir, options)
1046 exception = "'foo' is an unsupported command" 1016 exception = "'foo' is an unsupported command"
1047 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client, 1017 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1048 'foo', self.args) 1018 'foo', self.args)
1049 self.mox.VerifyAll()
1050 1019
1051 def testRunOnDepsFailureEmpty(self): 1020 def testRunOnDepsFailureEmpty(self):
1052 options = self.Options() 1021 options = self.Options()
1053 1022
1054 self.mox.ReplayAll() 1023 self.mox.ReplayAll()
1055 client = self._gclient_gclient(self.root_dir, options) 1024 client = self._gclient_gclient(self.root_dir, options)
1056 exception = "No solution specified" 1025 exception = "No solution specified"
1057 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client, 1026 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1058 'update', self.args) 1027 'update', self.args)
1059 self.mox.VerifyAll()
1060 1028
1061 def testFromImpl(self): 1029 def testFromImpl(self):
1062 # TODO(maruel): Test me! 1030 # TODO(maruel): Test me!
1063 pass 1031 pass
1064 1032
1065 def test_PrintRevInfo(self): 1033 def test_PrintRevInfo(self):
1066 # TODO(aharper): no test yet for revinfo, lock it down once we've verified 1034 # TODO(aharper): no test yet for revinfo, lock it down once we've verified
1067 # implementation for Pulse plugin 1035 # implementation for Pulse plugin
1068 pass 1036 pass
1069 1037
(...skipping 24 matching lines...) Expand all
1094 def setUp(self): 1062 def setUp(self):
1095 GClientBaseTestCase.setUp(self) 1063 GClientBaseTestCase.setUp(self)
1096 self.root_dir = Dir() 1064 self.root_dir = Dir()
1097 self.args = Args() 1065 self.args = Args()
1098 self.url = Url() 1066 self.url = Url()
1099 self.relpath = 'asf' 1067 self.relpath = 'asf'
1100 self._os_path_isdir = gclient.os.path.isdir 1068 self._os_path_isdir = gclient.os.path.isdir
1101 gclient.os.path.isdir = self.mox.CreateMockAnything() 1069 gclient.os.path.isdir = self.mox.CreateMockAnything()
1102 1070
1103 def tearDown(self): 1071 def tearDown(self):
1072 gclient.os.path.isdir = self._os_path_isdir
1104 GClientBaseTestCase.tearDown(self) 1073 GClientBaseTestCase.tearDown(self)
1105 gclient.os.path.isdir = self._os_path_isdir
1106 1074
1107 def testDir(self): 1075 def testDir(self):
1108 members = [ 1076 members = [
1109 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath', 1077 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath',
1110 'revert', 'scm_name', 'status', 'update', 'url', 1078 'revert', 'scm_name', 'status', 'update', 'url',
1111 ] 1079 ]
1112 1080
1113 # If you add a member, be sure to add the relevant test! 1081 # If you add a member, be sure to add the relevant test!
1114 self.compareMembers(self._scm_wrapper(), members) 1082 self.compareMembers(self._scm_wrapper(), members)
1115 1083
1116 def testFullUrlForRelativeUrl(self): 1084 def testFullUrlForRelativeUrl(self):
1117 self.url = 'svn://a/b/c/d' 1085 self.url = 'svn://a/b/c/d'
1118 1086
1119 self.mox.ReplayAll() 1087 self.mox.ReplayAll()
1120 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1088 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1121 relpath=self.relpath) 1089 relpath=self.relpath)
1122 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') 1090 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
1123 self.mox.VerifyAll()
1124 1091
1125 def testRunCommandException(self): 1092 def testRunCommandException(self):
1126 options = self.Options(verbose=False) 1093 options = self.Options(verbose=False)
1127 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git') 1094 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1128 ).AndReturn(False) 1095 ).AndReturn(False)
1129 1096
1130 self.mox.ReplayAll() 1097 self.mox.ReplayAll()
1131 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1098 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1132 relpath=self.relpath) 1099 relpath=self.relpath)
1133 exception = "Unsupported argument(s): %s" % ','.join(self.args) 1100 exception = "Unsupported argument(s): %s" % ','.join(self.args)
1134 self.assertRaisesError(exception, self._scm_wrapper.RunCommand, 1101 self.assertRaisesError(exception, self._scm_wrapper.RunCommand,
1135 scm, 'update', options, self.args) 1102 scm, 'update', options, self.args)
1136 self.mox.VerifyAll()
1137 1103
1138 def testRunCommandUnknown(self): 1104 def testRunCommandUnknown(self):
1139 # TODO(maruel): if ever used. 1105 # TODO(maruel): if ever used.
1140 pass 1106 pass
1141 1107
1142 def testRevertMissing(self): 1108 def testRevertMissing(self):
1143 options = self.Options(verbose=True) 1109 options = self.Options(verbose=True)
1144 base_path = os.path.join(self.root_dir, self.relpath) 1110 base_path = os.path.join(self.root_dir, self.relpath)
1145 gclient.os.path.isdir(base_path).AndReturn(False) 1111 gclient.os.path.isdir(base_path).AndReturn(False)
1146 # It'll to a checkout instead. 1112 # It'll to a checkout instead.
1147 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1113 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1148 print("\n_____ %s is missing, synching instead" % self.relpath) 1114 print("\n_____ %s is missing, synching instead" % self.relpath)
1149 # Checkout. 1115 # Checkout.
1150 gclient.os.path.exists(base_path).AndReturn(False) 1116 gclient.os.path.exists(base_path).AndReturn(False)
1151 files_list = self.mox.CreateMockAnything() 1117 files_list = self.mox.CreateMockAnything()
1152 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1118 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1153 self.root_dir, files_list) 1119 self.root_dir, files_list)
1154 1120
1155 self.mox.ReplayAll() 1121 self.mox.ReplayAll()
1156 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1122 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1157 relpath=self.relpath) 1123 relpath=self.relpath)
1158 scm.revert(options, self.args, files_list) 1124 scm.revert(options, self.args, files_list)
1159 self.mox.VerifyAll()
1160 1125
1161 def testRevertNone(self): 1126 def testRevertNone(self):
1162 options = self.Options(verbose=True) 1127 options = self.Options(verbose=True)
1163 base_path = os.path.join(self.root_dir, self.relpath) 1128 base_path = os.path.join(self.root_dir, self.relpath)
1164 gclient.os.path.isdir(base_path).AndReturn(True) 1129 gclient.os.path.isdir(base_path).AndReturn(True)
1165 gclient.CaptureSVNStatus(base_path).AndReturn([]) 1130 gclient.CaptureSVNStatus(base_path).AndReturn([])
1166 1131
1167 self.mox.ReplayAll() 1132 self.mox.ReplayAll()
1168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1169 relpath=self.relpath) 1134 relpath=self.relpath)
1170 file_list = [] 1135 file_list = []
1171 scm.revert(options, self.args, file_list) 1136 scm.revert(options, self.args, file_list)
1172 self.mox.VerifyAll()
1173 1137
1174 def testRevert2Files(self): 1138 def testRevert2Files(self):
1175 options = self.Options(verbose=True) 1139 options = self.Options(verbose=True)
1176 base_path = os.path.join(self.root_dir, self.relpath) 1140 base_path = os.path.join(self.root_dir, self.relpath)
1177 gclient.os.path.isdir(base_path).AndReturn(True) 1141 gclient.os.path.isdir(base_path).AndReturn(True)
1178 items = [ 1142 items = [
1179 ('M ', 'a'), 1143 ('M ', 'a'),
1180 ('A ', 'b'), 1144 ('A ', 'b'),
1181 ] 1145 ]
1182 gclient.CaptureSVNStatus(base_path).AndReturn(items) 1146 gclient.CaptureSVNStatus(base_path).AndReturn(items)
1183 1147
1184 print(os.path.join(base_path, 'a')) 1148 print(os.path.join(base_path, 'a'))
1185 print(os.path.join(base_path, 'b')) 1149 print(os.path.join(base_path, 'b'))
1186 gclient.RunSVN(['revert', 'a', 'b'], base_path) 1150 gclient.RunSVN(['revert', 'a', 'b'], base_path)
1187 1151
1188 self.mox.ReplayAll() 1152 self.mox.ReplayAll()
1189 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1153 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1190 relpath=self.relpath) 1154 relpath=self.relpath)
1191 file_list = [] 1155 file_list = []
1192 scm.revert(options, self.args, file_list) 1156 scm.revert(options, self.args, file_list)
1193 self.mox.VerifyAll()
1194 1157
1195 def testStatus(self): 1158 def testStatus(self):
1196 options = self.Options(verbose=True) 1159 options = self.Options(verbose=True)
1197 base_path = os.path.join(self.root_dir, self.relpath) 1160 base_path = os.path.join(self.root_dir, self.relpath)
1198 gclient.os.path.isdir(base_path).AndReturn(True) 1161 gclient.os.path.isdir(base_path).AndReturn(True)
1199 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path, 1162 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path,
1200 []).AndReturn(None) 1163 []).AndReturn(None)
1201 1164
1202 self.mox.ReplayAll() 1165 self.mox.ReplayAll()
1203 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1166 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1204 relpath=self.relpath) 1167 relpath=self.relpath)
1205 file_list = [] 1168 file_list = []
1206 self.assertEqual(scm.status(options, self.args, file_list), None) 1169 self.assertEqual(scm.status(options, self.args, file_list), None)
1207 self.mox.VerifyAll()
1208 1170
1209 1171
1210 # TODO(maruel): TEST REVISIONS!!! 1172 # TODO(maruel): TEST REVISIONS!!!
1211 # TODO(maruel): TEST RELOCATE!!! 1173 # TODO(maruel): TEST RELOCATE!!!
1212 def testUpdateCheckout(self): 1174 def testUpdateCheckout(self):
1213 options = self.Options(verbose=True) 1175 options = self.Options(verbose=True)
1214 base_path = os.path.join(self.root_dir, self.relpath) 1176 base_path = os.path.join(self.root_dir, self.relpath)
1215 file_info = gclient.PrintableObject() 1177 file_info = gclient.PrintableObject()
1216 file_info.root = 'blah' 1178 file_info.root = 'blah'
1217 file_info.url = self.url 1179 file_info.url = self.url
1218 file_info.uuid = 'ABC' 1180 file_info.uuid = 'ABC'
1219 file_info.revision = 42 1181 file_info.revision = 42
1220 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1182 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1221 # Checkout. 1183 # Checkout.
1222 gclient.os.path.exists(base_path).AndReturn(False) 1184 gclient.os.path.exists(base_path).AndReturn(False)
1223 files_list = self.mox.CreateMockAnything() 1185 files_list = self.mox.CreateMockAnything()
1224 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1186 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1225 self.root_dir, files_list) 1187 self.root_dir, files_list)
1226 self.mox.ReplayAll() 1188 self.mox.ReplayAll()
1227 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1189 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1228 relpath=self.relpath) 1190 relpath=self.relpath)
1229 scm.update(options, (), files_list) 1191 scm.update(options, (), files_list)
1230 self.mox.VerifyAll()
1231 1192
1232 def testUpdateUpdate(self): 1193 def testUpdateUpdate(self):
1233 options = self.Options(verbose=True) 1194 options = self.Options(verbose=True)
1234 base_path = os.path.join(self.root_dir, self.relpath) 1195 base_path = os.path.join(self.root_dir, self.relpath)
1235 options.force = True 1196 options.force = True
1236 file_info = { 1197 file_info = {
1237 'Repository Root': 'blah', 1198 'Repository Root': 'blah',
1238 'URL': self.url, 1199 'URL': self.url,
1239 'UUID': 'ABC', 1200 'UUID': 'ABC',
1240 'Revision': 42, 1201 'Revision': 42,
1241 } 1202 }
1242 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1203 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1243 # Checkout or update. 1204 # Checkout or update.
1244 gclient.os.path.exists(base_path).AndReturn(True) 1205 gclient.os.path.exists(base_path).AndReturn(True)
1245 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.' 1206 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.'
1246 ).AndReturn(file_info) 1207 ).AndReturn(file_info)
1247 # Cheat a bit here. 1208 # Cheat a bit here.
1248 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) 1209 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info)
1249 additional_args = [] 1210 additional_args = []
1250 if options.manually_grab_svn_rev: 1211 if options.manually_grab_svn_rev:
1251 additional_args = ['--revision', str(file_info['Revision'])] 1212 additional_args = ['--revision', str(file_info['Revision'])]
1252 files_list = [] 1213 files_list = []
1253 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args, 1214 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args,
1254 self.root_dir, files_list) 1215 self.root_dir, files_list)
1255 1216
1256 self.mox.ReplayAll() 1217 self.mox.ReplayAll()
1257 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1218 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1258 relpath=self.relpath) 1219 relpath=self.relpath)
1259 scm.update(options, (), files_list) 1220 scm.update(options, (), files_list)
1260 self.mox.VerifyAll()
1261 1221
1262 def testUpdateGit(self): 1222 def testUpdateGit(self):
1263 options = self.Options(verbose=True) 1223 options = self.Options(verbose=True)
1264 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git') 1224 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1265 ).AndReturn(True) 1225 ).AndReturn(True)
1266 print("________ found .git directory; skipping %s" % self.relpath) 1226 print("________ found .git directory; skipping %s" % self.relpath)
1267 1227
1268 self.mox.ReplayAll() 1228 self.mox.ReplayAll()
1269 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1229 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1270 relpath=self.relpath) 1230 relpath=self.relpath)
1271 file_list = [] 1231 file_list = []
1272 scm.update(options, self.args, file_list) 1232 scm.update(options, self.args, file_list)
1273 self.mox.VerifyAll()
1274 1233
1275 def testGetSVNFileInfo(self): 1234 def testGetSVNFileInfo(self):
1276 xml_text = r"""<?xml version="1.0"?> 1235 xml_text = r"""<?xml version="1.0"?>
1277 <info> 1236 <info>
1278 <entry kind="file" path="%s" revision="14628"> 1237 <entry kind="file" path="%s" revision="14628">
1279 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> 1238 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
1280 <repository><root>http://src.chromium.org/svn</root></repository> 1239 <repository><root>http://src.chromium.org/svn</root></repository>
1281 <wc-info> 1240 <wc-info>
1282 <schedule>add</schedule> 1241 <schedule>add</schedule>
1283 <depth>infinity</depth> 1242 <depth>infinity</depth>
(...skipping 13 matching lines...) Expand all
1297 'Schedule': 'add', 1256 'Schedule': 'add',
1298 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS' , 1257 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS' ,
1299 'Copied From Rev': '14628', 1258 'Copied From Rev': '14628',
1300 'Path': self.url, 1259 'Path': self.url,
1301 'Revision': 14628, 1260 'Revision': 14628,
1302 'Node Kind': 'file', 1261 'Node Kind': 'file',
1303 } 1262 }
1304 self.mox.ReplayAll() 1263 self.mox.ReplayAll()
1305 file_info = self._CaptureSVNInfo(self.url, '.', True) 1264 file_info = self._CaptureSVNInfo(self.url, '.', True)
1306 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) 1265 self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
1307 self.mox.VerifyAll()
1308 1266
1309 def testCaptureSvnInfo(self): 1267 def testCaptureSvnInfo(self):
1310 xml_text = """<?xml version="1.0"?> 1268 xml_text = """<?xml version="1.0"?>
1311 <info> 1269 <info>
1312 <entry 1270 <entry
1313 kind="dir" 1271 kind="dir"
1314 path="." 1272 path="."
1315 revision="35"> 1273 revision="35">
1316 <url>%s</url> 1274 <url>%s</url>
1317 <repository> 1275 <repository>
(...skipping 21 matching lines...) Expand all
1339 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', 1297 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
1340 'Revision': 35, 1298 'Revision': 35,
1341 'Repository Root': self.root_dir, 1299 'Repository Root': self.root_dir,
1342 'Schedule': 'normal', 1300 'Schedule': 'normal',
1343 'Copied From URL': None, 1301 'Copied From URL': None,
1344 'Copied From Rev': None, 1302 'Copied From Rev': None,
1345 'Path': '.', 1303 'Path': '.',
1346 'Node Kind': 'dir', 1304 'Node Kind': 'dir',
1347 } 1305 }
1348 self.assertEqual(file_info, expected) 1306 self.assertEqual(file_info, expected)
1349 self.mox.VerifyAll()
1350 1307
1351 1308
1352 class RunSVNTestCase(BaseTestCase): 1309 class RunSVNTestCase(BaseTestCase):
1353 def setUp(self): 1310 def setUp(self):
1354 self.mox = mox.Mox() 1311 BaseTestCase.setUp(self)
1355 self._OldSubprocessCall = gclient.SubprocessCall 1312 self._OldSubprocessCall = gclient.SubprocessCall
1356 gclient.SubprocessCall = self.mox.CreateMockAnything() 1313 gclient.SubprocessCall = self.mox.CreateMockAnything()
1357 1314
1358 def tearDown(self): 1315 def tearDown(self):
1359 gclient.SubprocessCall = self._OldSubprocessCall 1316 gclient.SubprocessCall = self._OldSubprocessCall
1317 BaseTestCase.tearDown(self)
1360 1318
1361 def testRunSVN(self): 1319 def testRunSVN(self):
1362 param2 = 'bleh' 1320 param2 = 'bleh'
1363 gclient.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) 1321 gclient.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None)
1364 self.mox.ReplayAll() 1322 self.mox.ReplayAll()
1365 gclient.RunSVN(['foo', 'bar'], param2) 1323 gclient.RunSVN(['foo', 'bar'], param2)
1366 self.mox.VerifyAll()
1367 1324
1368 1325
1369 class SubprocessCallAndCaptureTestCase(BaseTestCase): 1326 class SubprocessCallAndCaptureTestCase(BaseTestCase):
1370 def setUp(self): 1327 def setUp(self):
1371 self.mox = mox.Mox() 1328 BaseTestCase.setUp(self)
1372 self._sys_stdout = gclient.sys.stdout 1329 self._sys_stdout = gclient.sys.stdout
1373 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) 1330 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout)
1374 self._subprocess_Popen = gclient.subprocess.Popen 1331 self._subprocess_Popen = gclient.subprocess.Popen
1375 gclient.subprocess.Popen = self.mox.CreateMockAnything() 1332 gclient.subprocess.Popen = self.mox.CreateMockAnything()
1376 self._CaptureSVN = gclient.CaptureSVN 1333 self._CaptureSVN = gclient.CaptureSVN
1377 gclient.CaptureSVN = self.mox.CreateMockAnything() 1334 gclient.CaptureSVN = self.mox.CreateMockAnything()
1378 1335
1379 def tearDown(self): 1336 def tearDown(self):
1380 gclient.sys.stdout = self._sys_stdout 1337 gclient.sys.stdout = self._sys_stdout
1381 gclient.subprocess.Popen = self._subprocess_Popen 1338 gclient.subprocess.Popen = self._subprocess_Popen
1382 gclient.CaptureSVN = self._CaptureSVN 1339 gclient.CaptureSVN = self._CaptureSVN
1340 BaseTestCase.tearDown(self)
1383 1341
1384 def testSubprocessCallAndCapture(self): 1342 def testSubprocessCallAndCapture(self):
1385 command = ['boo', 'foo', 'bar'] 1343 command = ['boo', 'foo', 'bar']
1386 in_directory = 'bleh' 1344 in_directory = 'bleh'
1387 fail_status = None 1345 fail_status = None
1388 pattern = 'a(.*)b' 1346 pattern = 'a(.*)b'
1389 test_string = 'ahah\naccb\nallo\naddb\n' 1347 test_string = 'ahah\naccb\nallo\naddb\n'
1390 class Mock(object): 1348 class Mock(object):
1391 stdout = StringIO.StringIO(test_string) 1349 stdout = StringIO.StringIO(test_string)
1392 def wait(self): 1350 def wait(self):
1393 pass 1351 pass
1394 kid = Mock() 1352 kid = Mock()
1395 print("\n________ running 'boo foo bar' in 'bleh'") 1353 print("\n________ running 'boo foo bar' in 'bleh'")
1396 for i in test_string: 1354 for i in test_string:
1397 gclient.sys.stdout.write(i) 1355 gclient.sys.stdout.write(i)
1398 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory, 1356 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory,
1399 shell=(sys.platform == 'win32'), 1357 shell=(sys.platform == 'win32'),
1400 stdout=gclient.subprocess.PIPE).AndReturn(kid) 1358 stdout=gclient.subprocess.PIPE).AndReturn(kid)
1401 self.mox.ReplayAll() 1359 self.mox.ReplayAll()
1402 capture_list = [] 1360 capture_list = []
1403 gclient.SubprocessCallAndCapture(command, in_directory, fail_status, 1361 gclient.SubprocessCallAndCapture(command, in_directory, fail_status,
1404 pattern, capture_list) 1362 pattern, capture_list)
1405 self.assertEquals(capture_list, ['cc', 'dd']) 1363 self.assertEquals(capture_list, ['cc', 'dd'])
1406 self.mox.VerifyAll()
1407 1364
1408 def testCaptureSVNStatus(self): 1365 def testCaptureSVNStatus(self):
1409 x = self 1366 x = self
1410 def CaptureSVNMock(command, in_directory=None, print_error=True): 1367 def CaptureSVNMock(command, in_directory=None, print_error=True):
1411 x.assertEquals(in_directory, None) 1368 x.assertEquals(in_directory, None)
1412 x.assertEquals(print_error, True) 1369 x.assertEquals(print_error, True)
1413 x.assertEquals(['status', '--xml', '.'], command) 1370 x.assertEquals(['status', '--xml', '.'], command)
1414 return r"""<?xml version="1.0"?> 1371 return r"""<?xml version="1.0"?>
1415 <status> 1372 <status>
1416 <target path="."> 1373 <target path=".">
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 """ 1430 """
1474 gclient.CaptureSVN = CaptureSVNMock 1431 gclient.CaptureSVN = CaptureSVNMock
1475 info = gclient.CaptureSVNStatus(None) 1432 info = gclient.CaptureSVNStatus(None)
1476 self.assertEquals(info, []) 1433 self.assertEquals(info, [])
1477 1434
1478 1435
1479 if __name__ == '__main__': 1436 if __name__ == '__main__':
1480 unittest.main() 1437 unittest.main()
1481 1438
1482 # vim: ts=2:sw=2:tw=80:et: 1439 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698