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

Side by Side Diff: tests/gclient_test.py

Issue 193004: Added "gclient pack" subcommand, which generates a patch relative to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« gclient.py ('K') | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. 3 # Copyright 2008-2009 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
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 os 22 import os
23 import re
23 import StringIO 24 import StringIO
24 import unittest 25 import unittest
25 26
26 import gclient 27 import gclient
27 import super_mox 28 import super_mox
28 from super_mox import mox 29 from super_mox import mox
29 30
30 31
31 class BaseTestCase(super_mox.SuperMoxTestBase): 32 class BaseTestCase(super_mox.SuperMoxTestBase):
32 def setUp(self): 33 def setUp(self):
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 self.args = self.Args() 104 self.args = self.Args()
104 self.root_dir = self.Dir() 105 self.root_dir = self.Dir()
105 self.url = self.Url() 106 self.url = self.Url()
106 107
107 108
108 class GClientCommandsTestCase(GClientBaseTestCase): 109 class GClientCommandsTestCase(GClientBaseTestCase):
109 def testCommands(self): 110 def testCommands(self):
110 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, 111 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff,
111 gclient.DoExport, gclient.DoHelp, gclient.DoStatus, 112 gclient.DoExport, gclient.DoHelp, gclient.DoStatus,
112 gclient.DoUpdate, gclient.DoRevert, gclient.DoRunHooks, 113 gclient.DoUpdate, gclient.DoRevert, gclient.DoRunHooks,
113 » » gclient.DoRevInfo] 114 » » gclient.DoRevInfo, gclient.DoPack]
114 for (k,v) in gclient.gclient_command_map.iteritems(): 115 for (k,v) in gclient.gclient_command_map.iteritems():
115 # If it fails, you need to add a test case for the new command. 116 # If it fails, you need to add a test case for the new command.
116 self.assert_(v in known_commands) 117 self.assert_(v in known_commands)
117 self.mox.ReplayAll() 118 self.mox.ReplayAll()
118 119
119 class TestDoConfig(GclientTestCase): 120 class TestDoConfig(GclientTestCase):
120 def testMissingArgument(self): 121 def testMissingArgument(self):
121 exception_msg = "required argument missing; see 'gclient help config'" 122 exception_msg = "required argument missing; see 'gclient help config'"
122 123
123 self.mox.ReplayAll() 124 self.mox.ReplayAll()
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 self.args = ['dir'] 296 self.args = ['dir']
296 self.ReturnValue('export', gclient.DoExport, 0) 297 self.ReturnValue('export', gclient.DoExport, 0)
297 def testError(self): 298 def testError(self):
298 self.args = ['dir'] 299 self.args = ['dir']
299 self.ReturnValue('export', gclient.DoExport, 42) 300 self.ReturnValue('export', gclient.DoExport, 42)
300 def testBadClient(self): 301 def testBadClient(self):
301 self.args = ['dir'] 302 self.args = ['dir']
302 self.BadClient(gclient.DoExport) 303 self.BadClient(gclient.DoExport)
303 304
304 305
306 class TestDoPack(GenericCommandTestCase):
307 def Options(self, *args, **kwargs):
308 return self.OptionsObject(self, *args, **kwargs)
309
310 def testBasic(self):
311 self.ReturnValue('pack', gclient.DoPack, 0)
312 def testError(self):
313 self.ReturnValue('pack', gclient.DoPack, 42)
314 def testBadClient(self):
315 self.BadClient(gclient.DoPack)
316
317
305 class TestDoRevert(GenericCommandTestCase): 318 class TestDoRevert(GenericCommandTestCase):
306 def testBasic(self): 319 def testBasic(self):
307 self.ReturnValue('revert', gclient.DoRevert, 0) 320 self.ReturnValue('revert', gclient.DoRevert, 0)
308 def testError(self): 321 def testError(self):
309 self.ReturnValue('revert', gclient.DoRevert, 42) 322 self.ReturnValue('revert', gclient.DoRevert, 42)
310 def testBadClient(self): 323 def testBadClient(self):
311 self.BadClient(gclient.DoRevert) 324 self.BadClient(gclient.DoRevert)
312 325
313 326
314 class GClientClassTestCase(GclientTestCase): 327 class GClientClassTestCase(GclientTestCase):
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 def setUp(self): 1026 def setUp(self):
1014 GClientBaseTestCase.setUp(self) 1027 GClientBaseTestCase.setUp(self)
1015 self.root_dir = self.Dir() 1028 self.root_dir = self.Dir()
1016 self.args = self.Args() 1029 self.args = self.Args()
1017 self.url = self.Url() 1030 self.url = self.Url()
1018 self.relpath = 'asf' 1031 self.relpath = 'asf'
1019 1032
1020 def testDir(self): 1033 def testDir(self):
1021 members = [ 1034 members = [
1022 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', 1035 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
1023 'relpath', 'revert', 'scm_name', 'status', 'update', 'url', 1036 'pack', 'relpath', 'revert', 'scm_name', 'status', 'update', 'url',
1024 ] 1037 ]
1025 1038
1026 # If you add a member, be sure to add the relevant test! 1039 # If you add a member, be sure to add the relevant test!
1027 self.compareMembers(self._scm_wrapper(), members) 1040 self.compareMembers(self._scm_wrapper(), members)
1028 1041
1029 def testFullUrlForRelativeUrl(self): 1042 def testFullUrlForRelativeUrl(self):
1030 self.url = 'svn://a/b/c/d' 1043 self.url = 'svn://a/b/c/d'
1031 1044
1032 self.mox.ReplayAll() 1045 self.mox.ReplayAll()
1033 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1046 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1266
1254 1267
1255 class RunSVNTestCase(BaseTestCase): 1268 class RunSVNTestCase(BaseTestCase):
1256 def testRunSVN(self): 1269 def testRunSVN(self):
1257 param2 = 'bleh' 1270 param2 = 'bleh'
1258 gclient.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) 1271 gclient.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None)
1259 self.mox.ReplayAll() 1272 self.mox.ReplayAll()
1260 gclient.RunSVN(['foo', 'bar'], param2) 1273 gclient.RunSVN(['foo', 'bar'], param2)
1261 1274
1262 1275
1263 class SubprocessCallAndCaptureTestCase(BaseTestCase): 1276 class SubprocessCallAndFilterTestCase(BaseTestCase):
1264 def setUp(self): 1277 def setUp(self):
1265 BaseTestCase.setUp(self) 1278 BaseTestCase.setUp(self)
1266 self.mox.StubOutWithMock(gclient, 'CaptureSVN') 1279 self.mox.StubOutWithMock(gclient, 'CaptureSVN')
1267 1280
1268 def testSubprocessCallAndCapture(self): 1281 def testSubprocessCallAndFilter(self):
1269 command = ['boo', 'foo', 'bar'] 1282 command = ['boo', 'foo', 'bar']
1270 in_directory = 'bleh' 1283 in_directory = 'bleh'
1271 fail_status = None 1284 fail_status = None
1272 pattern = 'a(.*)b' 1285 pattern = 'a(.*)b'
1273 test_string = 'ahah\naccb\nallo\naddb\n' 1286 test_string = 'ahah\naccb\nallo\naddb\n'
1274 class Mock(object): 1287 class Mock(object):
1275 stdout = StringIO.StringIO(test_string) 1288 stdout = StringIO.StringIO(test_string)
1276 def wait(self): 1289 def wait(self):
1277 pass 1290 pass
1278 kid = Mock() 1291 kid = Mock()
1279 print("\n________ running 'boo foo bar' in 'bleh'") 1292 print("\n________ running 'boo foo bar' in 'bleh'")
1280 for i in test_string: 1293 for i in test_string:
1281 gclient.sys.stdout.write(i) 1294 gclient.sys.stdout.write(i)
1282 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory, 1295 gclient.subprocess.Popen(command, bufsize=0, cwd=in_directory,
1283 shell=(gclient.sys.platform == 'win32'), 1296 shell=(gclient.sys.platform == 'win32'),
1284 stdout=gclient.subprocess.PIPE).AndReturn(kid) 1297 stdout=gclient.subprocess.PIPE).AndReturn(kid)
1285 self.mox.ReplayAll() 1298 self.mox.ReplayAll()
1299 compiled_pattern = re.compile(pattern)
1300 line_list = []
1286 capture_list = [] 1301 capture_list = []
1287 gclient.SubprocessCallAndCapture(command, in_directory, fail_status, 1302 def FilterLines(line):
1288 pattern, capture_list) 1303 line_list.append(line)
1304 match = compiled_pattern.search(line)
1305 if match:
1306 capture_list.append(match.group(1))
1307 gclient.SubprocessCallAndFilter(command, in_directory,
1308 True, True,
1309 fail_status, FilterLines)
1310 self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb'])
1289 self.assertEquals(capture_list, ['cc', 'dd']) 1311 self.assertEquals(capture_list, ['cc', 'dd'])
1290 1312
1291 def testCaptureSVNStatus(self): 1313 def testCaptureSVNStatus(self):
1292 x = self 1314 x = self
1293 def CaptureSVNMock(command, in_directory=None, print_error=True): 1315 def CaptureSVNMock(command, in_directory=None, print_error=True):
1294 x.assertEquals(in_directory, None) 1316 x.assertEquals(in_directory, None)
1295 x.assertEquals(print_error, True) 1317 x.assertEquals(print_error, True)
1296 x.assertEquals(['status', '--xml', '.'], command) 1318 x.assertEquals(['status', '--xml', '.'], command)
1297 return r"""<?xml version="1.0"?> 1319 return r"""<?xml version="1.0"?>
1298 <status> 1320 <status>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 """ 1378 """
1357 gclient.CaptureSVN = CaptureSVNMock 1379 gclient.CaptureSVN = CaptureSVNMock
1358 info = gclient.CaptureSVNStatus(None) 1380 info = gclient.CaptureSVNStatus(None)
1359 self.assertEquals(info, []) 1381 self.assertEquals(info, [])
1360 1382
1361 1383
1362 if __name__ == '__main__': 1384 if __name__ == '__main__':
1363 unittest.main() 1385 unittest.main()
1364 1386
1365 # vim: ts=2:sw=2:tw=80:et: 1387 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« gclient.py ('K') | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698