| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 re | 6 import re |
| 7 import StringIO | 7 import StringIO |
| 8 | 8 |
| 9 import gclient_utils | 9 import gclient_utils |
| 10 from super_mox import SuperMoxTestBase | 10 from super_mox import SuperMoxTestBase |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class CheckCallTestCase(SuperMoxTestBase): | 28 class CheckCallTestCase(SuperMoxTestBase): |
| 29 def testCheckCallSuccess(self): | 29 def testCheckCallSuccess(self): |
| 30 command = ['boo', 'foo', 'bar'] | 30 command = ['boo', 'foo', 'bar'] |
| 31 process = self.mox.CreateMockAnything() | 31 process = self.mox.CreateMockAnything() |
| 32 process.returncode = 0 | 32 process.returncode = 0 |
| 33 gclient_utils.subprocess.Popen( | 33 gclient_utils.subprocess.Popen( |
| 34 command, cwd=None, | 34 command, cwd=None, |
| 35 stderr=None, | 35 stderr=None, |
| 36 stdout=gclient_utils.subprocess.PIPE, | 36 stdout=gclient_utils.subprocess.PIPE, |
| 37 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 37 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) |
| 38 process.communicate().AndReturn(['bleh']) | 38 process.communicate().AndReturn(['bleh', 'foo']) |
| 39 self.mox.ReplayAll() | 39 self.mox.ReplayAll() |
| 40 gclient_utils.CheckCall(command) | 40 gclient_utils.CheckCall(command) |
| 41 | 41 |
| 42 def testCheckCallFailure(self): | 42 def testCheckCallFailure(self): |
| 43 command = ['boo', 'foo', 'bar'] | 43 command = ['boo', 'foo', 'bar'] |
| 44 process = self.mox.CreateMockAnything() | 44 process = self.mox.CreateMockAnything() |
| 45 process.returncode = 42 | 45 process.returncode = 42 |
| 46 gclient_utils.subprocess.Popen( | 46 gclient_utils.subprocess.Popen( |
| 47 command, cwd=None, | 47 command, cwd=None, |
| 48 stderr=None, | 48 stderr=None, |
| 49 stdout=gclient_utils.subprocess.PIPE, | 49 stdout=gclient_utils.subprocess.PIPE, |
| 50 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 50 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) |
| 51 process.communicate().AndReturn(['bleh']) | 51 process.communicate().AndReturn(['bleh', 'foo']) |
| 52 self.mox.ReplayAll() | 52 self.mox.ReplayAll() |
| 53 try: | 53 try: |
| 54 gclient_utils.CheckCall(command) | 54 gclient_utils.CheckCall(command) |
| 55 self.fail() | 55 self.fail() |
| 56 except gclient_utils.CheckCallError, e: | 56 except gclient_utils.CheckCallError, e: |
| 57 self.assertEqual(e.command, command) | 57 self.assertEqual(e.command, command) |
| 58 self.assertEqual(e.cwd, None) | 58 self.assertEqual(e.cwd, None) |
| 59 self.assertEqual(e.retcode, 42) | 59 self.assertEqual(e.retcode, 42) |
| 60 self.assertEqual(e.stdout, 'bleh') | 60 self.assertEqual(e.stdout, 'bleh') |
| 61 self.assertEqual(e.stderr, 'foo') |
| 61 | 62 |
| 62 | 63 |
| 63 class SubprocessCallAndFilterTestCase(SuperMoxTestBase): | 64 class SubprocessCallAndFilterTestCase(SuperMoxTestBase): |
| 64 def testSubprocessCallAndFilter(self): | 65 def testSubprocessCallAndFilter(self): |
| 65 command = ['boo', 'foo', 'bar'] | 66 command = ['boo', 'foo', 'bar'] |
| 66 in_directory = 'bleh' | 67 in_directory = 'bleh' |
| 67 fail_status = None | 68 fail_status = None |
| 68 pattern = 'a(.*)b' | 69 pattern = 'a(.*)b' |
| 69 test_string = 'ahah\naccb\nallo\naddb\n' | 70 test_string = 'ahah\naccb\nallo\naddb\n' |
| 70 class Mock(object): | 71 class Mock(object): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) | 136 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) |
| 136 self.assertEquals(out_rev, rev) | 137 self.assertEquals(out_rev, rev) |
| 137 self.assertEquals(out_url, url) | 138 self.assertEquals(out_url, url) |
| 138 | 139 |
| 139 | 140 |
| 140 if __name__ == '__main__': | 141 if __name__ == '__main__': |
| 141 import unittest | 142 import unittest |
| 142 unittest.main() | 143 unittest.main() |
| 143 | 144 |
| 144 # vim: ts=2:sw=2:tw=80:et: | 145 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |