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

Side by Side Diff: tests/gclient_test.py

Issue 2129005: Goes further down the rabbit hole. (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 | « gclient.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for v in cmds: 90 for v in cmds:
91 # If it fails, you need to add a test case for the new command. 91 # If it fails, you need to add a test case for the new command.
92 self.assert_(v in known_commands) 92 self.assert_(v in known_commands)
93 self.mox.ReplayAll() 93 self.mox.ReplayAll()
94 94
95 class TestCMDconfig(GclientTestCase): 95 class TestCMDconfig(GclientTestCase):
96 def testMissingArgument(self): 96 def testMissingArgument(self):
97 exception_msg = "required argument missing; see 'gclient help config'" 97 exception_msg = "required argument missing; see 'gclient help config'"
98 98
99 self.mox.ReplayAll() 99 self.mox.ReplayAll()
100 self.assertRaisesError(exception_msg, gclient.CMDconfig, self.Options(), ()) 100 self.assertRaisesError(exception_msg, gclient.CMDconfig, None,
101 self.Options(), ())
101 102
102 def testExistingClientFile(self): 103 def testExistingClientFile(self):
103 options = self.Options() 104 options = self.Options()
104 exception_msg = ('%s file already exists in the current directory' % 105 exception_msg = ('%s file already exists in the current directory' %
105 options.config_filename) 106 options.config_filename)
106 gclient.os.path.exists(options.config_filename).AndReturn(True) 107 gclient.os.path.exists(options.config_filename).AndReturn(True)
107 108
108 self.mox.ReplayAll() 109 self.mox.ReplayAll()
109 self.assertRaisesError(exception_msg, gclient.CMDconfig, options, (1,)) 110 self.assertRaisesError(exception_msg, gclient.CMDconfig, None, options,
111 (1,))
110 112
111 def testFromText(self): 113 def testFromText(self):
112 options = self.Options(spec='config_source_content') 114 options = self.Options(spec='config_source_content')
113 gclient.os.path.exists(options.config_filename).AndReturn(False) 115 gclient.os.path.exists(options.config_filename).AndReturn(False)
114 gclient.GClient('.', options).AndReturn(gclient.GClient) 116 gclient.GClient('.', options).AndReturn(gclient.GClient)
115 gclient.GClient.SetConfig(options.spec) 117 gclient.GClient.SetConfig(options.spec)
116 gclient.GClient.SaveConfig() 118 gclient.GClient.SaveConfig()
117 119
118 self.mox.ReplayAll() 120 self.mox.ReplayAll()
119 gclient.CMDconfig(options, (1,),) 121 gclient.CMDconfig(None, options, (1,),)
120 122
121 def testCreateClientFile(self): 123 def testCreateClientFile(self):
122 options = self.Options() 124 options = self.Options()
123 gclient.os.path.exists(options.config_filename).AndReturn(False) 125 gclient.os.path.exists(options.config_filename).AndReturn(False)
124 gclient.GClient('.', options).AndReturn(gclient.GClient) 126 gclient.GClient('.', options).AndReturn(gclient.GClient)
125 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name', 127 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
126 'other') 128 'other')
127 gclient.GClient.SaveConfig() 129 gclient.GClient.SaveConfig()
128 130
129 self.mox.ReplayAll() 131 self.mox.ReplayAll()
130 gclient.CMDconfig(options, 132 gclient.CMDconfig(None, options,
131 ('http://svn/url/the_name', 'other', 'args', 'ignored')) 133 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
132 134
133 135
134 class GenericCommandTestCase(GclientTestCase): 136 class GenericCommandTestCase(GclientTestCase):
135 def ReturnValue(self, command, function, return_value): 137 def ReturnValue(self, command, function, return_value):
136 options = self.Options() 138 options = self.Options()
137 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 139 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
138 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 140 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
139 141
140 self.mox.ReplayAll() 142 self.mox.ReplayAll()
141 result = function(options, self.args) 143 result = function(None, options, self.args)
142 self.assertEquals(result, return_value) 144 self.assertEquals(result, return_value)
143 145
144 def BadClient(self, function): 146 def BadClient(self, function):
145 options = self.Options() 147 options = self.Options()
146 gclient.GClient.LoadCurrentConfig(options).AndReturn(None) 148 gclient.GClient.LoadCurrentConfig(options).AndReturn(None)
147 149
148 self.mox.ReplayAll() 150 self.mox.ReplayAll()
149 self.assertRaisesError( 151 self.assertRaisesError(
150 "client not configured; see 'gclient config'", 152 "client not configured; see 'gclient config'",
151 function, options, self.args) 153 function, None, options, self.args)
152 154
153 def Verbose(self, command, function): 155 def Verbose(self, command, function):
154 options = self.Options(verbose=True) 156 options = self.Options(verbose=True)
155 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 157 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
156 text = "# Dummy content\nclient = 'my client'" 158 text = "# Dummy content\nclient = 'my client'"
157 gclient.GClient.ConfigContent().AndReturn(text) 159 gclient.GClient.ConfigContent().AndReturn(text)
158 print(text) 160 print(text)
159 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 161 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
160 162
161 self.mox.ReplayAll() 163 self.mox.ReplayAll()
162 result = function(options, self.args) 164 result = function(None, options, self.args)
163 self.assertEquals(result, 0) 165 self.assertEquals(result, 0)
164 166
165 167
166 class TestCMDcleanup(GenericCommandTestCase): 168 class TestCMDcleanup(GenericCommandTestCase):
167 def testGoodClient(self): 169 def testGoodClient(self):
168 self.ReturnValue('cleanup', gclient.CMDcleanup, 0) 170 self.ReturnValue('cleanup', gclient.CMDcleanup, 0)
169 def testError(self): 171 def testError(self):
170 self.ReturnValue('cleanup', gclient.CMDcleanup, 42) 172 self.ReturnValue('cleanup', gclient.CMDcleanup, 42)
171 def testBadClient(self): 173 def testBadClient(self):
172 self.BadClient(gclient.CMDcleanup) 174 self.BadClient(gclient.CMDcleanup)
(...skipping 21 matching lines...) Expand all
194 196
195 197
196 class TestCMDupdate(GenericCommandTestCase): 198 class TestCMDupdate(GenericCommandTestCase):
197 def ReturnValue(self, command, function, return_value): 199 def ReturnValue(self, command, function, return_value):
198 options = self.Options() 200 options = self.Options()
199 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 201 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
200 gclient.GClient.GetVar("solutions") 202 gclient.GClient.GetVar("solutions")
201 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value) 203 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
202 204
203 self.mox.ReplayAll() 205 self.mox.ReplayAll()
204 result = function(options, self.args) 206 result = function(None, options, self.args)
205 self.assertEquals(result, return_value) 207 self.assertEquals(result, return_value)
206 208
207 def Verbose(self, command, function): 209 def Verbose(self, command, function):
208 options = self.Options(verbose=True) 210 options = self.Options(verbose=True)
209 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient) 211 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
210 gclient.GClient.GetVar("solutions") 212 gclient.GClient.GetVar("solutions")
211 text = "# Dummy content\nclient = 'my client'" 213 text = "# Dummy content\nclient = 'my client'"
212 gclient.GClient.ConfigContent().AndReturn(text) 214 gclient.GClient.ConfigContent().AndReturn(text)
213 print(text) 215 print(text)
214 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0) 216 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
215 217
216 self.mox.ReplayAll() 218 self.mox.ReplayAll()
217 result = function(options, self.args) 219 result = function(None, options, self.args)
218 self.assertEquals(result, 0) 220 self.assertEquals(result, 0)
219 221
220 def Options(self, verbose=False, *args, **kwargs): 222 def Options(self, verbose=False, *args, **kwargs):
221 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 223 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
222 224
223 def testBasic(self): 225 def testBasic(self):
224 self.ReturnValue('update', gclient.CMDupdate, 0) 226 self.ReturnValue('update', gclient.CMDupdate, 0)
225 def testError(self): 227 def testError(self):
226 self.ReturnValue('update', gclient.CMDupdate, 42) 228 self.ReturnValue('update', gclient.CMDupdate, 42)
227 def testBadClient(self): 229 def testBadClient(self):
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 pass 1259 pass
1258 def test_VarImpl(self): 1260 def test_VarImpl(self):
1259 pass 1261 pass
1260 1262
1261 1263
1262 if __name__ == '__main__': 1264 if __name__ == '__main__':
1263 import unittest 1265 import unittest
1264 unittest.main() 1266 unittest.main()
1265 1267
1266 # vim: ts=2:sw=2:tw=80:et: 1268 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698