OLD | NEW |
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 # pylint: disable=E1101,W0403 | 6 # pylint: disable=E1101,W0403 |
7 | 7 |
8 import StringIO | 8 import StringIO |
9 | 9 |
10 # Fixes include path. | 10 # Fixes include path. |
11 from super_mox import SuperMoxTestBase | 11 from super_mox import SuperMoxTestBase |
12 | 12 import trial_dir |
| 13 import os |
13 import gclient_utils | 14 import gclient_utils |
14 | 15 |
15 | 16 |
16 class GclientUtilBase(SuperMoxTestBase): | 17 class GclientUtilBase(SuperMoxTestBase): |
17 def setUp(self): | 18 def setUp(self): |
18 super(GclientUtilBase, self).setUp() | 19 super(GclientUtilBase, self).setUp() |
19 gclient_utils.sys.stdout.flush = lambda: None | 20 gclient_utils.sys.stdout.flush = lambda: None |
20 self.mox.StubOutWithMock(gclient_utils, 'Popen') | 21 self.mox.StubOutWithMock(gclient_utils, 'Popen') |
21 | 22 |
22 | 23 |
23 class GclientUtilsUnittest(GclientUtilBase): | 24 class GclientUtilsUnittest(GclientUtilBase): |
24 """General gclient_utils.py tests.""" | 25 """General gclient_utils.py tests.""" |
25 def testMembersChanged(self): | 26 def testMembersChanged(self): |
26 members = [ | 27 members = [ |
27 'CheckCall', 'CheckCallError', 'CheckCallAndFilter', | 28 'CheckCall', 'CheckCallError', 'CheckCallAndFilter', |
28 'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead', | 29 'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead', |
29 'FileWrite', 'FindFileUpwards', 'FindGclientRoot', | 30 'FileWrite', 'FindFileUpwards', 'FindGclientRoot', |
30 'GetGClientRootAndEntries', 'GetNamedNodeText', 'MakeFileAutoFlush', | 31 'GetGClientRootAndEntries', 'GetNamedNodeText', 'MakeFileAutoFlush', |
31 'GetNodeNamedAttributeText', 'MakeFileAnnotated', 'PathDifference', | 32 'GetNodeNamedAttributeText', 'MakeFileAnnotated', 'PathDifference', |
32 'ParseXML', 'Popen', | 33 'ParseXML', 'Popen', |
33 'PrintableObject', 'RemoveDirectory', 'SoftClone', 'SplitUrlRevision', | 34 'PrintableObject', 'RemoveDirectory', 'SoftClone', 'SplitUrlRevision', |
34 'SyntaxErrorToError', 'WorkItem', | 35 'SyntaxErrorToError', 'WorkItem', |
35 'errno', 'hack_subprocess', 'logging', 'os', 'Queue', 're', 'stat', | 36 'errno', 'hack_subprocess', 'logging', 'os', 'Queue', 're', 'rmtree', |
36 'subprocess', 'sys','threading', 'time', 'xml', | 37 'stat', 'subprocess', 'sys','threading', 'time', 'xml', |
37 ] | 38 ] |
38 # If this test fails, you should add the relevant test. | 39 # If this test fails, you should add the relevant test. |
39 self.compareMembers(gclient_utils, members) | 40 self.compareMembers(gclient_utils, members) |
40 | 41 |
41 | 42 |
42 class CheckCallTestCase(GclientUtilBase): | 43 class CheckCallTestCase(GclientUtilBase): |
43 def testCheckCallSuccess(self): | 44 def testCheckCallSuccess(self): |
44 args = ['boo', 'foo', 'bar'] | 45 args = ['boo', 'foo', 'bar'] |
45 process = self.mox.CreateMockAnything() | 46 process = self.mox.CreateMockAnything() |
46 process.returncode = 0 | 47 process.returncode = 0 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 url = "svn://example.com/test" | 175 url = "svn://example.com/test" |
175 rev = "ac345e52dc" | 176 rev = "ac345e52dc" |
176 out_url, out_rev = gclient_utils.SplitUrlRevision(url) | 177 out_url, out_rev = gclient_utils.SplitUrlRevision(url) |
177 self.assertEquals(out_rev, None) | 178 self.assertEquals(out_rev, None) |
178 self.assertEquals(out_url, url) | 179 self.assertEquals(out_url, url) |
179 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) | 180 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) |
180 self.assertEquals(out_rev, rev) | 181 self.assertEquals(out_rev, rev) |
181 self.assertEquals(out_url, url) | 182 self.assertEquals(out_url, url) |
182 | 183 |
183 | 184 |
| 185 class GClientUtilsTest(trial_dir.TestCase): |
| 186 def testHardToDelete(self): |
| 187 # Use the fact that tearDown will delete the directory to make it hard to do |
| 188 # so. |
| 189 l1 = os.path.join(self.root_dir, 'l1') |
| 190 l2 = os.path.join(l1, 'l2') |
| 191 l3 = os.path.join(l2, 'l3') |
| 192 f3 = os.path.join(l3, 'f3') |
| 193 os.mkdir(l1) |
| 194 os.mkdir(l2) |
| 195 os.mkdir(l3) |
| 196 gclient_utils.FileWrite(f3, 'foo') |
| 197 os.chmod(f3, 0) |
| 198 os.chmod(l3, 0) |
| 199 os.chmod(l2, 0) |
| 200 os.chmod(l1, 0) |
| 201 |
| 202 |
184 if __name__ == '__main__': | 203 if __name__ == '__main__': |
185 import unittest | 204 import unittest |
186 unittest.main() | 205 unittest.main() |
187 | 206 |
188 # vim: ts=2:sw=2:tw=80:et: | 207 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |