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

Side by Side Diff: tests/gclient_test.py

Issue 2078011: Simplify a bit the gclient unit test (Closed)
Patch Set: Created 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for gclient.py.""" 6 """Unit tests for gclient.py."""
7 7
8 # Fixes include path. 8 # Fixes include path.
9 from super_mox import mox, SuperMoxTestBase 9 from super_mox import mox, SuperMoxTestBase
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name', 127 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
128 'other') 128 'other')
129 gclient.GClient.SaveConfig() 129 gclient.GClient.SaveConfig()
130 130
131 self.mox.ReplayAll() 131 self.mox.ReplayAll()
132 gclient.CMDconfig(None, options, 132 gclient.CMDconfig(None, options,
133 ('http://svn/url/the_name', 'other', 'args', 'ignored')) 133 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
134 134
135 135
136 class GenericCommandTestCase(GclientTestCase): 136 class GenericCommandTestCase(GclientTestCase):
137 def ReturnValue(self, command, function, return_value): 137 def ReturnValue(self, command, return_value):
138 options = self.Options() 138 options = self.Options()
139 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 139 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
140 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 140 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
141 141
142 self.mox.ReplayAll() 142 self.mox.ReplayAll()
143 function = getattr(gclient, 'CMD' + command)
143 result = function(None, options, self.args) 144 result = function(None, options, self.args)
144 self.assertEquals(result, return_value) 145 self.assertEquals(result, return_value)
145 146
146 def BadClient(self, function): 147 def BadClient(self, command):
147 options = self.Options() 148 options = self.Options()
148 gclient.GClient.LoadCurrentConfig(options).AndReturn(None) 149 gclient.GClient.LoadCurrentConfig(options).AndReturn(None)
149 150
150 self.mox.ReplayAll() 151 self.mox.ReplayAll()
152 function = getattr(gclient, 'CMD' + command)
151 self.assertRaisesError( 153 self.assertRaisesError(
152 "client not configured; see 'gclient config'", 154 "client not configured; see 'gclient config'",
153 function, None, options, self.args) 155 function, None, options, self.args)
154 156
155 def Verbose(self, command, function): 157 def Verbose(self, command):
156 options = self.Options(verbose=True) 158 options = self.Options(verbose=True)
157 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 159 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
158 text = "# Dummy content\nclient = 'my client'" 160 text = "# Dummy content\nclient = 'my client'"
159 gclient.GClient.ConfigContent().AndReturn(text) 161 gclient.GClient.ConfigContent().AndReturn(text)
160 print(text) 162 print(text)
161 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 163 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
162 164
163 self.mox.ReplayAll() 165 self.mox.ReplayAll()
166 function = getattr(gclient, 'CMD' + command)
164 result = function(None, options, self.args) 167 result = function(None, options, self.args)
165 self.assertEquals(result, 0) 168 self.assertEquals(result, 0)
166 169
167 170
168 class TestCMDcleanup(GenericCommandTestCase): 171 class TestCMDcleanup(GenericCommandTestCase):
169 def testGoodClient(self): 172 def testGoodClient(self):
170 self.ReturnValue('cleanup', gclient.CMDcleanup, 0) 173 self.ReturnValue('cleanup', 0)
171 def testError(self): 174 def testError(self):
172 self.ReturnValue('cleanup', gclient.CMDcleanup, 42) 175 self.ReturnValue('cleanup', 42)
173 def testBadClient(self): 176 def testBadClient(self):
174 self.BadClient(gclient.CMDcleanup) 177 self.BadClient('cleanup')
175 178
176 179
177 class TestCMDstatus(GenericCommandTestCase): 180 class TestCMDstatus(GenericCommandTestCase):
178 def testGoodClient(self): 181 def testGoodClient(self):
179 self.ReturnValue('status', gclient.CMDstatus, 0) 182 self.ReturnValue('status', 0)
180 def testError(self): 183 def testError(self):
181 self.ReturnValue('status', gclient.CMDstatus, 42) 184 self.ReturnValue('status', 42)
182 def testBadClient(self): 185 def testBadClient(self):
183 self.BadClient(gclient.CMDstatus) 186 self.BadClient('status')
184 187
185 188
186 class TestCMDrunhooks(GenericCommandTestCase): 189 class TestCMDrunhooks(GenericCommandTestCase):
187 def Options(self, verbose=False, *args, **kwargs): 190 def Options(self, verbose=False, *args, **kwargs):
188 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 191 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
189 192
190 def testGoodClient(self): 193 def testGoodClient(self):
191 self.ReturnValue('runhooks', gclient.CMDrunhooks, 0) 194 self.ReturnValue('runhooks', 0)
192 def testError(self): 195 def testError(self):
193 self.ReturnValue('runhooks', gclient.CMDrunhooks, 42) 196 self.ReturnValue('runhooks', 42)
194 def testBadClient(self): 197 def testBadClient(self):
195 self.BadClient(gclient.CMDrunhooks) 198 self.BadClient('runhooks')
196 199
197 200
198 class TestCMDupdate(GenericCommandTestCase): 201 class TestCMDupdate(GenericCommandTestCase):
199 def ReturnValue(self, command, function, return_value): 202 def ReturnValue(self, command, return_value):
200 options = self.Options() 203 options = self.Options()
201 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 204 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
202 gclient.GClient.GetVar("solutions") 205 gclient.GClient.GetVar("solutions")
203 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 206 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
204 207
205 self.mox.ReplayAll() 208 self.mox.ReplayAll()
209 function = getattr(gclient, 'CMD' + command)
206 result = function(None, options, self.args) 210 result = function(None, options, self.args)
207 self.assertEquals(result, return_value) 211 self.assertEquals(result, return_value)
208 212
209 def Verbose(self, command, function): 213 def Verbose(self, command):
210 options = self.Options(verbose=True) 214 options = self.Options(verbose=True)
211 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 215 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
212 gclient.GClient.GetVar("solutions") 216 gclient.GClient.GetVar("solutions")
213 text = "# Dummy content\nclient = 'my client'" 217 text = "# Dummy content\nclient = 'my client'"
214 gclient.GClient.ConfigContent().AndReturn(text) 218 gclient.GClient.ConfigContent().AndReturn(text)
215 print(text) 219 print(text)
216 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 220 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
217 221
218 self.mox.ReplayAll() 222 self.mox.ReplayAll()
223 function = getattr(gclient, 'CMD' + command)
219 result = function(None, options, self.args) 224 result = function(None, options, self.args)
220 self.assertEquals(result, 0) 225 self.assertEquals(result, 0)
221 226
222 def Options(self, verbose=False, *args, **kwargs): 227 def Options(self, verbose=False, *args, **kwargs):
223 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 228 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
224 229
225 def testBasic(self): 230 def testBasic(self):
226 self.ReturnValue('update', gclient.CMDupdate, 0) 231 self.ReturnValue('update', 0)
227 def testError(self): 232 def testError(self):
228 self.ReturnValue('update', gclient.CMDupdate, 42) 233 self.ReturnValue('update', 42)
229 def testBadClient(self): 234 def testBadClient(self):
230 self.BadClient(gclient.CMDupdate) 235 self.BadClient('update')
231 def testVerbose(self): 236 def testVerbose(self):
232 self.Verbose('update', gclient.CMDupdate) 237 self.Verbose('update')
233 238
234 239
235 class TestCMDdiff(GenericCommandTestCase): 240 class TestCMDdiff(GenericCommandTestCase):
236 def Options(self, *args, **kwargs): 241 def Options(self, *args, **kwargs):
237 return self.OptionsObject(self, *args, **kwargs) 242 return self.OptionsObject(self, *args, **kwargs)
238 243
239 def testBasic(self): 244 def testBasic(self):
240 self.ReturnValue('diff', gclient.CMDdiff, 0) 245 self.ReturnValue('diff', 0)
241 def testError(self): 246 def testError(self):
242 self.ReturnValue('diff', gclient.CMDdiff, 42) 247 self.ReturnValue('diff', 42)
243 def testBadClient(self): 248 def testBadClient(self):
244 self.BadClient(gclient.CMDdiff) 249 self.BadClient('diff')
245 def testVerbose(self): 250 def testVerbose(self):
246 self.Verbose('diff', gclient.CMDdiff) 251 self.Verbose('diff')
247 252
248 253
249 class TestCMDexport(GenericCommandTestCase): 254 class TestCMDexport(GenericCommandTestCase):
250 def testBasic(self): 255 def testBasic(self):
251 self.args = ['dir'] 256 self.args = ['dir']
252 self.ReturnValue('export', gclient.CMDexport, 0) 257 self.ReturnValue('export', 0)
253 def testError(self): 258 def testError(self):
254 self.args = ['dir'] 259 self.args = ['dir']
255 self.ReturnValue('export', gclient.CMDexport, 42) 260 self.ReturnValue('export', 42)
256 def testBadClient(self): 261 def testBadClient(self):
257 self.args = ['dir'] 262 self.args = ['dir']
258 self.BadClient(gclient.CMDexport) 263 self.BadClient('export')
259 264
260 265
261 class TestCMDpack(GenericCommandTestCase): 266 class TestCMDpack(GenericCommandTestCase):
262 def Options(self, *args, **kwargs): 267 def Options(self, *args, **kwargs):
263 return self.OptionsObject(self, *args, **kwargs) 268 return self.OptionsObject(self, *args, **kwargs)
264 269
265 def testBasic(self): 270 def testBasic(self):
266 self.ReturnValue('pack', gclient.CMDpack, 0) 271 self.ReturnValue('pack', 0)
267 def testError(self): 272 def testError(self):
268 self.ReturnValue('pack', gclient.CMDpack, 42) 273 self.ReturnValue('pack', 42)
269 def testBadClient(self): 274 def testBadClient(self):
270 self.BadClient(gclient.CMDpack) 275 self.BadClient('pack')
271 276
272 277
273 class TestCMDrevert(GenericCommandTestCase): 278 class TestCMDrevert(GenericCommandTestCase):
274 def testBasic(self): 279 def testBasic(self):
275 self.ReturnValue('revert', gclient.CMDrevert, 0) 280 self.ReturnValue('revert', 0)
276 def testError(self): 281 def testError(self):
277 self.ReturnValue('revert', gclient.CMDrevert, 42) 282 self.ReturnValue('revert', 42)
278 def testBadClient(self): 283 def testBadClient(self):
279 self.BadClient(gclient.CMDrevert) 284 self.BadClient('revert')
280 285
281 286
282 class GClientClassTestCase(GclientTestCase): 287 class GClientClassTestCase(GclientTestCase):
283 def testDir(self): 288 def testDir(self):
284 members = [ 289 members = [
285 'ConfigContent', 'DEFAULT_CLIENT_FILE_TEXT', 290 'ConfigContent', 'DEFAULT_CLIENT_FILE_TEXT',
286 'DEFAULT_SNAPSHOT_FILE_TEXT', 'DEFAULT_SNAPSHOT_SOLUTION_TEXT', 291 'DEFAULT_SNAPSHOT_FILE_TEXT', 'DEFAULT_SNAPSHOT_SOLUTION_TEXT',
287 'DEPS_FILE', 'FileImpl', 'FromImpl', 'GetVar', 'LoadCurrentConfig', 292 'DEPS_FILE', 'FileImpl', 'FromImpl', 'GetVar', 'LoadCurrentConfig',
288 'PrintRevInfo', 'RunOnDeps', 'SaveConfig', 'SetConfig', 293 'PrintRevInfo', 'RunOnDeps', 'SaveConfig', 'SetConfig',
289 'SetDefaultConfig', 294 'SetDefaultConfig',
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 pass 1264 pass
1260 def test_VarImpl(self): 1265 def test_VarImpl(self):
1261 pass 1266 pass
1262 1267
1263 1268
1264 if __name__ == '__main__': 1269 if __name__ == '__main__':
1265 import unittest 1270 import unittest
1266 unittest.main() 1271 unittest.main()
1267 1272
1268 # vim: ts=2:sw=2:tw=80:et: 1273 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698