| 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 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ] | 33 ] |
| 34 # If this test fails, you should add the relevant test. | 34 # If this test fails, you should add the relevant test. |
| 35 self.compareMembers(gclient_utils, members) | 35 self.compareMembers(gclient_utils, members) |
| 36 | 36 |
| 37 | 37 |
| 38 class CheckCallTestCase(GclientUtilBase): | 38 class CheckCallTestCase(GclientUtilBase): |
| 39 def testCheckCallSuccess(self): | 39 def testCheckCallSuccess(self): |
| 40 command = ['boo', 'foo', 'bar'] | 40 command = ['boo', 'foo', 'bar'] |
| 41 process = self.mox.CreateMockAnything() | 41 process = self.mox.CreateMockAnything() |
| 42 process.returncode = 0 | 42 process.returncode = 0 |
| 43 env = gclient_utils.os.environ.copy() |
| 44 env['LANGUAGE'] = 'en' |
| 43 gclient_utils.subprocess.Popen( | 45 gclient_utils.subprocess.Popen( |
| 44 command, cwd=None, | 46 command, cwd=None, |
| 45 stderr=None, | 47 stderr=None, |
| 48 env=env, |
| 46 stdout=gclient_utils.subprocess.PIPE, | 49 stdout=gclient_utils.subprocess.PIPE, |
| 47 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 50 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) |
| 48 process.communicate().AndReturn(['bleh', 'foo']) | 51 process.communicate().AndReturn(['bleh', 'foo']) |
| 49 self.mox.ReplayAll() | 52 self.mox.ReplayAll() |
| 50 gclient_utils.CheckCall(command) | 53 gclient_utils.CheckCall(command) |
| 51 | 54 |
| 52 def testCheckCallFailure(self): | 55 def testCheckCallFailure(self): |
| 53 command = ['boo', 'foo', 'bar'] | 56 command = ['boo', 'foo', 'bar'] |
| 54 process = self.mox.CreateMockAnything() | 57 process = self.mox.CreateMockAnything() |
| 55 process.returncode = 42 | 58 process.returncode = 42 |
| 59 env = gclient_utils.os.environ.copy() |
| 60 env['LANGUAGE'] = 'en' |
| 56 gclient_utils.subprocess.Popen( | 61 gclient_utils.subprocess.Popen( |
| 57 command, cwd=None, | 62 command, cwd=None, |
| 58 stderr=None, | 63 stderr=None, |
| 64 env=env, |
| 59 stdout=gclient_utils.subprocess.PIPE, | 65 stdout=gclient_utils.subprocess.PIPE, |
| 60 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 66 shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) |
| 61 process.communicate().AndReturn(['bleh', 'foo']) | 67 process.communicate().AndReturn(['bleh', 'foo']) |
| 62 self.mox.ReplayAll() | 68 self.mox.ReplayAll() |
| 63 try: | 69 try: |
| 64 gclient_utils.CheckCall(command) | 70 gclient_utils.CheckCall(command) |
| 65 self.fail() | 71 self.fail() |
| 66 except gclient_utils.CheckCallError, e: | 72 except gclient_utils.CheckCallError, e: |
| 67 self.assertEqual(e.command, command) | 73 self.assertEqual(e.command, command) |
| 68 self.assertEqual(e.cwd, None) | 74 self.assertEqual(e.cwd, None) |
| 69 self.assertEqual(e.retcode, 42) | 75 self.assertEqual(e.retcode, 42) |
| 70 self.assertEqual(e.stdout, 'bleh') | 76 self.assertEqual(e.stdout, 'bleh') |
| 71 self.assertEqual(e.stderr, 'foo') | 77 self.assertEqual(e.stderr, 'foo') |
| 72 | 78 |
| 73 | 79 |
| 74 class SubprocessCallAndFilterTestCase(GclientUtilBase): | 80 class SubprocessCallAndFilterTestCase(GclientUtilBase): |
| 75 def testSubprocessCallAndFilter(self): | 81 def testSubprocessCallAndFilter(self): |
| 76 command = ['boo', 'foo', 'bar'] | 82 command = ['boo', 'foo', 'bar'] |
| 77 in_directory = 'bleh' | 83 in_directory = 'bleh' |
| 78 fail_status = None | 84 fail_status = None |
| 79 pattern = 'a(.*)b' | 85 pattern = 'a(.*)b' |
| 80 test_string = 'ahah\naccb\nallo\naddb\n' | 86 test_string = 'ahah\naccb\nallo\naddb\n' |
| 87 env = gclient_utils.os.environ.copy() |
| 88 env['LANGUAGE'] = 'en' |
| 81 class Mock(object): | 89 class Mock(object): |
| 82 stdout = StringIO.StringIO(test_string) | 90 stdout = StringIO.StringIO(test_string) |
| 83 def wait(self): | 91 def wait(self): |
| 84 pass | 92 pass |
| 85 kid = Mock() | 93 kid = Mock() |
| 86 print("\n________ running 'boo foo bar' in 'bleh'") | 94 print("\n________ running 'boo foo bar' in 'bleh'") |
| 87 for i in test_string: | 95 for i in test_string: |
| 88 gclient_utils.sys.stdout.write(i) | 96 gclient_utils.sys.stdout.write(i) |
| 89 gclient_utils.subprocess.Popen( | 97 gclient_utils.subprocess.Popen( |
| 90 command, bufsize=0, cwd=in_directory, | 98 command, bufsize=0, cwd=in_directory, |
| 91 shell=(gclient_utils.sys.platform == 'win32'), | 99 shell=(gclient_utils.sys.platform == 'win32'), |
| 100 env=env, |
| 92 stdout=gclient_utils.subprocess.PIPE, | 101 stdout=gclient_utils.subprocess.PIPE, |
| 93 stderr=gclient_utils.subprocess.STDOUT).AndReturn(kid) | 102 stderr=gclient_utils.subprocess.STDOUT).AndReturn(kid) |
| 94 self.mox.ReplayAll() | 103 self.mox.ReplayAll() |
| 95 compiled_pattern = gclient_utils.re.compile(pattern) | 104 compiled_pattern = gclient_utils.re.compile(pattern) |
| 96 line_list = [] | 105 line_list = [] |
| 97 capture_list = [] | 106 capture_list = [] |
| 98 def FilterLines(line): | 107 def FilterLines(line): |
| 99 line_list.append(line) | 108 line_list.append(line) |
| 100 match = compiled_pattern.search(line) | 109 match = compiled_pattern.search(line) |
| 101 if match: | 110 if match: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) | 155 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) |
| 147 self.assertEquals(out_rev, rev) | 156 self.assertEquals(out_rev, rev) |
| 148 self.assertEquals(out_url, url) | 157 self.assertEquals(out_url, url) |
| 149 | 158 |
| 150 | 159 |
| 151 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 152 import unittest | 161 import unittest |
| 153 unittest.main() | 162 unittest.main() |
| 154 | 163 |
| 155 # vim: ts=2:sw=2:tw=80:et: | 164 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |