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