| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved. | 2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 import os | 30 import os |
| 31 import errno | |
| 32 import signal | |
| 33 import subprocess | 31 import subprocess |
| 34 import sys | 32 import sys |
| 35 import unittest | 33 import unittest |
| 36 | 34 |
| 37 # Since we execute this script directly as part of the unit tests, we need to en
sure | 35 # Since we execute this script directly as part of the unit tests, we need to en
sure |
| 38 # that Tools/Scripts is in sys.path for the next imports to work correctly. | 36 # that Tools/Scripts is in sys.path for the next imports to work correctly. |
| 39 script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.
path.abspath(__file__))))) | 37 SCRIPT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.
path.abspath(__file__))))) |
| 40 if script_dir not in sys.path: | 38 if SCRIPT_DIR not in sys.path: |
| 41 sys.path.append(script_dir) | 39 sys.path.append(SCRIPT_DIR) |
| 42 | |
| 43 | 40 |
| 44 from webkitpy.common.system.executive import Executive, ScriptError | 41 from webkitpy.common.system.executive import Executive, ScriptError |
| 45 from webkitpy.common.system.filesystem_mock import MockFileSystem | 42 from webkitpy.common.system.filesystem_mock import MockFileSystem |
| 46 | 43 |
| 47 | 44 |
| 48 class ScriptErrorTest(unittest.TestCase): | 45 class ScriptErrorTest(unittest.TestCase): |
| 49 | 46 |
| 50 def test_message_with_output(self): | 47 def test_message_with_output(self): |
| 51 error = ScriptError('My custom message!', '', -1) | 48 error = ScriptError('My custom message!', '', -1) |
| 52 self.assertEqual(error.message_with_output(), 'My custom message!') | 49 self.assertEqual(error.message_with_output(), 'My custom message!') |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 encoded_tor = unicode_tor_input.encode(encoding) | 133 encoded_tor = unicode_tor_input.encode(encoding) |
| 137 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be | 134 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be |
| 138 # lossy. On other platforms, we expect a lossless roundtrip. | 135 # lossy. On other platforms, we expect a lossless roundtrip. |
| 139 if sys.platform == 'win32': | 136 if sys.platform == 'win32': |
| 140 unicode_tor_output = encoded_tor.decode(encoding) | 137 unicode_tor_output = encoded_tor.decode(encoding) |
| 141 else: | 138 else: |
| 142 unicode_tor_output = unicode_tor_input | 139 unicode_tor_output = unicode_tor_input |
| 143 | 140 |
| 144 executive = Executive() | 141 executive = Executive() |
| 145 | 142 |
| 146 output = executive.run_command(command_line('cat'), input=unicode_tor_in
put) | 143 output = executive.run_command(command_line('cat'), input_func=unicode_t
or_input) |
| 147 self.assertEqual(output, unicode_tor_output) | 144 self.assertEqual(output, unicode_tor_output) |
| 148 | 145 |
| 149 output = executive.run_command(command_line('echo', unicode_tor_input)) | 146 output = executive.run_command(command_line('echo', unicode_tor_input)) |
| 150 self.assertEqual(output, unicode_tor_output) | 147 self.assertEqual(output, unicode_tor_output) |
| 151 | 148 |
| 152 output = executive.run_command(command_line('echo', unicode_tor_input),
decode_output=False) | 149 output = executive.run_command(command_line('echo', unicode_tor_input),
decode_output=False) |
| 153 self.assertEqual(output, encoded_tor) | 150 self.assertEqual(output, encoded_tor) |
| 154 | 151 |
| 155 # Make sure that str() input also works. | 152 # Make sure that str() input also works. |
| 156 output = executive.run_command(command_line('cat'), input=encoded_tor, d
ecode_output=False) | 153 output = executive.run_command(command_line('cat'), input_func=encoded_t
or, decode_output=False) |
| 157 self.assertEqual(output, encoded_tor) | 154 self.assertEqual(output, encoded_tor) |
| 158 | 155 |
| 159 def test_kill_process(self): | 156 def test_kill_process(self): |
| 160 executive = Executive() | 157 executive = Executive() |
| 161 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP
E) | 158 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP
E) |
| 162 self.assertEqual(process.poll(), None) # Process is running | 159 self.assertEqual(process.poll(), None) # Process is running |
| 163 executive.kill_process(process.pid) | 160 executive.kill_process(process.pid) |
| 164 | 161 |
| 165 # Killing again should fail silently. | 162 # Killing again should fail silently. |
| 166 executive.kill_process(process.pid) | 163 executive.kill_process(process.pid) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 executive = Executive() | 186 executive = Executive() |
| 190 pids = executive.running_pids() | 187 pids = executive.running_pids() |
| 191 self.assertIn(os.getpid(), pids) | 188 self.assertIn(os.getpid(), pids) |
| 192 | 189 |
| 193 def test_run_in_parallel_assert_nonempty(self): | 190 def test_run_in_parallel_assert_nonempty(self): |
| 194 self.assertRaises(AssertionError, Executive().run_in_parallel, []) | 191 self.assertRaises(AssertionError, Executive().run_in_parallel, []) |
| 195 | 192 |
| 196 | 193 |
| 197 def main(platform, stdin, stdout, cmd, args): | 194 def main(platform, stdin, stdout, cmd, args): |
| 198 if platform == 'win32' and hasattr(stdout, 'fileno'): | 195 if platform == 'win32' and hasattr(stdout, 'fileno'): |
| 199 import msvcrt | 196 # The module msvcrt and os.O_BINARY are not available on non-Windows. |
| 200 msvcrt.setmode(stdout.fileno(), os.O_BINARY) | 197 import msvcrt # pylint: disable=import-error |
| 198 msvcrt.setmode(stdout.fileno(), os.O_BINARY) # pylint: disable=no-membe
r |
| 201 if cmd == '--cat': | 199 if cmd == '--cat': |
| 202 stdout.write(stdin.read()) | 200 stdout.write(stdin.read()) |
| 203 elif cmd == '--echo': | 201 elif cmd == '--echo': |
| 204 stdout.write(' '.join(args)) | 202 stdout.write(' '.join(args)) |
| 205 return 0 | 203 return 0 |
| 206 | 204 |
| 207 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): | 205 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): |
| 208 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) | 206 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) |
| OLD | NEW |