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

Side by Side Diff: tests/gclient_utils_test.py

Issue 3155024: Fix gclient_utils_test and disable gclient_scm_test. (Closed)
Patch Set: Created 10 years, 4 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 | « PRESUBMIT.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 import StringIO 6 import StringIO
7 7
8 # Fixes include path. 8 # Fixes include path.
9 from super_mox import SuperMoxTestBase 9 from super_mox import SuperMoxTestBase
10 10
11 import gclient_utils 11 import gclient_utils
12 12
13 13
14 class GclientUtilsUnittest(SuperMoxTestBase): 14 class GclientUtilBase(SuperMoxTestBase):
15 def setUp(self):
16 super(GclientUtilBase, self).setUp()
17 gclient_utils.sys.stdout.flush = lambda: None
18
19
20 class GclientUtilsUnittest(GclientUtilBase):
15 """General gclient_utils.py tests.""" 21 """General gclient_utils.py tests."""
16 def testMembersChanged(self): 22 def testMembersChanged(self):
17 members = [ 23 members = [
18 'CheckCall', 'CheckCallError', 'Error', 'ExecutionQueue', 'FileRead', 24 'CheckCall', 'CheckCallError', 'Error', 'ExecutionQueue', 'FileRead',
19 'FileWrite', 'FindFileUpwards', 'FindGclientRoot', 25 'FileWrite', 'FindFileUpwards', 'FindGclientRoot',
20 'GetGClientRootAndEntries', 'GetNamedNodeText', 26 'GetGClientRootAndEntries', 'GetNamedNodeText',
21 'GetNodeNamedAttributeText', 'PathDifference', 'ParseXML', 27 'GetNodeNamedAttributeText', 'PathDifference', 'ParseXML',
22 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', 28 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
23 'SubprocessCall', 'SubprocessCallAndFilter', 'SyntaxErrorToError', 29 'SubprocessCall', 'SubprocessCallAndFilter', 'SyntaxErrorToError',
24 'WorkItem', 30 'WorkItem',
25 'errno', 'logging', 'os', 're', 'stat', 'subprocess', 'sys', 31 'errno', 'logging', 'os', 're', 'stat', 'subprocess', 'sys',
26 'threading', 'time', 'xml', 32 'threading', 'time', 'xml',
27 ] 33 ]
28 # If this test fails, you should add the relevant test. 34 # If this test fails, you should add the relevant test.
29 self.compareMembers(gclient_utils, members) 35 self.compareMembers(gclient_utils, members)
30 36
31 37
32 class CheckCallTestCase(SuperMoxTestBase): 38 class CheckCallTestCase(GclientUtilBase):
33 def testCheckCallSuccess(self): 39 def testCheckCallSuccess(self):
34 command = ['boo', 'foo', 'bar'] 40 command = ['boo', 'foo', 'bar']
35 process = self.mox.CreateMockAnything() 41 process = self.mox.CreateMockAnything()
36 process.returncode = 0 42 process.returncode = 0
37 gclient_utils.subprocess.Popen( 43 gclient_utils.subprocess.Popen(
38 command, cwd=None, 44 command, cwd=None,
39 stderr=None, 45 stderr=None,
40 stdout=gclient_utils.subprocess.PIPE, 46 stdout=gclient_utils.subprocess.PIPE,
41 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) 47 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process)
42 process.communicate().AndReturn(['bleh', 'foo']) 48 process.communicate().AndReturn(['bleh', 'foo'])
(...skipping 15 matching lines...) Expand all
58 gclient_utils.CheckCall(command) 64 gclient_utils.CheckCall(command)
59 self.fail() 65 self.fail()
60 except gclient_utils.CheckCallError, e: 66 except gclient_utils.CheckCallError, e:
61 self.assertEqual(e.command, command) 67 self.assertEqual(e.command, command)
62 self.assertEqual(e.cwd, None) 68 self.assertEqual(e.cwd, None)
63 self.assertEqual(e.retcode, 42) 69 self.assertEqual(e.retcode, 42)
64 self.assertEqual(e.stdout, 'bleh') 70 self.assertEqual(e.stdout, 'bleh')
65 self.assertEqual(e.stderr, 'foo') 71 self.assertEqual(e.stderr, 'foo')
66 72
67 73
68 class SubprocessCallAndFilterTestCase(SuperMoxTestBase): 74 class SubprocessCallAndFilterTestCase(GclientUtilBase):
69 def testSubprocessCallAndFilter(self): 75 def testSubprocessCallAndFilter(self):
70 command = ['boo', 'foo', 'bar'] 76 command = ['boo', 'foo', 'bar']
71 in_directory = 'bleh' 77 in_directory = 'bleh'
72 fail_status = None 78 fail_status = None
73 pattern = 'a(.*)b' 79 pattern = 'a(.*)b'
74 test_string = 'ahah\naccb\nallo\naddb\n' 80 test_string = 'ahah\naccb\nallo\naddb\n'
75 class Mock(object): 81 class Mock(object):
76 stdout = StringIO.StringIO(test_string) 82 stdout = StringIO.StringIO(test_string)
77 def wait(self): 83 def wait(self):
78 pass 84 pass
(...skipping 16 matching lines...) Expand all
95 if match: 101 if match:
96 capture_list.append(match.group(1)) 102 capture_list.append(match.group(1))
97 gclient_utils.SubprocessCallAndFilter( 103 gclient_utils.SubprocessCallAndFilter(
98 command, in_directory, 104 command, in_directory,
99 True, True, 105 True, True,
100 fail_status, FilterLines) 106 fail_status, FilterLines)
101 self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb']) 107 self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb'])
102 self.assertEquals(capture_list, ['cc', 'dd']) 108 self.assertEquals(capture_list, ['cc', 'dd'])
103 109
104 110
105 class SplitUrlRevisionTestCase(SuperMoxTestBase): 111 class SplitUrlRevisionTestCase(GclientUtilBase):
106 def testSSHUrl(self): 112 def testSSHUrl(self):
107 url = "ssh://test@example.com/test.git" 113 url = "ssh://test@example.com/test.git"
108 rev = "ac345e52dc" 114 rev = "ac345e52dc"
109 out_url, out_rev = gclient_utils.SplitUrlRevision(url) 115 out_url, out_rev = gclient_utils.SplitUrlRevision(url)
110 self.assertEquals(out_rev, None) 116 self.assertEquals(out_rev, None)
111 self.assertEquals(out_url, url) 117 self.assertEquals(out_url, url)
112 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) 118 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
113 self.assertEquals(out_rev, rev) 119 self.assertEquals(out_rev, rev)
114 self.assertEquals(out_url, url) 120 self.assertEquals(out_url, url)
115 url = "ssh://example.com/test.git" 121 url = "ssh://example.com/test.git"
(...skipping 24 matching lines...) Expand all
140 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) 146 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
141 self.assertEquals(out_rev, rev) 147 self.assertEquals(out_rev, rev)
142 self.assertEquals(out_url, url) 148 self.assertEquals(out_url, url)
143 149
144 150
145 if __name__ == '__main__': 151 if __name__ == '__main__':
146 import unittest 152 import unittest
147 unittest.main() 153 unittest.main()
148 154
149 # vim: ts=2:sw=2:tw=80:et: 155 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698