OLD | NEW |
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 # |
11 # Unless required by applicable law or agreed to in writing, software | 11 # Unless required by applicable law or agreed to in writing, software |
12 # distributed under the License is distributed on an "AS IS" BASIS, | 12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and | 14 # See the License for the specific language governing permissions and |
15 # limitations under the License. | 15 # limitations under the License. |
16 | 16 |
17 """Unit tests for gclient.py.""" | 17 """Unit tests for gclient.py.""" |
18 | 18 |
19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' | 19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' |
20 | 20 |
21 import __builtin__ | 21 import __builtin__ |
22 import copy | 22 import copy |
23 import os | 23 import os |
24 import random | 24 import random |
25 import string | 25 import string |
| 26 import StringIO |
26 import subprocess | 27 import subprocess |
27 import sys | 28 import sys |
28 import unittest | 29 import unittest |
29 | 30 |
30 directory, _file = os.path.split(__file__) | 31 directory, _file = os.path.split(__file__) |
31 if directory: | 32 if directory: |
32 directory += os.sep | 33 directory += os.sep |
33 sys.path.append(os.path.abspath(directory + '../pymox')) | 34 sys.path.append(os.path.abspath(directory + '../pymox')) |
34 | 35 |
35 import gclient | 36 import gclient |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 class BaseTestCase(unittest.TestCase): | 71 class BaseTestCase(unittest.TestCase): |
71 # Like unittest's assertRaises, but checks for Gclient.Error. | 72 # Like unittest's assertRaises, but checks for Gclient.Error. |
72 def assertRaisesError(self, msg, fn, *args, **kwargs): | 73 def assertRaisesError(self, msg, fn, *args, **kwargs): |
73 try: | 74 try: |
74 fn(*args, **kwargs) | 75 fn(*args, **kwargs) |
75 except gclient.Error, e: | 76 except gclient.Error, e: |
76 self.assertEquals(e.args[0], msg) | 77 self.assertEquals(e.args[0], msg) |
77 else: | 78 else: |
78 self.fail('%s not raised' % msg) | 79 self.fail('%s not raised' % msg) |
79 | 80 |
| 81 def compareMembers(self, object, members): |
| 82 """If you add a member, be sure to add the relevant test!""" |
| 83 # Skip over members starting with '_' since they are usually not meant to |
| 84 # be for public use. |
| 85 actual_members = [x for x in sorted(dir(object)) |
| 86 if not x.startswith('_')] |
| 87 expected_members = sorted(members) |
| 88 if actual_members != expected_members: |
| 89 diff = ([i for i in actual_members if i not in expected_members] + |
| 90 [i for i in expected_members if i not in actual_members]) |
| 91 print diff |
| 92 self.assertEqual(actual_members, expected_members) |
| 93 |
| 94 |
| 95 class GClientBaseTestCase(BaseTestCase): |
80 def Options(self, *args, **kwargs): | 96 def Options(self, *args, **kwargs): |
81 return self.OptionsObject(self, *args, **kwargs) | 97 return self.OptionsObject(self, *args, **kwargs) |
82 | 98 |
83 def setUp(self): | 99 def setUp(self): |
84 self.mox = mox.Mox() | 100 self.mox = mox.Mox() |
85 # Mock them to be sure nothing bad happens. | 101 # Mock them to be sure nothing bad happens. |
86 self._CaptureSVN = gclient.CaptureSVN | 102 self._CaptureSVN = gclient.CaptureSVN |
87 gclient.CaptureSVN = self.mox.CreateMockAnything() | 103 gclient.CaptureSVN = self.mox.CreateMockAnything() |
88 self._CaptureSVNInfo = gclient.CaptureSVNInfo | 104 self._CaptureSVNInfo = gclient.CaptureSVNInfo |
89 gclient.CaptureSVNInfo = self.mox.CreateMockAnything() | 105 gclient.CaptureSVNInfo = self.mox.CreateMockAnything() |
90 self._CaptureSVNStatus = gclient.CaptureSVNStatus | 106 self._CaptureSVNStatus = gclient.CaptureSVNStatus |
91 gclient.CaptureSVNStatus = self.mox.CreateMockAnything() | 107 gclient.CaptureSVNStatus = self.mox.CreateMockAnything() |
92 self._FileRead = gclient.FileRead | 108 self._FileRead = gclient.FileRead |
93 gclient.FileRead = self.mox.CreateMockAnything() | 109 gclient.FileRead = self.mox.CreateMockAnything() |
94 self._FileWrite = gclient.FileWrite | 110 self._FileWrite = gclient.FileWrite |
95 gclient.FileWrite = self.mox.CreateMockAnything() | 111 gclient.FileWrite = self.mox.CreateMockAnything() |
96 self._RemoveDirectory = gclient.RemoveDirectory | 112 self._RemoveDirectory = gclient.RemoveDirectory |
97 gclient.RemoveDirectory = self.mox.CreateMockAnything() | 113 gclient.RemoveDirectory = self.mox.CreateMockAnything() |
98 self._RunSVN = gclient.RunSVN | 114 self._RunSVN = gclient.RunSVN |
99 gclient.RunSVN = self.mox.CreateMockAnything() | 115 gclient.RunSVN = self.mox.CreateMockAnything() |
100 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList | 116 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList |
101 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything() | 117 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything() |
102 # Doesn't seem to work very well: | 118 self._sys_stdout = gclient.sys.stdout |
103 self._os = gclient.os | 119 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) |
104 gclient.os = self.mox.CreateMock(os) | |
105 self._sys = gclient.sys | |
106 gclient.sys = self.mox.CreateMock(sys) | |
107 self._subprocess = gclient.subprocess | 120 self._subprocess = gclient.subprocess |
108 gclient.subprocess = self.mox.CreateMock(subprocess) | 121 gclient.subprocess = self.mox.CreateMock(self._subprocess) |
109 | 122 |
110 def tearDown(self): | 123 def tearDown(self): |
111 gclient.CaptureSVN = self._CaptureSVN | 124 gclient.CaptureSVN = self._CaptureSVN |
112 gclient.CaptureSVNInfo = self._CaptureSVNInfo | 125 gclient.CaptureSVNInfo = self._CaptureSVNInfo |
113 gclient.CaptureSVNStatus = self._CaptureSVNStatus | 126 gclient.CaptureSVNStatus = self._CaptureSVNStatus |
114 gclient.FileRead = self._FileRead | 127 gclient.FileRead = self._FileRead |
115 gclient.FileWrite = self._FileWrite | 128 gclient.FileWrite = self._FileWrite |
116 gclient.RemoveDirectory = self._RemoveDirectory | 129 gclient.RemoveDirectory = self._RemoveDirectory |
117 gclient.RunSVN = self._RunSVN | 130 gclient.RunSVN = self._RunSVN |
118 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList | 131 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList |
119 # Doesn't seem to work very well: | 132 gclient.sys.stdout = self._sys_stdout |
120 gclient.os = self._os | |
121 gclient.sys = self._sys | |
122 gclient.subprocess = self._subprocess | 133 gclient.subprocess = self._subprocess |
123 | 134 |
124 | 135 |
125 class GclientTestCase(BaseTestCase): | 136 class GclientTestCase(GClientBaseTestCase): |
126 class OptionsObject(object): | 137 class OptionsObject(object): |
127 def __init__(self, test_case, verbose=False, spec=None, | 138 def __init__(self, test_case, verbose=False, spec=None, |
128 config_filename='a_file_name', | 139 config_filename='a_file_name', |
129 entries_filename='a_entry_file_name', | 140 entries_filename='a_entry_file_name', |
130 deps_file='a_deps_file_name', force=False): | 141 deps_file='a_deps_file_name', force=False): |
131 self.verbose = verbose | 142 self.verbose = verbose |
132 self.spec = spec | 143 self.spec = spec |
133 self.config_filename = config_filename | 144 self.config_filename = config_filename |
134 self.entries_filename = entries_filename | 145 self.entries_filename = entries_filename |
135 self.deps_file = deps_file | 146 self.deps_file = deps_file |
136 self.force = force | 147 self.force = force |
137 self.revisions = [] | 148 self.revisions = [] |
138 self.manually_grab_svn_rev = True | 149 self.manually_grab_svn_rev = True |
139 self.deps_os = None | 150 self.deps_os = None |
140 self.head = False | 151 self.head = False |
141 | 152 |
142 # Mox | 153 # Mox |
143 self.stdout = test_case.stdout | |
144 self.path_exists = test_case.path_exists | 154 self.path_exists = test_case.path_exists |
145 self.platform = test_case.platform | 155 self.platform = test_case.platform |
146 self.gclient = test_case.gclient | 156 self.gclient = test_case.gclient |
147 self.scm_wrapper = test_case.scm_wrapper | 157 self.scm_wrapper = test_case.scm_wrapper |
148 | 158 |
149 def setUp(self): | 159 def setUp(self): |
150 BaseTestCase.setUp(self) | 160 GClientBaseTestCase.setUp(self) |
151 self.stdout = self.mox.CreateMock(sys.stdout) | |
152 #self.subprocess = self.mox.CreateMock(subprocess) | 161 #self.subprocess = self.mox.CreateMock(subprocess) |
153 # Stub os.path.exists. | 162 # Stub os.path.exists. |
154 self.path_exists = self.mox.CreateMockAnything() | 163 self.path_exists = self.mox.CreateMockAnything() |
155 self.sys = self.mox.CreateMock(sys) | |
156 self.platform = 'darwin' | 164 self.platform = 'darwin' |
157 | 165 |
158 self.gclient = self.mox.CreateMock(gclient.GClient) | 166 self.gclient = self.mox.CreateMock(gclient.GClient) |
159 self.scm_wrapper = self.mox.CreateMock(gclient.SCMWrapper) | 167 self.scm_wrapper = self.mox.CreateMock(gclient.SCMWrapper) |
160 | 168 |
161 self.args = Args() | 169 self.args = Args() |
162 self.root_dir = Dir() | 170 self.root_dir = Dir() |
163 self.url = Url() | 171 self.url = Url() |
164 | 172 |
165 | 173 |
166 class GClientCommandsTestCase(BaseTestCase): | 174 class GClientCommandsTestCase(GClientBaseTestCase): |
167 def testCommands(self): | 175 def testCommands(self): |
168 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, | 176 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, |
169 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate, | 177 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate, |
170 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo] | 178 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo] |
171 for (k,v) in gclient.gclient_command_map.iteritems(): | 179 for (k,v) in gclient.gclient_command_map.iteritems(): |
172 # If it fails, you need to add a test case for the new command. | 180 # If it fails, you need to add a test case for the new command. |
173 self.assert_(v in known_commands) | 181 self.assert_(v in known_commands) |
174 self.mox.ReplayAll() | 182 self.mox.ReplayAll() |
175 self.mox.VerifyAll() | 183 self.mox.VerifyAll() |
176 | 184 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 options.gclient.SaveConfig() | 225 options.gclient.SaveConfig() |
218 | 226 |
219 self.mox.ReplayAll() | 227 self.mox.ReplayAll() |
220 gclient.DoConfig(options, | 228 gclient.DoConfig(options, |
221 ('http://svn/url/the_name', 'other', 'args', 'ignored')) | 229 ('http://svn/url/the_name', 'other', 'args', 'ignored')) |
222 self.mox.VerifyAll() | 230 self.mox.VerifyAll() |
223 | 231 |
224 | 232 |
225 class TestDoHelp(GclientTestCase): | 233 class TestDoHelp(GclientTestCase): |
226 def testGetUsage(self): | 234 def testGetUsage(self): |
| 235 print(gclient.COMMAND_USAGE_TEXT['config']) |
| 236 self.mox.ReplayAll() |
227 options = self.Options() | 237 options = self.Options() |
228 print >> options.stdout, gclient.COMMAND_USAGE_TEXT['config'] | |
229 | |
230 self.mox.ReplayAll() | |
231 gclient.DoHelp(options, ('config',)) | 238 gclient.DoHelp(options, ('config',)) |
232 self.mox.VerifyAll() | 239 self.mox.VerifyAll() |
233 | 240 |
234 def testTooManyArgs(self): | 241 def testTooManyArgs(self): |
| 242 self.mox.ReplayAll() |
235 options = self.Options() | 243 options = self.Options() |
236 self.mox.ReplayAll() | |
237 self.assertRaisesError("unknown subcommand 'config'; see 'gclient help'", | 244 self.assertRaisesError("unknown subcommand 'config'; see 'gclient help'", |
238 gclient.DoHelp, options, ('config', | 245 gclient.DoHelp, options, ('config', |
239 'another argument')) | 246 'another argument')) |
240 self.mox.VerifyAll() | 247 self.mox.VerifyAll() |
241 | 248 |
242 def testUnknownSubcommand(self): | 249 def testUnknownSubcommand(self): |
| 250 self.mox.ReplayAll() |
243 options = self.Options() | 251 options = self.Options() |
244 self.mox.ReplayAll() | |
245 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'", | 252 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'", |
246 gclient.DoHelp, options, ('xyzzy',)) | 253 gclient.DoHelp, options, ('xyzzy',)) |
247 self.mox.VerifyAll() | 254 self.mox.VerifyAll() |
248 | 255 |
249 | 256 |
250 class GenericCommandTestCase(GclientTestCase): | 257 class GenericCommandTestCase(GclientTestCase): |
251 def ReturnValue(self, command, function, return_value): | 258 def ReturnValue(self, command, function, return_value): |
252 options = self.Options() | 259 options = self.Options() |
253 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) | 260 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) |
254 self.gclient.RunOnDeps(command, self.args).AndReturn(return_value) | 261 self.gclient.RunOnDeps(command, self.args).AndReturn(return_value) |
(...skipping 11 matching lines...) Expand all Loading... |
266 self.assertRaisesError( | 273 self.assertRaisesError( |
267 "client not configured; see 'gclient config'", | 274 "client not configured; see 'gclient config'", |
268 function, options, self.args) | 275 function, options, self.args) |
269 self.mox.VerifyAll() | 276 self.mox.VerifyAll() |
270 | 277 |
271 def Verbose(self, command, function): | 278 def Verbose(self, command, function): |
272 options = self.Options(verbose=True) | 279 options = self.Options(verbose=True) |
273 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) | 280 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) |
274 text = "# Dummy content\nclient = 'my client'" | 281 text = "# Dummy content\nclient = 'my client'" |
275 self.gclient.ConfigContent().AndReturn(text) | 282 self.gclient.ConfigContent().AndReturn(text) |
276 print >>self.stdout, text | 283 print(text) |
277 self.gclient.RunOnDeps(command, self.args).AndReturn(0) | 284 self.gclient.RunOnDeps(command, self.args).AndReturn(0) |
278 | 285 |
279 self.mox.ReplayAll() | 286 self.mox.ReplayAll() |
280 result = function(options, self.args) | 287 result = function(options, self.args) |
281 self.assertEquals(result, 0) | 288 self.assertEquals(result, 0) |
282 self.mox.VerifyAll() | 289 self.mox.VerifyAll() |
283 | 290 |
284 class TestDoCleanup(GenericCommandTestCase): | 291 class TestDoCleanup(GenericCommandTestCase): |
285 def testGoodClient(self): | 292 def testGoodClient(self): |
286 self.ReturnValue('cleanup', gclient.DoCleanup, 0) | 293 self.ReturnValue('cleanup', gclient.DoCleanup, 0) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 result = function(options, self.args) | 331 result = function(options, self.args) |
325 self.assertEquals(result, return_value) | 332 self.assertEquals(result, return_value) |
326 self.mox.VerifyAll() | 333 self.mox.VerifyAll() |
327 | 334 |
328 def Verbose(self, command, function): | 335 def Verbose(self, command, function): |
329 options = self.Options(verbose=True) | 336 options = self.Options(verbose=True) |
330 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) | 337 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) |
331 self.gclient.GetVar("solutions") | 338 self.gclient.GetVar("solutions") |
332 text = "# Dummy content\nclient = 'my client'" | 339 text = "# Dummy content\nclient = 'my client'" |
333 self.gclient.ConfigContent().AndReturn(text) | 340 self.gclient.ConfigContent().AndReturn(text) |
334 print >>self.stdout, text | 341 print(text) |
335 self.gclient.RunOnDeps(command, self.args).AndReturn(0) | 342 self.gclient.RunOnDeps(command, self.args).AndReturn(0) |
336 | 343 |
337 self.mox.ReplayAll() | 344 self.mox.ReplayAll() |
338 result = function(options, self.args) | 345 result = function(options, self.args) |
339 self.assertEquals(result, 0) | 346 self.assertEquals(result, 0) |
340 self.mox.VerifyAll() | 347 self.mox.VerifyAll() |
341 | 348 |
342 def Options(self, verbose=False, *args, **kwargs): | 349 def Options(self, verbose=False, *args, **kwargs): |
343 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) | 350 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) |
344 | 351 |
(...skipping 25 matching lines...) Expand all Loading... |
370 def testBasic(self): | 377 def testBasic(self): |
371 self.ReturnValue('revert', gclient.DoRevert, 0) | 378 self.ReturnValue('revert', gclient.DoRevert, 0) |
372 def testError(self): | 379 def testError(self): |
373 self.ReturnValue('revert', gclient.DoRevert, 42) | 380 self.ReturnValue('revert', gclient.DoRevert, 42) |
374 def testBadClient(self): | 381 def testBadClient(self): |
375 self.BadClient(gclient.DoRevert) | 382 self.BadClient(gclient.DoRevert) |
376 | 383 |
377 | 384 |
378 class GClientClassTestCase(GclientTestCase): | 385 class GClientClassTestCase(GclientTestCase): |
379 def testDir(self): | 386 def testDir(self): |
380 members = ['ConfigContent', 'FromImpl', '_VarImpl', '_ParseAllDeps', | 387 members = [ |
381 '_ParseSolutionDeps', 'GetVar', '_LoadConfig', 'LoadCurrentConfig', | 388 'ConfigContent', 'FromImpl', 'GetVar', 'LoadCurrentConfig', |
382 '_ReadEntries', '_RunHookAction', '_RunHooks', 'RunOnDeps', 'SaveConfig', | 389 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', |
383 '_SaveEntries', 'SetConfig', 'SetDefaultConfig', 'supported_commands', | 390 'supported_commands', 'PrintRevInfo', |
384 'PrintRevInfo'] | 391 ] |
385 | 392 |
386 # If you add a member, be sure to add the relevant test! | 393 # If you add a member, be sure to add the relevant test! |
387 actual_members = [x for x in sorted(dir(gclient.GClient)) | 394 self.compareMembers(gclient.GClient('root_dir', 'options'), members) |
388 if not x.startswith('__')] | |
389 self.assertEqual(actual_members, sorted(members)) | |
390 self.mox.ReplayAll() | |
391 self.mox.VerifyAll() | |
392 | 395 |
393 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): | 396 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): |
394 options = self.Options() | 397 options = self.Options() |
395 text = "# Dummy content\nclient = 'my client'" | 398 text = "# Dummy content\nclient = 'my client'" |
396 gclient.FileWrite(os.path.join(self.root_dir, options.config_filename), | 399 gclient.FileWrite(os.path.join(self.root_dir, options.config_filename), |
397 text) | 400 text) |
398 | 401 |
399 self.mox.ReplayAll() | 402 self.mox.ReplayAll() |
400 client = gclient.GClient(self.root_dir, options) | 403 client = gclient.GClient(self.root_dir, options) |
401 client.SetConfig(text) | 404 client.SetConfig(text) |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 727 |
725 self.mox.ReplayAll() | 728 self.mox.ReplayAll() |
726 client = gclient.GClient(self.root_dir, options) | 729 client = gclient.GClient(self.root_dir, options) |
727 client.SetConfig(gclient_config) | 730 client.SetConfig(gclient_config) |
728 client.RunOnDeps('update', self.args) | 731 client.RunOnDeps('update', self.args) |
729 self.mox.VerifyAll() | 732 self.mox.VerifyAll() |
730 | 733 |
731 def testRunOnDepsRevisions(self): | 734 def testRunOnDepsRevisions(self): |
732 def OptIsRev(options, rev): | 735 def OptIsRev(options, rev): |
733 if not options.revision == str(rev): | 736 if not options.revision == str(rev): |
734 print "options.revision = %s" % options.revision | 737 print("options.revision = %s" % options.revision) |
735 return options.revision == str(rev) | 738 return options.revision == str(rev) |
736 def OptIsRevNone(options): | 739 def OptIsRevNone(options): |
737 if options.revision: | 740 if options.revision: |
738 print "options.revision = %s" % options.revision | 741 print("options.revision = %s" % options.revision) |
739 return options.revision == None | 742 return options.revision == None |
740 def OptIsRev42(options): | 743 def OptIsRev42(options): |
741 return OptIsRev(options, 42) | 744 return OptIsRev(options, 42) |
742 def OptIsRev123(options): | 745 def OptIsRev123(options): |
743 return OptIsRev(options, 123) | 746 return OptIsRev(options, 123) |
744 def OptIsRev333(options): | 747 def OptIsRev333(options): |
745 return OptIsRev(options, 333) | 748 return OptIsRev(options, 333) |
746 | 749 |
747 # Fake .gclient file. | 750 # Fake .gclient file. |
748 gclient_config = """solutions = [ { | 751 gclient_config = """solutions = [ { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 def test_LoadConfig(self): | 1054 def test_LoadConfig(self): |
1052 pass | 1055 pass |
1053 def test_ReadEntries(self): | 1056 def test_ReadEntries(self): |
1054 pass | 1057 pass |
1055 def test_SaveEntries(self): | 1058 def test_SaveEntries(self): |
1056 pass | 1059 pass |
1057 def test_VarImpl(self): | 1060 def test_VarImpl(self): |
1058 pass | 1061 pass |
1059 | 1062 |
1060 | 1063 |
1061 class SCMWrapperTestCase(BaseTestCase): | 1064 class SCMWrapperTestCase(GClientBaseTestCase): |
1062 class OptionsObject(object): | 1065 class OptionsObject(object): |
1063 def __init__(self, test_case, verbose=False, revision=None): | 1066 def __init__(self, test_case, verbose=False, revision=None): |
1064 self.verbose = verbose | 1067 self.verbose = verbose |
1065 self.revision = revision | 1068 self.revision = revision |
1066 self.manually_grab_svn_rev = True | 1069 self.manually_grab_svn_rev = True |
1067 self.deps_os = None | 1070 self.deps_os = None |
1068 self.force = False | 1071 self.force = False |
1069 | 1072 |
1070 # Mox | 1073 # Mox |
1071 self.stdout = test_case.stdout | |
1072 self.path_exists = test_case.path_exists | 1074 self.path_exists = test_case.path_exists |
1073 | 1075 |
1074 def setUp(self): | 1076 def setUp(self): |
1075 BaseTestCase.setUp(self) | 1077 GClientBaseTestCase.setUp(self) |
1076 self.root_dir = Dir() | 1078 self.root_dir = Dir() |
1077 self.args = Args() | 1079 self.args = Args() |
1078 self.url = Url() | 1080 self.url = Url() |
1079 self.relpath = 'asf' | 1081 self.relpath = 'asf' |
1080 self.stdout = self.mox.CreateMock(sys.stdout) | |
1081 # Stub os.path.exists. | 1082 # Stub os.path.exists. |
1082 self.path_exists = self.mox.CreateMockAnything() | 1083 self.path_exists = self.mox.CreateMockAnything() |
1083 | 1084 |
1084 def testDir(self): | 1085 def testDir(self): |
1085 members = ['FullUrlForRelativeUrl', 'RunCommand', | 1086 members = [ |
1086 'cleanup', 'diff', 'revert', 'status', 'update'] | 1087 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath', |
| 1088 'revert', 'scm_name', 'status', 'update', 'url', |
| 1089 ] |
1087 | 1090 |
1088 # If you add a member, be sure to add the relevant test! | 1091 # If you add a member, be sure to add the relevant test! |
1089 actual_members = [x for x in sorted(dir(gclient.SCMWrapper)) | 1092 self.compareMembers(gclient.SCMWrapper(), members) |
1090 if not x.startswith('__')] | |
1091 self.assertEqual(actual_members, sorted(members)) | |
1092 self.mox.ReplayAll() | |
1093 self.mox.VerifyAll() | |
1094 | 1093 |
1095 def testFullUrlForRelativeUrl(self): | 1094 def testFullUrlForRelativeUrl(self): |
1096 self.url = 'svn://a/b/c/d' | 1095 self.url = 'svn://a/b/c/d' |
1097 | 1096 |
1098 self.mox.ReplayAll() | 1097 self.mox.ReplayAll() |
1099 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1098 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1100 relpath=self.relpath) | 1099 relpath=self.relpath) |
1101 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') | 1100 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') |
1102 self.mox.VerifyAll() | 1101 self.mox.VerifyAll() |
1103 | 1102 |
(...skipping 14 matching lines...) Expand all Loading... |
1118 # TODO(maruel): if ever used. | 1117 # TODO(maruel): if ever used. |
1119 pass | 1118 pass |
1120 | 1119 |
1121 def testRevertMissing(self): | 1120 def testRevertMissing(self): |
1122 options = self.Options(verbose=True) | 1121 options = self.Options(verbose=True) |
1123 gclient.os.path.isdir = self.mox.CreateMockAnything() | 1122 gclient.os.path.isdir = self.mox.CreateMockAnything() |
1124 base_path = os.path.join(self.root_dir, self.relpath) | 1123 base_path = os.path.join(self.root_dir, self.relpath) |
1125 gclient.os.path.isdir(base_path).AndReturn(False) | 1124 gclient.os.path.isdir(base_path).AndReturn(False) |
1126 # It'll to a checkout instead. | 1125 # It'll to a checkout instead. |
1127 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) | 1126 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) |
1128 print >>options.stdout, ("\n_____ %s is missing, synching instead" % | 1127 print("\n_____ %s is missing, synching instead" % self.relpath) |
1129 self.relpath) | |
1130 # Checkout. | 1128 # Checkout. |
1131 options.path_exists(base_path).AndReturn(False) | 1129 options.path_exists(base_path).AndReturn(False) |
1132 files_list = self.mox.CreateMockAnything() | 1130 files_list = self.mox.CreateMockAnything() |
1133 gclient.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], | 1131 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], |
1134 self.root_dir, files_list) | 1132 self.root_dir, files_list) |
1135 | 1133 |
1136 self.mox.ReplayAll() | 1134 self.mox.ReplayAll() |
1137 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1135 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1138 relpath=self.relpath) | 1136 relpath=self.relpath) |
1139 scm.revert(options, self.args, files_list) | 1137 scm.revert(options, self.args, files_list) |
1140 self.mox.VerifyAll() | 1138 self.mox.VerifyAll() |
1141 gclient.os.path.isdir = os.path.isdir | 1139 gclient.os.path.isdir = os.path.isdir |
1142 | 1140 |
1143 def testRevertNone(self): | 1141 def testRevertNone(self): |
1144 options = self.Options(verbose=True) | 1142 options = self.Options(verbose=True) |
1145 base_path = os.path.join(self.root_dir, self.relpath) | 1143 base_path = os.path.join(self.root_dir, self.relpath) |
1146 gclient.os.path.isdir = self.mox.CreateMockAnything() | 1144 gclient.os.path.isdir = self.mox.CreateMockAnything() |
1147 gclient.os.path.isdir(base_path).AndReturn(True) | 1145 gclient.os.path.isdir(base_path).AndReturn(True) |
1148 gclient.CaptureSVNStatus(options, base_path).AndReturn([]) | 1146 gclient.CaptureSVNStatus(base_path).AndReturn([]) |
1149 | 1147 |
1150 self.mox.ReplayAll() | 1148 self.mox.ReplayAll() |
1151 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1149 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1152 relpath=self.relpath) | 1150 relpath=self.relpath) |
1153 file_list = [] | 1151 file_list = [] |
1154 scm.revert(options, self.args, file_list) | 1152 scm.revert(options, self.args, file_list) |
1155 self.mox.VerifyAll() | 1153 self.mox.VerifyAll() |
1156 gclient.os.path.isdir = os.path.isdir | 1154 gclient.os.path.isdir = os.path.isdir |
1157 | 1155 |
1158 def testRevert2Files(self): | 1156 def testRevert2Files(self): |
1159 options = self.Options(verbose=True) | 1157 options = self.Options(verbose=True) |
1160 base_path = os.path.join(self.root_dir, self.relpath) | 1158 base_path = os.path.join(self.root_dir, self.relpath) |
1161 gclient.os.path.isdir = self.mox.CreateMockAnything() | 1159 gclient.os.path.isdir = self.mox.CreateMockAnything() |
1162 gclient.os.path.isdir(base_path).AndReturn(True) | 1160 gclient.os.path.isdir(base_path).AndReturn(True) |
1163 items = [ | 1161 items = [ |
1164 gclient.FileStatus('a', 'M', ' ', ' ', ' '), | 1162 gclient.FileStatus('a', 'M', ' ', ' ', ' '), |
1165 gclient.FileStatus('b', 'A', ' ', ' ', ' '), | 1163 gclient.FileStatus('b', 'A', ' ', ' ', ' '), |
1166 ] | 1164 ] |
1167 gclient.CaptureSVNStatus(options, base_path).AndReturn(items) | 1165 gclient.CaptureSVNStatus(base_path).AndReturn(items) |
1168 | 1166 |
1169 print >>options.stdout, os.path.join(base_path, 'a') | 1167 print(os.path.join(base_path, 'a')) |
1170 print >>options.stdout, os.path.join(base_path, 'b') | 1168 print(os.path.join(base_path, 'b')) |
1171 gclient.RunSVN(options, ['revert', 'a', 'b'], base_path) | 1169 gclient.RunSVN(['revert', 'a', 'b'], base_path) |
1172 | 1170 |
1173 self.mox.ReplayAll() | 1171 self.mox.ReplayAll() |
1174 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1172 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1175 relpath=self.relpath) | 1173 relpath=self.relpath) |
1176 file_list = [] | 1174 file_list = [] |
1177 scm.revert(options, self.args, file_list) | 1175 scm.revert(options, self.args, file_list) |
1178 self.mox.VerifyAll() | 1176 self.mox.VerifyAll() |
1179 gclient.os.path.isdir = os.path.isdir | 1177 gclient.os.path.isdir = os.path.isdir |
1180 | 1178 |
1181 def testStatus(self): | 1179 def testStatus(self): |
1182 options = self.Options(verbose=True) | 1180 options = self.Options(verbose=True) |
1183 base_path = os.path.join(self.root_dir, self.relpath) | 1181 base_path = os.path.join(self.root_dir, self.relpath) |
1184 gclient.os.path.isdir = self.mox.CreateMockAnything() | 1182 gclient.os.path.isdir = self.mox.CreateMockAnything() |
1185 gclient.os.path.isdir(base_path).AndReturn(True) | 1183 gclient.os.path.isdir(base_path).AndReturn(True) |
1186 gclient.RunSVNAndGetFileList(options, ['status'] + self.args, base_path, | 1184 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path, |
1187 []).AndReturn(None) | 1185 []).AndReturn(None) |
1188 | 1186 |
1189 self.mox.ReplayAll() | 1187 self.mox.ReplayAll() |
1190 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1188 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1191 relpath=self.relpath) | 1189 relpath=self.relpath) |
1192 file_list = [] | 1190 file_list = [] |
1193 self.assertEqual(scm.status(options, self.args, file_list), None) | 1191 self.assertEqual(scm.status(options, self.args, file_list), None) |
1194 self.mox.VerifyAll() | 1192 self.mox.VerifyAll() |
1195 | 1193 |
1196 | 1194 |
1197 # TODO(maruel): TEST REVISIONS!!! | 1195 # TODO(maruel): TEST REVISIONS!!! |
1198 # TODO(maruel): TEST RELOCATE!!! | 1196 # TODO(maruel): TEST RELOCATE!!! |
1199 def testUpdateCheckout(self): | 1197 def testUpdateCheckout(self): |
1200 options = self.Options(verbose=True) | 1198 options = self.Options(verbose=True) |
1201 base_path = os.path.join(self.root_dir, self.relpath) | 1199 base_path = os.path.join(self.root_dir, self.relpath) |
1202 file_info = gclient.PrintableObject() | 1200 file_info = gclient.PrintableObject() |
1203 file_info.root = 'blah' | 1201 file_info.root = 'blah' |
1204 file_info.url = self.url | 1202 file_info.url = self.url |
1205 file_info.uuid = 'ABC' | 1203 file_info.uuid = 'ABC' |
1206 file_info.revision = 42 | 1204 file_info.revision = 42 |
1207 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) | 1205 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) |
1208 # Checkout. | 1206 # Checkout. |
1209 options.path_exists(base_path).AndReturn(False) | 1207 options.path_exists(base_path).AndReturn(False) |
1210 files_list = self.mox.CreateMockAnything() | 1208 files_list = self.mox.CreateMockAnything() |
1211 gclient.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], | 1209 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], |
1212 self.root_dir, files_list) | 1210 self.root_dir, files_list) |
1213 self.mox.ReplayAll() | 1211 self.mox.ReplayAll() |
1214 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1212 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1215 relpath=self.relpath) | 1213 relpath=self.relpath) |
1216 scm.update(options, (), files_list) | 1214 scm.update(options, (), files_list) |
1217 self.mox.VerifyAll() | 1215 self.mox.VerifyAll() |
1218 | 1216 |
1219 def testUpdateUpdate(self): | 1217 def testUpdateUpdate(self): |
1220 options = self.Options(verbose=True) | 1218 options = self.Options(verbose=True) |
1221 base_path = os.path.join(self.root_dir, self.relpath) | 1219 base_path = os.path.join(self.root_dir, self.relpath) |
1222 options.force = True | 1220 options.force = True |
1223 file_info = { | 1221 file_info = { |
1224 'Repository Root': 'blah', | 1222 'Repository Root': 'blah', |
1225 'URL': self.url, | 1223 'URL': self.url, |
1226 'UUID': 'ABC', | 1224 'UUID': 'ABC', |
1227 'Revision': 42, | 1225 'Revision': 42, |
1228 } | 1226 } |
1229 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) | 1227 options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) |
1230 # Checkout or update. | 1228 # Checkout or update. |
1231 options.path_exists(base_path).AndReturn(True) | 1229 options.path_exists(base_path).AndReturn(True) |
1232 gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.' | 1230 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.' |
1233 ).AndReturn(file_info) | 1231 ).AndReturn(file_info) |
1234 # Cheat a bit here. | 1232 # Cheat a bit here. |
1235 gclient.CaptureSVNInfo(options, file_info['URL'], '.').AndReturn(file_info) | 1233 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) |
1236 additional_args = [] | 1234 additional_args = [] |
1237 if options.manually_grab_svn_rev: | 1235 if options.manually_grab_svn_rev: |
1238 additional_args = ['--revision', str(file_info['Revision'])] | 1236 additional_args = ['--revision', str(file_info['Revision'])] |
1239 files_list = [] | 1237 files_list = [] |
1240 gclient.RunSVNAndGetFileList(options, ['update', base_path] + additional_arg
s, | 1238 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args, |
1241 self.root_dir, files_list) | 1239 self.root_dir, files_list) |
1242 | 1240 |
1243 self.mox.ReplayAll() | 1241 self.mox.ReplayAll() |
1244 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1242 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1245 relpath=self.relpath) | 1243 relpath=self.relpath) |
1246 scm.update(options, (), files_list) | 1244 scm.update(options, (), files_list) |
1247 self.mox.VerifyAll() | 1245 self.mox.VerifyAll() |
1248 | 1246 |
1249 def testUpdateGit(self): | 1247 def testUpdateGit(self): |
1250 options = self.Options(verbose=True) | 1248 options = self.Options(verbose=True) |
1251 options.path_exists(os.path.join(self.root_dir, self.relpath, '.git') | 1249 options.path_exists(os.path.join(self.root_dir, self.relpath, '.git') |
1252 ).AndReturn(True) | 1250 ).AndReturn(True) |
1253 print >> options.stdout, ( | 1251 print("________ found .git directory; skipping %s" % self.relpath) |
1254 "________ found .git directory; skipping %s" % self.relpath) | |
1255 | 1252 |
1256 self.mox.ReplayAll() | 1253 self.mox.ReplayAll() |
1257 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, | 1254 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, |
1258 relpath=self.relpath) | 1255 relpath=self.relpath) |
1259 file_list = [] | 1256 file_list = [] |
1260 scm.update(options, self.args, file_list) | 1257 scm.update(options, self.args, file_list) |
1261 self.mox.VerifyAll() | 1258 self.mox.VerifyAll() |
1262 | 1259 |
1263 def testGetSVNFileInfo(self): | 1260 def testGetSVNFileInfo(self): |
1264 xml_text = r"""<?xml version="1.0"?> | 1261 xml_text = r"""<?xml version="1.0"?> |
1265 <info> | 1262 <info> |
1266 <entry kind="file" path="%s" revision="14628"> | 1263 <entry kind="file" path="%s" revision="14628"> |
1267 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 1264 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
1268 <repository><root>http://src.chromium.org/svn</root></repository> | 1265 <repository><root>http://src.chromium.org/svn</root></repository> |
1269 <wc-info> | 1266 <wc-info> |
1270 <schedule>add</schedule> | 1267 <schedule>add</schedule> |
1271 <depth>infinity</depth> | 1268 <depth>infinity</depth> |
1272 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> | 1269 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> |
1273 <copy-from-rev>14628</copy-from-rev> | 1270 <copy-from-rev>14628</copy-from-rev> |
1274 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> | 1271 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
1275 </wc-info> | 1272 </wc-info> |
1276 </entry> | 1273 </entry> |
1277 </info> | 1274 </info> |
1278 """ % self.url | 1275 """ % self.url |
1279 options = self.Options(verbose=True) | 1276 gclient.CaptureSVN(['info', '--xml', self.url], '.').AndReturn(xml_text) |
1280 gclient.CaptureSVN(options, ['info', '--xml', self.url], | |
1281 '.').AndReturn(xml_text) | |
1282 expected = { | 1277 expected = { |
1283 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', | 1278 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
1284 'UUID': None, | 1279 'UUID': None, |
1285 'Repository Root': 'http://src.chromium.org/svn', | 1280 'Repository Root': 'http://src.chromium.org/svn', |
1286 'Schedule': 'add', | 1281 'Schedule': 'add', |
1287 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS'
, | 1282 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS'
, |
1288 'Copied From Rev': '14628', | 1283 'Copied From Rev': '14628', |
1289 'Path': self.url, | 1284 'Path': self.url, |
1290 'Revision': 14628, | 1285 'Revision': 14628, |
1291 'Node Kind': 'file', | 1286 'Node Kind': 'file', |
1292 } | 1287 } |
1293 self.mox.ReplayAll() | 1288 self.mox.ReplayAll() |
1294 file_info = self._CaptureSVNInfo(options, self.url, '.') | 1289 file_info = self._CaptureSVNInfo(self.url, '.') |
1295 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) | 1290 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) |
1296 self.mox.VerifyAll() | 1291 self.mox.VerifyAll() |
1297 | 1292 |
1298 def testCaptureSvnInfo(self): | 1293 def testCaptureSvnInfo(self): |
1299 xml_text = """<?xml version="1.0"?> | 1294 xml_text = """<?xml version="1.0"?> |
1300 <info> | 1295 <info> |
1301 <entry | 1296 <entry |
1302 kind="dir" | 1297 kind="dir" |
1303 path="." | 1298 path="." |
1304 revision="35"> | 1299 revision="35"> |
1305 <url>%s</url> | 1300 <url>%s</url> |
1306 <repository> | 1301 <repository> |
1307 <root>%s</root> | 1302 <root>%s</root> |
1308 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> | 1303 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
1309 </repository> | 1304 </repository> |
1310 <wc-info> | 1305 <wc-info> |
1311 <schedule>normal</schedule> | 1306 <schedule>normal</schedule> |
1312 <depth>infinity</depth> | 1307 <depth>infinity</depth> |
1313 </wc-info> | 1308 </wc-info> |
1314 <commit | 1309 <commit |
1315 revision="35"> | 1310 revision="35"> |
1316 <author>maruel</author> | 1311 <author>maruel</author> |
1317 <date>2008-12-04T20:12:19.685120Z</date> | 1312 <date>2008-12-04T20:12:19.685120Z</date> |
1318 </commit> | 1313 </commit> |
1319 </entry> | 1314 </entry> |
1320 </info> | 1315 </info> |
1321 """ % (self.url, self.root_dir) | 1316 """ % (self.url, self.root_dir) |
1322 options = self.Options(verbose=True) | 1317 gclient.CaptureSVN(['info', '--xml', self.url], '.').AndReturn(xml_text) |
1323 gclient.CaptureSVN(options, ['info', '--xml', self.url], | |
1324 '.').AndReturn(xml_text) | |
1325 self.mox.ReplayAll() | 1318 self.mox.ReplayAll() |
1326 file_info = self._CaptureSVNInfo(options, self.url, '.') | 1319 file_info = self._CaptureSVNInfo(self.url, '.') |
1327 expected = { | 1320 expected = { |
1328 'URL': self.url, | 1321 'URL': self.url, |
1329 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', | 1322 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', |
1330 'Revision': 35, | 1323 'Revision': 35, |
1331 'Repository Root': self.root_dir, | 1324 'Repository Root': self.root_dir, |
1332 'Schedule': 'normal', | 1325 'Schedule': 'normal', |
1333 'Copied From URL': None, | 1326 'Copied From URL': None, |
1334 'Copied From Rev': None, | 1327 'Copied From Rev': None, |
1335 'Path': '.', | 1328 'Path': '.', |
1336 'Node Kind': 'dir', | 1329 'Node Kind': 'dir', |
1337 } | 1330 } |
1338 self.assertEqual(file_info, expected) | 1331 self.assertEqual(file_info, expected) |
1339 self.mox.VerifyAll() | 1332 self.mox.VerifyAll() |
1340 | 1333 |
1341 | 1334 |
| 1335 class RunSVNTestCase(BaseTestCase): |
| 1336 def setUp(self): |
| 1337 self.mox = mox.Mox() |
| 1338 self._OldSubprocessCall = gclient.SubprocessCall |
| 1339 gclient.SubprocessCall = self.mox.CreateMockAnything() |
| 1340 |
| 1341 def tearDown(self): |
| 1342 gclient.SubprocessCall = self._OldSubprocessCall |
| 1343 |
| 1344 def testRunSVN(self): |
| 1345 param2 = 'bleh' |
| 1346 gclient.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) |
| 1347 self.mox.ReplayAll() |
| 1348 gclient.RunSVN(['foo', 'bar'], param2) |
| 1349 self.mox.VerifyAll() |
| 1350 |
| 1351 |
| 1352 class SubprocessCallAndCaptureTestCase(BaseTestCase): |
| 1353 def setUp(self): |
| 1354 self.mox = mox.Mox() |
| 1355 self._sys_stdout = gclient.sys.stdout |
| 1356 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) |
| 1357 self._subprocess_Popen = gclient.subprocess.Popen |
| 1358 gclient.subprocess.Popen = self.mox.CreateMockAnything() |
| 1359 |
| 1360 def tearDown(self): |
| 1361 gclient.sys.stdout = self._sys_stdout |
| 1362 gclient.subprocess.Popen = self._subprocess_Popen |
| 1363 |
| 1364 def testSubprocessCallAndCapture(self): |
| 1365 command = ['boo', 'foo', 'bar'] |
| 1366 in_directory = 'bleh' |
| 1367 fail_status = None |
| 1368 pattern = 'a(.*)b' |
| 1369 test_string = 'ahah\naccb\nallo\naddb\n' |
| 1370 class Mock(object): |
| 1371 stdout = StringIO.StringIO(test_string) |
| 1372 def wait(self): |
| 1373 pass |
| 1374 kid = Mock() |
| 1375 print("\n________ running 'boo foo bar' in 'bleh'") |
| 1376 for i in test_string: |
| 1377 sys.stdout.write(i) |
| 1378 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory, |
| 1379 shell=(sys.platform == 'win32'), |
| 1380 stdout=gclient.subprocess.PIPE).AndReturn(kid) |
| 1381 self.mox.ReplayAll() |
| 1382 capture_list = [] |
| 1383 gclient.SubprocessCallAndCapture(command, in_directory, fail_status, |
| 1384 pattern, capture_list) |
| 1385 self.assertEquals(capture_list, ['cc', 'dd']) |
| 1386 self.mox.VerifyAll() |
| 1387 |
| 1388 |
1342 if __name__ == '__main__': | 1389 if __name__ == '__main__': |
1343 unittest.main() | 1390 unittest.main() |
1344 | 1391 |
1345 # vim: ts=2:sw=2:tw=80:et: | 1392 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |