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

Side by Side Diff: tests/gclient_test.py

Issue 115286: Remove the options.path_exists which only existed as a seam. It's not really ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « gclient.py ('k') | 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 self._RemoveDirectory = gclient.RemoveDirectory 112 self._RemoveDirectory = gclient.RemoveDirectory
113 gclient.RemoveDirectory = self.mox.CreateMockAnything() 113 gclient.RemoveDirectory = self.mox.CreateMockAnything()
114 self._RunSVN = gclient.RunSVN 114 self._RunSVN = gclient.RunSVN
115 gclient.RunSVN = self.mox.CreateMockAnything() 115 gclient.RunSVN = self.mox.CreateMockAnything()
116 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList 116 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList
117 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything() 117 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything()
118 self._sys_stdout = gclient.sys.stdout 118 self._sys_stdout = gclient.sys.stdout
119 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) 119 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout)
120 self._subprocess = gclient.subprocess 120 self._subprocess = gclient.subprocess
121 gclient.subprocess = self.mox.CreateMock(self._subprocess) 121 gclient.subprocess = self.mox.CreateMock(self._subprocess)
122 self._os_path_exists = gclient.os.path.exists
123 gclient.os.path.exists = self.mox.CreateMockAnything()
122 124
123 def tearDown(self): 125 def tearDown(self):
124 gclient.CaptureSVN = self._CaptureSVN 126 gclient.CaptureSVN = self._CaptureSVN
125 gclient.CaptureSVNInfo = self._CaptureSVNInfo 127 gclient.CaptureSVNInfo = self._CaptureSVNInfo
126 gclient.CaptureSVNStatus = self._CaptureSVNStatus 128 gclient.CaptureSVNStatus = self._CaptureSVNStatus
127 gclient.FileRead = self._FileRead 129 gclient.FileRead = self._FileRead
128 gclient.FileWrite = self._FileWrite 130 gclient.FileWrite = self._FileWrite
129 gclient.RemoveDirectory = self._RemoveDirectory 131 gclient.RemoveDirectory = self._RemoveDirectory
130 gclient.RunSVN = self._RunSVN 132 gclient.RunSVN = self._RunSVN
131 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList 133 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList
132 gclient.sys.stdout = self._sys_stdout 134 gclient.sys.stdout = self._sys_stdout
133 gclient.subprocess = self._subprocess 135 gclient.subprocess = self._subprocess
136 gclient.os.path.exists = self._os_path_exists
134 137
135 138
136 class GclientTestCase(GClientBaseTestCase): 139 class GclientTestCase(GClientBaseTestCase):
137 class OptionsObject(object): 140 class OptionsObject(object):
138 def __init__(self, test_case, verbose=False, spec=None, 141 def __init__(self, test_case, verbose=False, spec=None,
139 config_filename='a_file_name', 142 config_filename='a_file_name',
140 entries_filename='a_entry_file_name', 143 entries_filename='a_entry_file_name',
141 deps_file='a_deps_file_name', force=False): 144 deps_file='a_deps_file_name', force=False):
142 self.verbose = verbose 145 self.verbose = verbose
143 self.spec = spec 146 self.spec = spec
144 self.config_filename = config_filename 147 self.config_filename = config_filename
145 self.entries_filename = entries_filename 148 self.entries_filename = entries_filename
146 self.deps_file = deps_file 149 self.deps_file = deps_file
147 self.force = force 150 self.force = force
148 self.revisions = [] 151 self.revisions = []
149 self.manually_grab_svn_rev = True 152 self.manually_grab_svn_rev = True
150 self.deps_os = None 153 self.deps_os = None
151 self.head = False 154 self.head = False
152 155
153 # Mox 156 # Mox
154 self.path_exists = test_case.path_exists
155 self.platform = test_case.platform 157 self.platform = test_case.platform
156 self.gclient = test_case.gclient 158 self.gclient = test_case.gclient
157 self.scm_wrapper = test_case.scm_wrapper 159 self.scm_wrapper = test_case.scm_wrapper
158 160
159 def setUp(self): 161 def setUp(self):
160 GClientBaseTestCase.setUp(self) 162 GClientBaseTestCase.setUp(self)
161 #self.subprocess = self.mox.CreateMock(subprocess)
162 # Stub os.path.exists.
163 self.path_exists = self.mox.CreateMockAnything()
164 self.platform = 'darwin' 163 self.platform = 'darwin'
165 164
166 self.gclient = self.mox.CreateMock(gclient.GClient) 165 self.gclient = self.mox.CreateMock(gclient.GClient)
167 self.scm_wrapper = self.mox.CreateMock(gclient.SCMWrapper) 166 self.scm_wrapper = self.mox.CreateMock(gclient.SCMWrapper)
168 167
169 self.args = Args() 168 self.args = Args()
170 self.root_dir = Dir() 169 self.root_dir = Dir()
171 self.url = Url() 170 self.url = Url()
172 171
173 172
(...skipping 18 matching lines...) Expand all
192 exception_msg = "required argument missing; see 'gclient help config'" 191 exception_msg = "required argument missing; see 'gclient help config'"
193 192
194 self.mox.ReplayAll() 193 self.mox.ReplayAll()
195 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ()) 194 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ())
196 self.mox.VerifyAll() 195 self.mox.VerifyAll()
197 196
198 def testExistingClientFile(self): 197 def testExistingClientFile(self):
199 options = self.Options() 198 options = self.Options()
200 exception_msg = ('%s file already exists in the current directory' % 199 exception_msg = ('%s file already exists in the current directory' %
201 options.config_filename) 200 options.config_filename)
202 self.path_exists(options.config_filename).AndReturn(True) 201 gclient.os.path.exists(options.config_filename).AndReturn(True)
203 202
204 self.mox.ReplayAll() 203 self.mox.ReplayAll()
205 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,)) 204 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,))
206 self.mox.VerifyAll() 205 self.mox.VerifyAll()
207 206
208 def testFromText(self): 207 def testFromText(self):
209 options = self.Options(spec='config_source_content') 208 options = self.Options(spec='config_source_content')
210 options.path_exists(options.config_filename).AndReturn(False) 209 gclient.os.path.exists(options.config_filename).AndReturn(False)
211 options.gclient('.', options).AndReturn(options.gclient) 210 options.gclient('.', options).AndReturn(options.gclient)
212 options.gclient.SetConfig(options.spec) 211 options.gclient.SetConfig(options.spec)
213 options.gclient.SaveConfig() 212 options.gclient.SaveConfig()
214 213
215 self.mox.ReplayAll() 214 self.mox.ReplayAll()
216 gclient.DoConfig(options, (1,),) 215 gclient.DoConfig(options, (1,),)
217 self.mox.VerifyAll() 216 self.mox.VerifyAll()
218 217
219 def testCreateClientFile(self): 218 def testCreateClientFile(self):
220 options = self.Options() 219 options = self.Options()
221 options.path_exists(options.config_filename).AndReturn(False) 220 gclient.os.path.exists(options.config_filename).AndReturn(False)
222 options.gclient('.', options).AndReturn(options.gclient) 221 options.gclient('.', options).AndReturn(options.gclient)
223 options.gclient.SetDefaultConfig('the_name', 'http://svn/url/the_name', 222 options.gclient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
224 'other') 223 'other')
225 options.gclient.SaveConfig() 224 options.gclient.SaveConfig()
226 225
227 self.mox.ReplayAll() 226 self.mox.ReplayAll()
228 gclient.DoConfig(options, 227 gclient.DoConfig(options,
229 ('http://svn/url/the_name', 'other', 'args', 'ignored')) 228 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
230 self.mox.VerifyAll() 229 self.mox.VerifyAll()
231 230
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 }] 422 }]
424 self.assertEqual(client.GetVar('solutions'), solutions) 423 self.assertEqual(client.GetVar('solutions'), solutions)
425 self.assertEqual(client.GetVar('foo'), None) 424 self.assertEqual(client.GetVar('foo'), None)
426 self.mox.VerifyAll() 425 self.mox.VerifyAll()
427 426
428 def testLoadCurrentConfig(self): 427 def testLoadCurrentConfig(self):
429 # pymox has trouble to mock the class object and not a class instance. 428 # pymox has trouble to mock the class object and not a class instance.
430 self.gclient = self.mox.CreateMockAnything() 429 self.gclient = self.mox.CreateMockAnything()
431 options = self.Options() 430 options = self.Options()
432 path = os.path.realpath(self.root_dir) 431 path = os.path.realpath(self.root_dir)
433 options.path_exists(os.path.join(path, options.config_filename) 432 gclient.os.path.exists(os.path.join(path, options.config_filename)
434 ).AndReturn(True) 433 ).AndReturn(True)
435 options.gclient(path, options).AndReturn(options.gclient) 434 options.gclient(path, options).AndReturn(options.gclient)
436 options.gclient._LoadConfig() 435 options.gclient._LoadConfig()
437 436
438 self.mox.ReplayAll() 437 self.mox.ReplayAll()
439 client = gclient.GClient.LoadCurrentConfig(options, self.root_dir) 438 client = gclient.GClient.LoadCurrentConfig(options, self.root_dir)
440 self.mox.VerifyAll() 439 self.mox.VerifyAll()
441 440
442 def testRunOnDepsNoDeps(self): 441 def testRunOnDepsNoDeps(self):
443 solution_name = 'testRunOnDepsNoDeps_solution_name' 442 solution_name = 'testRunOnDepsNoDeps_solution_name'
444 gclient_config = ( 443 gclient_config = (
445 "solutions = [ {\n" 444 "solutions = [ {\n"
446 " 'name': '%s',\n" 445 " 'name': '%s',\n"
447 " 'url': '%s',\n" 446 " 'url': '%s',\n"
448 " 'custom_deps': {},\n" 447 " 'custom_deps': {},\n"
449 "} ]\n" 448 "} ]\n"
450 ) % (solution_name, self.url) 449 ) % (solution_name, self.url)
451 450
452 entries_content = ( 451 entries_content = (
453 'entries = [\n' 452 'entries = [\n'
454 ' "%s",\n' 453 ' "%s",\n'
455 ']\n' 454 ']\n'
456 ) % solution_name 455 ) % solution_name
457 456
458 self.scm_wrapper = self.mox.CreateMockAnything() 457 self.scm_wrapper = self.mox.CreateMockAnything()
459 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper) 458 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper)
460 459
461 options = self.Options() 460 options = self.Options()
462 461
462 checkout_path = os.path.join(self.root_dir, solution_name)
463 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False)
463 # Expect a check for the entries file and we say there is not one. 464 # Expect a check for the entries file and we say there is not one.
464 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 465 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
465 ).AndReturn(False) 466 ).AndReturn(False)
466 467
467 # An scm will be requested for the solution. 468 # An scm will be requested for the solution.
468 options.scm_wrapper(self.url, self.root_dir, solution_name 469 options.scm_wrapper(self.url, self.root_dir, solution_name
469 ).AndReturn(scm_wrapper_sol) 470 ).AndReturn(scm_wrapper_sol)
470 # Then an update will be performed. 471 # Then an update will be performed.
471 scm_wrapper_sol.RunCommand('update', options, self.args, []) 472 scm_wrapper_sol.RunCommand('update', options, self.args, [])
472 # Then an attempt will be made to read its DEPS file. 473 # Then an attempt will be made to read its DEPS file.
473 gclient.FileRead(os.path.join(self.root_dir, 474 gclient.FileRead(os.path.join(self.root_dir,
474 solution_name, 475 solution_name,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 ' "%s",\n' 508 ' "%s",\n'
508 ']\n' 509 ']\n'
509 ) % (os.path.join(solution_name, 'src', 't'), solution_name) 510 ) % (os.path.join(solution_name, 'src', 't'), solution_name)
510 511
511 self.scm_wrapper = self.mox.CreateMockAnything() 512 self.scm_wrapper = self.mox.CreateMockAnything()
512 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper) 513 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper)
513 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper) 514 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper)
514 515
515 options = self.Options() 516 options = self.Options()
516 517
518 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, 'src',
519 't', '.git')
520 ).AndReturn(False)
521 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, '.git')
522 ).AndReturn(False)
517 # Expect a check for the entries file and we say there is not one. 523 # Expect a check for the entries file and we say there is not one.
518 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 524 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
519 ).AndReturn(False) 525 ).AndReturn(False)
520 526
521 # An scm will be requested for the solution. 527 # An scm will be requested for the solution.
522 options.scm_wrapper(self.url, self.root_dir, solution_name 528 options.scm_wrapper(self.url, self.root_dir, solution_name
523 ).AndReturn(scm_wrapper_sol) 529 ).AndReturn(scm_wrapper_sol)
524 # Then an update will be performed. 530 # Then an update will be performed.
525 scm_wrapper_sol.RunCommand('update', options, self.args, []) 531 scm_wrapper_sol.RunCommand('update', options, self.args, [])
526 # Then an attempt will be made to read its DEPS file. 532 # Then an attempt will be made to read its DEPS file.
527 gclient.FileRead(os.path.join(self.root_dir, 533 gclient.FileRead(os.path.join(self.root_dir,
528 solution_name, 534 solution_name,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 ']\n' 582 ']\n'
577 ) % solution_name 583 ) % solution_name
578 584
579 self.scm_wrapper = self.mox.CreateMockAnything() 585 self.scm_wrapper = self.mox.CreateMockAnything()
580 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper) 586 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper)
581 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper) 587 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper)
582 scm_wrapper_n = self.mox.CreateMock(gclient.SCMWrapper) 588 scm_wrapper_n = self.mox.CreateMock(gclient.SCMWrapper)
583 589
584 options = self.Options() 590 options = self.Options()
585 591
592 checkout_path = os.path.join(self.root_dir, solution_name)
593 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False)
594 gclient.os.path.exists(os.path.join(self.root_dir, 'src/n', '.git')
595 ).AndReturn(False)
596 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git')
597 ).AndReturn(False)
598
586 # Expect a check for the entries file and we say there is not one. 599 # Expect a check for the entries file and we say there is not one.
587 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 600 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
588 ).AndReturn(False) 601 ).AndReturn(False)
589 602
590 # An scm will be requested for the solution. 603 # An scm will be requested for the solution.
591 options.scm_wrapper(self.url, self.root_dir, solution_name 604 options.scm_wrapper(self.url, self.root_dir, solution_name
592 ).AndReturn(scm_wrapper_sol) 605 ).AndReturn(scm_wrapper_sol)
593 # Then an update will be performed. 606 # Then an update will be performed.
594 scm_wrapper_sol.RunCommand('update', options, self.args, []) 607 scm_wrapper_sol.RunCommand('update', options, self.args, [])
595 # Then an attempt will be made to read its DEPS file. 608 # Then an attempt will be made to read its DEPS file.
596 gclient.FileRead(os.path.join(self.root_dir, 609 gclient.FileRead(os.path.join(checkout_path, options.deps_file)
597 solution_name, 610 ).AndReturn(deps)
598 options.deps_file)).AndReturn(deps)
599 611
600 # Next we expect an scm to be request for dep src/n even though it does not 612 # Next we expect an scm to be request for dep src/n even though it does not
601 # exist in the DEPS file. 613 # exist in the DEPS file.
602 options.scm_wrapper('svn://custom.n/trunk', 614 options.scm_wrapper('svn://custom.n/trunk',
603 self.root_dir, 615 self.root_dir,
604 "src/n").AndReturn(scm_wrapper_n) 616 "src/n").AndReturn(scm_wrapper_n)
605 617
606 # Next we expect an scm to be request for dep src/t but it should 618 # Next we expect an scm to be request for dep src/t but it should
607 # use the url specified in custom_deps. 619 # use the url specified in custom_deps.
608 options.scm_wrapper('svn://custom.t/trunk', 620 options.scm_wrapper('svn://custom.t/trunk',
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 ' "src/t",\n' 670 ' "src/t",\n'
659 ']\n') % (name_a, name_b) 671 ']\n') % (name_a, name_b)
660 672
661 self.scm_wrapper = self.mox.CreateMockAnything() 673 self.scm_wrapper = self.mox.CreateMockAnything()
662 scm_wrapper_a = self.mox.CreateMock(gclient.SCMWrapper) 674 scm_wrapper_a = self.mox.CreateMock(gclient.SCMWrapper)
663 scm_wrapper_b = self.mox.CreateMock(gclient.SCMWrapper) 675 scm_wrapper_b = self.mox.CreateMock(gclient.SCMWrapper)
664 scm_wrapper_dep = self.mox.CreateMock(gclient.SCMWrapper) 676 scm_wrapper_dep = self.mox.CreateMock(gclient.SCMWrapper)
665 677
666 options = self.Options() 678 options = self.Options()
667 679
680 gclient.os.path.exists(os.path.join(self.root_dir, name_a, '.git')
681 ).AndReturn(False)
682 gclient.os.path.exists(os.path.join(self.root_dir, name_b, '.git')
683 ).AndReturn(False)
684 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git')
685 ).AndReturn(False)
686
668 # Expect a check for the entries file and we say there is not one. 687 # Expect a check for the entries file and we say there is not one.
669 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 688 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
670 ).AndReturn(False) 689 ).AndReturn(False)
671 690
672 # An scm will be requested for the first solution. 691 # An scm will be requested for the first solution.
673 options.scm_wrapper(url_a, self.root_dir, name_a).AndReturn( 692 options.scm_wrapper(url_a, self.root_dir, name_a).AndReturn(
674 scm_wrapper_a) 693 scm_wrapper_a)
675 # Then an attempt will be made to read it's DEPS file. 694 # Then an attempt will be made to read it's DEPS file.
676 gclient.FileRead(os.path.join(self.root_dir, name_a, options.deps_file) 695 gclient.FileRead(os.path.join(self.root_dir, name_a, options.deps_file)
677 ).AndReturn(deps_a) 696 ).AndReturn(deps_a)
678 # Then an update will be performed. 697 # Then an update will be performed.
679 scm_wrapper_a.RunCommand('update', options, self.args, []) 698 scm_wrapper_a.RunCommand('update', options, self.args, [])
(...skipping 28 matching lines...) Expand all
708 name = 'testRunOnDepsSuccess_solution_name' 727 name = 'testRunOnDepsSuccess_solution_name'
709 gclient_config = """solutions = [ { 728 gclient_config = """solutions = [ {
710 'name': '%s', 729 'name': '%s',
711 'url': '%s', 730 'url': '%s',
712 'custom_deps': {}, 731 'custom_deps': {},
713 }, ]""" % (name, self.url) 732 }, ]""" % (name, self.url)
714 733
715 # pymox has trouble to mock the class object and not a class instance. 734 # pymox has trouble to mock the class object and not a class instance.
716 self.scm_wrapper = self.mox.CreateMockAnything() 735 self.scm_wrapper = self.mox.CreateMockAnything()
717 options = self.Options() 736 options = self.Options()
718 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 737 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
738 ).AndReturn(False)
739 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
719 ).AndReturn(False) 740 ).AndReturn(False)
720 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 741 options.scm_wrapper(self.url, self.root_dir, name).AndReturn(
721 options.scm_wrapper) 742 options.scm_wrapper)
722 options.scm_wrapper.RunCommand('update', options, self.args, []) 743 options.scm_wrapper.RunCommand('update', options, self.args, [])
723 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 744 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
724 ).AndReturn("Boo = 'a'") 745 ).AndReturn("Boo = 'a'")
725 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 746 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
726 'entries = [\n "%s",\n]\n' % name) 747 'entries = [\n "%s",\n]\n' % name)
727 748
728 self.mox.ReplayAll() 749 self.mox.ReplayAll()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', 811 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42',
791 'src/third_party/cygwin@333' ] 812 'src/third_party/cygwin@333' ]
792 813
793 # Also, pymox doesn't verify the order of function calling w.r.t. different 814 # Also, pymox doesn't verify the order of function calling w.r.t. different
794 # mock objects. Pretty lame. So reorder as we wish to make it clearer. 815 # mock objects. Pretty lame. So reorder as we wish to make it clearer.
795 gclient.FileRead(os.path.join(self.root_dir, 'src', options.deps_file) 816 gclient.FileRead(os.path.join(self.root_dir, 'src', options.deps_file)
796 ).AndReturn(deps_content) 817 ).AndReturn(deps_content)
797 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 818 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
798 entries_content) 819 entries_content)
799 820
800 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 821 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git')
822 ).AndReturn(False)
823 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
824 '.git')
825 ).AndReturn(False)
826 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin',
827 '.git')
828 ).AndReturn(False)
829 gclient.os.path.exists(os.path.join(self.root_dir,
830 'src/third_party/python_24', '.git')
831 ).AndReturn(False)
832 gclient.os.path.exists(os.path.join(self.root_dir, 'src/breakpad/bar',
833 '.git')
834 ).AndReturn(False)
835 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
801 ).AndReturn(False) 836 ).AndReturn(False)
802 837
803 options.scm_wrapper(self.url, self.root_dir, 'src').AndReturn( 838 options.scm_wrapper(self.url, self.root_dir, 'src').AndReturn(
804 scm_wrapper_src) 839 scm_wrapper_src)
805 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, []) 840 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, [])
806 841
807 options.scm_wrapper(self.url, self.root_dir, 842 options.scm_wrapper(self.url, self.root_dir,
808 None).AndReturn(scm_wrapper_src2) 843 None).AndReturn(scm_wrapper_src2)
809 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248' 844 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248'
810 ).AndReturn(cygwin_path) 845 ).AndReturn(cygwin_path)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 self.scm_wrapper = self.mox.CreateMockAnything() 930 self.scm_wrapper = self.mox.CreateMockAnything()
896 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper) 931 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper)
897 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper) 932 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper)
898 933
899 options = self.Options() 934 options = self.Options()
900 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 935 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
901 ).AndReturn(deps_content) 936 ).AndReturn(deps_content)
902 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 937 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
903 entries_content) 938 entries_content)
904 939
905 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 940 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
941 '.git')).AndReturn(False)
942 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
943 ).AndReturn(False)
944 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
906 ).AndReturn(False) 945 ).AndReturn(False)
907 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 946 options.scm_wrapper(self.url, self.root_dir, name).AndReturn(
908 options.scm_wrapper) 947 options.scm_wrapper)
909 options.scm_wrapper.RunCommand('update', options, self.args, []) 948 options.scm_wrapper.RunCommand('update', options, self.args, [])
910 949
911 options.scm_wrapper(self.url, self.root_dir, 950 options.scm_wrapper(self.url, self.root_dir,
912 None).AndReturn(scm_wrapper_src) 951 None).AndReturn(scm_wrapper_src)
913 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit' 952 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit'
914 ).AndReturn(webkit_path) 953 ).AndReturn(webkit_path)
915 954
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 self.scm_wrapper = self.mox.CreateMockAnything() 988 self.scm_wrapper = self.mox.CreateMockAnything()
950 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper) 989 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper)
951 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper) 990 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper)
952 991
953 options = self.Options() 992 options = self.Options()
954 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 993 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
955 ).AndReturn(deps_content) 994 ).AndReturn(deps_content)
956 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 995 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
957 entries_content) 996 entries_content)
958 997
959 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 998 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
999 '.git')
1000 ).AndReturn(False)
1001 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
1002 ).AndReturn(False)
1003 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
960 ).AndReturn(False) 1004 ).AndReturn(False)
961 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 1005 options.scm_wrapper(self.url, self.root_dir, name).AndReturn(
962 options.scm_wrapper) 1006 options.scm_wrapper)
963 options.scm_wrapper.RunCommand('update', options, self.args, []) 1007 options.scm_wrapper.RunCommand('update', options, self.args, [])
964 1008
965 options.scm_wrapper(self.url, self.root_dir, 1009 options.scm_wrapper(self.url, self.root_dir,
966 None).AndReturn(scm_wrapper_src) 1010 None).AndReturn(scm_wrapper_src)
967 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit' 1011 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit'
968 ).AndReturn(webkit_path) 1012 ).AndReturn(webkit_path)
969 1013
(...skipping 23 matching lines...) Expand all
993 1037
994 # pymox has trouble to mock the class object and not a class instance. 1038 # pymox has trouble to mock the class object and not a class instance.
995 self.scm_wrapper = self.mox.CreateMockAnything() 1039 self.scm_wrapper = self.mox.CreateMockAnything()
996 1040
997 options = self.Options() 1041 options = self.Options()
998 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 1042 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
999 ).AndReturn(deps_content) 1043 ).AndReturn(deps_content)
1000 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 1044 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
1001 'dummy entries content') 1045 'dummy entries content')
1002 1046
1003 options.path_exists(os.path.join(self.root_dir, options.entries_filename) 1047 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
1004 ).AndReturn(False) 1048 ).AndReturn(False)
1005 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 1049 options.scm_wrapper(self.url, self.root_dir, name).AndReturn(
1006 options.scm_wrapper) 1050 options.scm_wrapper)
1007 options.scm_wrapper.RunCommand('update', options, self.args, []) 1051 options.scm_wrapper.RunCommand('update', options, self.args, [])
1008 1052
1009 self.mox.ReplayAll() 1053 self.mox.ReplayAll()
1010 client = gclient.GClient(self.root_dir, options) 1054 client = gclient.GClient(self.root_dir, options)
1011 client.SetConfig(gclient_config) 1055 client.SetConfig(gclient_config)
1012 exception = "Var is not defined: webkit" 1056 exception = "Var is not defined: webkit"
1013 try: 1057 try:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1107
1064 class SCMWrapperTestCase(GClientBaseTestCase): 1108 class SCMWrapperTestCase(GClientBaseTestCase):
1065 class OptionsObject(object): 1109 class OptionsObject(object):
1066 def __init__(self, test_case, verbose=False, revision=None): 1110 def __init__(self, test_case, verbose=False, revision=None):
1067 self.verbose = verbose 1111 self.verbose = verbose
1068 self.revision = revision 1112 self.revision = revision
1069 self.manually_grab_svn_rev = True 1113 self.manually_grab_svn_rev = True
1070 self.deps_os = None 1114 self.deps_os = None
1071 self.force = False 1115 self.force = False
1072 1116
1073 # Mox
1074 self.path_exists = test_case.path_exists
1075
1076 def setUp(self): 1117 def setUp(self):
1077 GClientBaseTestCase.setUp(self) 1118 GClientBaseTestCase.setUp(self)
1078 self.root_dir = Dir() 1119 self.root_dir = Dir()
1079 self.args = Args() 1120 self.args = Args()
1080 self.url = Url() 1121 self.url = Url()
1081 self.relpath = 'asf' 1122 self.relpath = 'asf'
1082 # Stub os.path.exists. 1123 self._os_path_isdir = gclient.os.path.isdir
1083 self.path_exists = self.mox.CreateMockAnything() 1124 gclient.os.path.isdir = self.mox.CreateMockAnything()
1125
1126 def tearDown(self):
1127 GClientBaseTestCase.tearDown(self)
1128 gclient.os.path.isdir = self._os_path_isdir
1084 1129
1085 def testDir(self): 1130 def testDir(self):
1086 members = [ 1131 members = [
1087 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath', 1132 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath',
1088 'revert', 'scm_name', 'status', 'update', 'url', 1133 'revert', 'scm_name', 'status', 'update', 'url',
1089 ] 1134 ]
1090 1135
1091 # If you add a member, be sure to add the relevant test! 1136 # If you add a member, be sure to add the relevant test!
1092 self.compareMembers(gclient.SCMWrapper(), members) 1137 self.compareMembers(gclient.SCMWrapper(), members)
1093 1138
1094 def testFullUrlForRelativeUrl(self): 1139 def testFullUrlForRelativeUrl(self):
1095 self.url = 'svn://a/b/c/d' 1140 self.url = 'svn://a/b/c/d'
1096 1141
1097 self.mox.ReplayAll() 1142 self.mox.ReplayAll()
1098 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1143 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1099 relpath=self.relpath) 1144 relpath=self.relpath)
1100 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') 1145 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
1101 self.mox.VerifyAll() 1146 self.mox.VerifyAll()
1102 1147
1103 def testRunCommandException(self): 1148 def testRunCommandException(self):
1104 options = self.Options(verbose=False) 1149 options = self.Options(verbose=False)
1105 options.path_exists(os.path.join(self.root_dir, self.relpath, '.git') 1150 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1106 ).AndReturn(False) 1151 ).AndReturn(False)
1107 1152
1108 self.mox.ReplayAll() 1153 self.mox.ReplayAll()
1109 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1154 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1110 relpath=self.relpath) 1155 relpath=self.relpath)
1111 exception = "Unsupported argument(s): %s" % ','.join(self.args) 1156 exception = "Unsupported argument(s): %s" % ','.join(self.args)
1112 self.assertRaisesError(exception, gclient.SCMWrapper.RunCommand, 1157 self.assertRaisesError(exception, gclient.SCMWrapper.RunCommand,
1113 scm, 'update', options, self.args) 1158 scm, 'update', options, self.args)
1114 self.mox.VerifyAll() 1159 self.mox.VerifyAll()
1115 1160
1116 def testRunCommandUnknown(self): 1161 def testRunCommandUnknown(self):
1117 # TODO(maruel): if ever used. 1162 # TODO(maruel): if ever used.
1118 pass 1163 pass
1119 1164
1120 def testRevertMissing(self): 1165 def testRevertMissing(self):
1121 options = self.Options(verbose=True) 1166 options = self.Options(verbose=True)
1122 gclient.os.path.isdir = self.mox.CreateMockAnything()
1123 base_path = os.path.join(self.root_dir, self.relpath) 1167 base_path = os.path.join(self.root_dir, self.relpath)
1124 gclient.os.path.isdir(base_path).AndReturn(False) 1168 gclient.os.path.isdir(base_path).AndReturn(False)
1125 # It'll to a checkout instead. 1169 # It'll to a checkout instead.
1126 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) 1170 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1127 print("\n_____ %s is missing, synching instead" % self.relpath) 1171 print("\n_____ %s is missing, synching instead" % self.relpath)
1128 # Checkout. 1172 # Checkout.
1129 options.path_exists(base_path).AndReturn(False) 1173 gclient.os.path.exists(base_path).AndReturn(False)
1130 files_list = self.mox.CreateMockAnything() 1174 files_list = self.mox.CreateMockAnything()
1131 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1175 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1132 self.root_dir, files_list) 1176 self.root_dir, files_list)
1133 1177
1134 self.mox.ReplayAll() 1178 self.mox.ReplayAll()
1135 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1179 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1136 relpath=self.relpath) 1180 relpath=self.relpath)
1137 scm.revert(options, self.args, files_list) 1181 scm.revert(options, self.args, files_list)
1138 self.mox.VerifyAll() 1182 self.mox.VerifyAll()
1139 gclient.os.path.isdir = os.path.isdir
1140 1183
1141 def testRevertNone(self): 1184 def testRevertNone(self):
1142 options = self.Options(verbose=True) 1185 options = self.Options(verbose=True)
1143 base_path = os.path.join(self.root_dir, self.relpath) 1186 base_path = os.path.join(self.root_dir, self.relpath)
1144 gclient.os.path.isdir = self.mox.CreateMockAnything()
1145 gclient.os.path.isdir(base_path).AndReturn(True) 1187 gclient.os.path.isdir(base_path).AndReturn(True)
1146 gclient.CaptureSVNStatus(base_path).AndReturn([]) 1188 gclient.CaptureSVNStatus(base_path).AndReturn([])
1147 1189
1148 self.mox.ReplayAll() 1190 self.mox.ReplayAll()
1149 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1191 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1150 relpath=self.relpath) 1192 relpath=self.relpath)
1151 file_list = [] 1193 file_list = []
1152 scm.revert(options, self.args, file_list) 1194 scm.revert(options, self.args, file_list)
1153 self.mox.VerifyAll() 1195 self.mox.VerifyAll()
1154 gclient.os.path.isdir = os.path.isdir
1155 1196
1156 def testRevert2Files(self): 1197 def testRevert2Files(self):
1157 options = self.Options(verbose=True) 1198 options = self.Options(verbose=True)
1158 base_path = os.path.join(self.root_dir, self.relpath) 1199 base_path = os.path.join(self.root_dir, self.relpath)
1159 gclient.os.path.isdir = self.mox.CreateMockAnything()
1160 gclient.os.path.isdir(base_path).AndReturn(True) 1200 gclient.os.path.isdir(base_path).AndReturn(True)
1161 items = [ 1201 items = [
1162 ('M ', 'a'), 1202 ('M ', 'a'),
1163 ('A ', 'b'), 1203 ('A ', 'b'),
1164 ] 1204 ]
1165 gclient.CaptureSVNStatus(base_path).AndReturn(items) 1205 gclient.CaptureSVNStatus(base_path).AndReturn(items)
1166 1206
1167 print(os.path.join(base_path, 'a')) 1207 print(os.path.join(base_path, 'a'))
1168 print(os.path.join(base_path, 'b')) 1208 print(os.path.join(base_path, 'b'))
1169 gclient.RunSVN(['revert', 'a', 'b'], base_path) 1209 gclient.RunSVN(['revert', 'a', 'b'], base_path)
1170 1210
1171 self.mox.ReplayAll() 1211 self.mox.ReplayAll()
1172 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1212 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1173 relpath=self.relpath) 1213 relpath=self.relpath)
1174 file_list = [] 1214 file_list = []
1175 scm.revert(options, self.args, file_list) 1215 scm.revert(options, self.args, file_list)
1176 self.mox.VerifyAll() 1216 self.mox.VerifyAll()
1177 gclient.os.path.isdir = os.path.isdir
1178 1217
1179 def testStatus(self): 1218 def testStatus(self):
1180 options = self.Options(verbose=True) 1219 options = self.Options(verbose=True)
1181 base_path = os.path.join(self.root_dir, self.relpath) 1220 base_path = os.path.join(self.root_dir, self.relpath)
1182 gclient.os.path.isdir = self.mox.CreateMockAnything()
1183 gclient.os.path.isdir(base_path).AndReturn(True) 1221 gclient.os.path.isdir(base_path).AndReturn(True)
1184 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path, 1222 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path,
1185 []).AndReturn(None) 1223 []).AndReturn(None)
1186 1224
1187 self.mox.ReplayAll() 1225 self.mox.ReplayAll()
1188 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1226 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1189 relpath=self.relpath) 1227 relpath=self.relpath)
1190 file_list = [] 1228 file_list = []
1191 self.assertEqual(scm.status(options, self.args, file_list), None) 1229 self.assertEqual(scm.status(options, self.args, file_list), None)
1192 self.mox.VerifyAll() 1230 self.mox.VerifyAll()
1193 1231
1194 1232
1195 # TODO(maruel): TEST REVISIONS!!! 1233 # TODO(maruel): TEST REVISIONS!!!
1196 # TODO(maruel): TEST RELOCATE!!! 1234 # TODO(maruel): TEST RELOCATE!!!
1197 def testUpdateCheckout(self): 1235 def testUpdateCheckout(self):
1198 options = self.Options(verbose=True) 1236 options = self.Options(verbose=True)
1199 base_path = os.path.join(self.root_dir, self.relpath) 1237 base_path = os.path.join(self.root_dir, self.relpath)
1200 file_info = gclient.PrintableObject() 1238 file_info = gclient.PrintableObject()
1201 file_info.root = 'blah' 1239 file_info.root = 'blah'
1202 file_info.url = self.url 1240 file_info.url = self.url
1203 file_info.uuid = 'ABC' 1241 file_info.uuid = 'ABC'
1204 file_info.revision = 42 1242 file_info.revision = 42
1205 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) 1243 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1206 # Checkout. 1244 # Checkout.
1207 options.path_exists(base_path).AndReturn(False) 1245 gclient.os.path.exists(base_path).AndReturn(False)
1208 files_list = self.mox.CreateMockAnything() 1246 files_list = self.mox.CreateMockAnything()
1209 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1247 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1210 self.root_dir, files_list) 1248 self.root_dir, files_list)
1211 self.mox.ReplayAll() 1249 self.mox.ReplayAll()
1212 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1250 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1213 relpath=self.relpath) 1251 relpath=self.relpath)
1214 scm.update(options, (), files_list) 1252 scm.update(options, (), files_list)
1215 self.mox.VerifyAll() 1253 self.mox.VerifyAll()
1216 1254
1217 def testUpdateUpdate(self): 1255 def testUpdateUpdate(self):
1218 options = self.Options(verbose=True) 1256 options = self.Options(verbose=True)
1219 base_path = os.path.join(self.root_dir, self.relpath) 1257 base_path = os.path.join(self.root_dir, self.relpath)
1220 options.force = True 1258 options.force = True
1221 file_info = { 1259 file_info = {
1222 'Repository Root': 'blah', 1260 'Repository Root': 'blah',
1223 'URL': self.url, 1261 'URL': self.url,
1224 'UUID': 'ABC', 1262 'UUID': 'ABC',
1225 'Revision': 42, 1263 'Revision': 42,
1226 } 1264 }
1227 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) 1265 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1228 # Checkout or update. 1266 # Checkout or update.
1229 options.path_exists(base_path).AndReturn(True) 1267 gclient.os.path.exists(base_path).AndReturn(True)
1230 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.' 1268 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.'
1231 ).AndReturn(file_info) 1269 ).AndReturn(file_info)
1232 # Cheat a bit here. 1270 # Cheat a bit here.
1233 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) 1271 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info)
1234 additional_args = [] 1272 additional_args = []
1235 if options.manually_grab_svn_rev: 1273 if options.manually_grab_svn_rev:
1236 additional_args = ['--revision', str(file_info['Revision'])] 1274 additional_args = ['--revision', str(file_info['Revision'])]
1237 files_list = [] 1275 files_list = []
1238 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args, 1276 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args,
1239 self.root_dir, files_list) 1277 self.root_dir, files_list)
1240 1278
1241 self.mox.ReplayAll() 1279 self.mox.ReplayAll()
1242 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1280 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1243 relpath=self.relpath) 1281 relpath=self.relpath)
1244 scm.update(options, (), files_list) 1282 scm.update(options, (), files_list)
1245 self.mox.VerifyAll() 1283 self.mox.VerifyAll()
1246 1284
1247 def testUpdateGit(self): 1285 def testUpdateGit(self):
1248 options = self.Options(verbose=True) 1286 options = self.Options(verbose=True)
1249 options.path_exists(os.path.join(self.root_dir, self.relpath, '.git') 1287 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1250 ).AndReturn(True) 1288 ).AndReturn(True)
1251 print("________ found .git directory; skipping %s" % self.relpath) 1289 print("________ found .git directory; skipping %s" % self.relpath)
1252 1290
1253 self.mox.ReplayAll() 1291 self.mox.ReplayAll()
1254 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1292 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
1255 relpath=self.relpath) 1293 relpath=self.relpath)
1256 file_list = [] 1294 file_list = []
1257 scm.update(options, self.args, file_list) 1295 scm.update(options, self.args, file_list)
1258 self.mox.VerifyAll() 1296 self.mox.VerifyAll()
1259 1297
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 self.mox.VerifyAll() 1389 self.mox.VerifyAll()
1352 1390
1353 1391
1354 class SubprocessCallAndCaptureTestCase(BaseTestCase): 1392 class SubprocessCallAndCaptureTestCase(BaseTestCase):
1355 def setUp(self): 1393 def setUp(self):
1356 self.mox = mox.Mox() 1394 self.mox = mox.Mox()
1357 self._sys_stdout = gclient.sys.stdout 1395 self._sys_stdout = gclient.sys.stdout
1358 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) 1396 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout)
1359 self._subprocess_Popen = gclient.subprocess.Popen 1397 self._subprocess_Popen = gclient.subprocess.Popen
1360 gclient.subprocess.Popen = self.mox.CreateMockAnything() 1398 gclient.subprocess.Popen = self.mox.CreateMockAnything()
1399 self._CaptureSVN = gclient.CaptureSVN
1400 gclient.CaptureSVN = self.mox.CreateMockAnything()
1361 1401
1362 def tearDown(self): 1402 def tearDown(self):
1363 gclient.sys.stdout = self._sys_stdout 1403 gclient.sys.stdout = self._sys_stdout
1364 gclient.subprocess.Popen = self._subprocess_Popen 1404 gclient.subprocess.Popen = self._subprocess_Popen
1405 gclient.CaptureSVN = self._CaptureSVN
1365 1406
1366 def testSubprocessCallAndCapture(self): 1407 def testSubprocessCallAndCapture(self):
1367 command = ['boo', 'foo', 'bar'] 1408 command = ['boo', 'foo', 'bar']
1368 in_directory = 'bleh' 1409 in_directory = 'bleh'
1369 fail_status = None 1410 fail_status = None
1370 pattern = 'a(.*)b' 1411 pattern = 'a(.*)b'
1371 test_string = 'ahah\naccb\nallo\naddb\n' 1412 test_string = 'ahah\naccb\nallo\naddb\n'
1372 class Mock(object): 1413 class Mock(object):
1373 stdout = StringIO.StringIO(test_string) 1414 stdout = StringIO.StringIO(test_string)
1374 def wait(self): 1415 def wait(self):
1375 pass 1416 pass
1376 kid = Mock() 1417 kid = Mock()
1377 print("\n________ running 'boo foo bar' in 'bleh'") 1418 print("\n________ running 'boo foo bar' in 'bleh'")
1378 for i in test_string: 1419 for i in test_string:
1379 sys.stdout.write(i) 1420 gclient.sys.stdout.write(i)
1380 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory, 1421 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory,
1381 shell=(sys.platform == 'win32'), 1422 shell=(sys.platform == 'win32'),
1382 stdout=gclient.subprocess.PIPE).AndReturn(kid) 1423 stdout=gclient.subprocess.PIPE).AndReturn(kid)
1383 self.mox.ReplayAll() 1424 self.mox.ReplayAll()
1384 capture_list = [] 1425 capture_list = []
1385 gclient.SubprocessCallAndCapture(command, in_directory, fail_status, 1426 gclient.SubprocessCallAndCapture(command, in_directory, fail_status,
1386 pattern, capture_list) 1427 pattern, capture_list)
1387 self.assertEquals(capture_list, ['cc', 'dd']) 1428 self.assertEquals(capture_list, ['cc', 'dd'])
1388 self.mox.VerifyAll() 1429 self.mox.VerifyAll()
1389 1430
1390 def testCaptureSVNStatus(self): 1431 def testCaptureSVNStatus(self):
1391 x = self 1432 x = self
1392 def CaptureSVNMock(command): 1433 def CaptureSVNMock(command, in_directory=None, print_error=True):
1434 x.assertEquals(in_directory, None)
1435 x.assertEquals(print_error, True)
1393 x.assertEquals(['status', '--xml', '.'], command) 1436 x.assertEquals(['status', '--xml', '.'], command)
1394 return r"""<?xml version="1.0"?> 1437 return r"""<?xml version="1.0"?>
1395 <status> 1438 <status>
1396 <target path="."> 1439 <target path=".">
1397 <entry path="unversionned_file.txt"> 1440 <entry path="unversionned_file.txt">
1398 <wc-status props="none" item="unversioned"></wc-status> 1441 <wc-status props="none" item="unversioned"></wc-status>
1399 </entry> 1442 </entry>
1400 <entry path="build\internal\essential.vsprops"> 1443 <entry path="build\internal\essential.vsprops">
1401 <wc-status props="normal" item="modified" revision="14628"> 1444 <wc-status props="normal" item="modified" revision="14628">
1402 <commit revision="13818"> 1445 <commit revision="13818">
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 ('? ', 'unversionned_file.txt'), 1477 ('? ', 'unversionned_file.txt'),
1435 ('M ', 'build\\internal\\essential.vsprops'), 1478 ('M ', 'build\\internal\\essential.vsprops'),
1436 ('A + ', 'chrome\\app\\d'), 1479 ('A + ', 'chrome\\app\\d'),
1437 ('MM ', 'chrome\\app\\DEPS'), 1480 ('MM ', 'chrome\\app\\DEPS'),
1438 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), 1481 ('C ', 'scripts\\master\\factory\\gclient_factory.py'),
1439 ] 1482 ]
1440 self.assertEquals(sorted(info), sorted(expected)) 1483 self.assertEquals(sorted(info), sorted(expected))
1441 1484
1442 def testCaptureSVNStatusEmpty(self): 1485 def testCaptureSVNStatusEmpty(self):
1443 x = self 1486 x = self
1444 def CaptureSVNMock(command): 1487 def CaptureSVNMock(command, in_directory=None, print_error=True):
1488 x.assertEquals(in_directory, None)
1445 x.assertEquals(['status', '--xml'], command) 1489 x.assertEquals(['status', '--xml'], command)
1446 return r"""<?xml version="1.0"?> 1490 return r"""<?xml version="1.0"?>
1447 <status> 1491 <status>
1448 <target 1492 <target
1449 path="perf"> 1493 path="perf">
1450 </target> 1494 </target>
1451 </status> 1495 </status>
1452 """ 1496 """
1453 gclient.CaptureSVN = CaptureSVNMock 1497 gclient.CaptureSVN = CaptureSVNMock
1454 info = gclient.CaptureSVNStatus(None) 1498 info = gclient.CaptureSVNStatus(None)
1455 self.assertEquals(info, []) 1499 self.assertEquals(info, [])
1456 1500
1457 1501
1458 if __name__ == '__main__': 1502 if __name__ == '__main__':
1459 unittest.main() 1503 unittest.main()
1460 1504
1461 # vim: ts=2:sw=2:tw=80:et: 1505 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698