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

Side by Side Diff: tests/gclient_utils_test.py

Issue 26234004: Consolidate subprocess retry logic into gclient_utils. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 2 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
« no previous file with comments | « gclient_utils.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import os 6 import os
7 import StringIO 7 import StringIO
8 import sys 8 import sys
9 9
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
(...skipping 16 matching lines...) Expand all
27 class GclientUtilsUnittest(GclientUtilBase): 27 class GclientUtilsUnittest(GclientUtilBase):
28 """General gclient_utils.py tests.""" 28 """General gclient_utils.py tests."""
29 def testMembersChanged(self): 29 def testMembersChanged(self):
30 members = [ 30 members = [
31 'Annotated', 'AutoFlush', 'CheckCallAndFilter', 'CommandToStr', 31 'Annotated', 'AutoFlush', 'CheckCallAndFilter', 'CommandToStr',
32 'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead', 32 'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead',
33 'FileWrite', 'FindFileUpwards', 'FindGclientRoot', 33 'FileWrite', 'FindFileUpwards', 'FindGclientRoot',
34 'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision', 34 'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision',
35 'MakeDateRevision', 'MakeFileAutoFlush', 'MakeFileAnnotated', 35 'MakeDateRevision', 'MakeFileAutoFlush', 'MakeFileAnnotated',
36 'PathDifference', 'ParseCodereviewSettingsContent', 'NumLocalCpus', 36 'PathDifference', 'ParseCodereviewSettingsContent', 'NumLocalCpus',
37 'PrintableObject', 'RunEditor', 'GCLIENT_CHILDREN', 37 'PrintableObject', 'RETRY_INITIAL_SLEEP', 'RETRY_MAX', 'RunEditor',
38 'GCLIENT_CHILDREN_LOCK', 'GClientChildren', 38 'GCLIENT_CHILDREN', 'GCLIENT_CHILDREN_LOCK', 'GClientChildren',
39 'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper', 39 'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper',
40 'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'pipes', 'Queue', 40 'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'pipes', 'Queue',
41 're', 'rmtree', 'safe_makedirs', 'safe_rename', 'stat', 'subprocess', 41 're', 'rmtree', 'safe_makedirs', 'safe_rename', 'stat', 'subprocess',
42 'subprocess2', 'sys', 'tempfile', 'threading', 'time', 'urlparse', 42 'subprocess2', 'sys', 'tempfile', 'threading', 'time', 'urlparse',
43 ] 43 ]
44 # If this test fails, you should add the relevant test. 44 # If this test fails, you should add the relevant test.
45 self.compareMembers(gclient_utils, members) 45 self.compareMembers(gclient_utils, members)
46 46
47 47
48 48
49 class CheckCallAndFilterTestCase(GclientUtilBase): 49 class CheckCallAndFilterTestCase(GclientUtilBase):
50 class ProcessIdMock(object): 50 class ProcessIdMock(object):
51 def __init__(self, test_string): 51 def __init__(self, test_string):
52 self.stdout = StringIO.StringIO(test_string) 52 self.stdout = StringIO.StringIO(test_string)
53 self.pid = 9284 53 self.pid = 9284
54 # pylint: disable=R0201
54 def wait(self): 55 def wait(self):
55 pass 56 return 0
56 57
57 def _inner(self, args, test_string): 58 def _inner(self, args, test_string):
58 cwd = 'bleh' 59 cwd = 'bleh'
59 gclient_utils.sys.stdout.write( 60 gclient_utils.sys.stdout.write(
60 '\n________ running \'boo foo bar\' in \'bleh\'\n') 61 '\n________ running \'boo foo bar\' in \'bleh\'\n')
61 for i in test_string: 62 for i in test_string:
62 gclient_utils.sys.stdout.write(i) 63 gclient_utils.sys.stdout.write(i)
63 # pylint: disable=E1101 64 # pylint: disable=E1101
64 subprocess2.Popen( 65 subprocess2.Popen(
65 args, 66 args,
66 cwd=cwd, 67 cwd=cwd,
67 stdout=subprocess2.PIPE, 68 stdout=subprocess2.PIPE,
68 stderr=subprocess2.STDOUT, 69 stderr=subprocess2.STDOUT,
69 bufsize=0).AndReturn(self.ProcessIdMock(test_string)) 70 bufsize=0).AndReturn(self.ProcessIdMock(test_string))
70 71
72 os.getcwd()
71 self.mox.ReplayAll() 73 self.mox.ReplayAll()
72 compiled_pattern = gclient_utils.re.compile(r'a(.*)b') 74 compiled_pattern = gclient_utils.re.compile(r'a(.*)b')
73 line_list = [] 75 line_list = []
74 capture_list = [] 76 capture_list = []
75 def FilterLines(line): 77 def FilterLines(line):
76 line_list.append(line) 78 line_list.append(line)
77 assert isinstance(line, str), type(line) 79 assert isinstance(line, str), type(line)
78 match = compiled_pattern.search(line) 80 match = compiled_pattern.search(line)
79 if match: 81 if match:
80 capture_list.append(match.group(1)) 82 capture_list.append(match.group(1))
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 for content, expected in values: 214 for content, expected in values:
213 self.assertEquals( 215 self.assertEquals(
214 expected, gclient_utils.ParseCodereviewSettingsContent(content)) 216 expected, gclient_utils.ParseCodereviewSettingsContent(content))
215 217
216 218
217 if __name__ == '__main__': 219 if __name__ == '__main__':
218 import unittest 220 import unittest
219 unittest.main() 221 unittest.main()
220 222
221 # vim: ts=2:sw=2:tw=80:et: 223 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698