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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 output = executive.run_command(command_line('cat'), input=encoded_tor, d
ecode_output=False) | 158 output = executive.run_command(command_line('cat'), input=encoded_tor, d
ecode_output=False) |
159 self.assertEqual(output, encoded_tor) | 159 self.assertEqual(output, encoded_tor) |
160 | 160 |
161 # FIXME: We should only have one run* method to test | 161 # FIXME: We should only have one run* method to test |
162 output = executive.run_and_throw_if_fail(command_line('echo', unicode_to
r_input), quiet=True) | 162 output = executive.run_and_throw_if_fail(command_line('echo', unicode_to
r_input), quiet=True) |
163 self.assertEqual(output, unicode_tor_output) | 163 self.assertEqual(output, unicode_tor_output) |
164 | 164 |
165 output = executive.run_and_throw_if_fail(command_line('echo', unicode_to
r_input), quiet=True, decode_output=False) | 165 output = executive.run_and_throw_if_fail(command_line('echo', unicode_to
r_input), quiet=True, decode_output=False) |
166 self.assertEqual(output, encoded_tor) | 166 self.assertEqual(output, encoded_tor) |
167 | 167 |
168 def serial_test_kill_process(self): | 168 def test_kill_process(self): |
169 if sys.platform in ("win32", "cygwin"): | |
170 return # Windows does not return consistent exit codes. | |
171 | |
172 executive = Executive() | 169 executive = Executive() |
173 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP
E) | 170 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP
E) |
174 self.assertEqual(process.poll(), None) # Process is running | 171 self.assertEqual(process.poll(), None) # Process is running |
175 executive.kill_process(process.pid) | 172 executive.kill_process(process.pid) |
176 self.assertEqual(process.wait(), -signal.SIGKILL) | |
177 | 173 |
178 # Killing again should fail silently. | 174 # Killing again should fail silently. |
179 executive.kill_process(process.pid) | 175 executive.kill_process(process.pid) |
180 | 176 |
181 def _assert_windows_image_name(self, name, expected_windows_name): | 177 def _assert_windows_image_name(self, name, expected_windows_name): |
182 executive = Executive() | 178 executive = Executive() |
183 windows_name = executive._windows_image_name(name) | 179 windows_name = executive._windows_image_name(name) |
184 self.assertEqual(windows_name, expected_windows_name) | 180 self.assertEqual(windows_name, expected_windows_name) |
185 | 181 |
186 def test_windows_image_name(self): | 182 def test_windows_image_name(self): |
187 self._assert_windows_image_name("foo", "foo.exe") | 183 self._assert_windows_image_name("foo", "foo.exe") |
188 self._assert_windows_image_name("foo.exe", "foo.exe") | 184 self._assert_windows_image_name("foo.exe", "foo.exe") |
189 self._assert_windows_image_name("foo.com", "foo.com") | 185 self._assert_windows_image_name("foo.com", "foo.com") |
190 # If the name looks like an extension, even if it isn't | 186 # If the name looks like an extension, even if it isn't |
191 # supposed to, we have no choice but to return the original name. | 187 # supposed to, we have no choice but to return the original name. |
192 self._assert_windows_image_name("foo.baz", "foo.baz") | 188 self._assert_windows_image_name("foo.baz", "foo.baz") |
193 self._assert_windows_image_name("foo.baz.exe", "foo.baz.exe") | 189 self._assert_windows_image_name("foo.baz.exe", "foo.baz.exe") |
194 | 190 |
195 def serial_test_check_running_pid(self): | 191 def test_check_running_pid(self): |
196 executive = Executive() | 192 executive = Executive() |
197 self.assertTrue(executive.check_running_pid(os.getpid())) | 193 self.assertTrue(executive.check_running_pid(os.getpid())) |
198 # Maximum pid number on Linux is 32768 by default | 194 # Maximum pid number on Linux is 32768 by default |
199 self.assertFalse(executive.check_running_pid(100000)) | 195 self.assertFalse(executive.check_running_pid(100000)) |
200 | 196 |
201 def serial_test_running_pids(self): | 197 def test_running_pids(self): |
202 if sys.platform in ("win32", "cygwin"): | 198 if sys.platform in ("win32", "cygwin"): |
203 return # This function isn't implemented on Windows yet. | 199 return # This function isn't implemented on Windows yet. |
204 | 200 |
205 executive = Executive() | 201 executive = Executive() |
206 pids = executive.running_pids() | 202 pids = executive.running_pids() |
207 self.assertIn(os.getpid(), pids) | 203 self.assertIn(os.getpid(), pids) |
208 | 204 |
209 def test_run_in_parallel_assert_nonempty(self): | 205 def test_run_in_parallel_assert_nonempty(self): |
210 self.assertRaises(AssertionError, Executive().run_in_parallel, []) | 206 self.assertRaises(AssertionError, Executive().run_in_parallel, []) |
211 | 207 |
212 | 208 |
213 def main(platform, stdin, stdout, cmd, args): | 209 def main(platform, stdin, stdout, cmd, args): |
214 if platform == 'win32' and hasattr(stdout, 'fileno'): | 210 if platform == 'win32' and hasattr(stdout, 'fileno'): |
215 import msvcrt | 211 import msvcrt |
216 msvcrt.setmode(stdout.fileno(), os.O_BINARY) | 212 msvcrt.setmode(stdout.fileno(), os.O_BINARY) |
217 if cmd == '--cat': | 213 if cmd == '--cat': |
218 stdout.write(stdin.read()) | 214 stdout.write(stdin.read()) |
219 elif cmd == '--echo': | 215 elif cmd == '--echo': |
220 stdout.write(' '.join(args)) | 216 stdout.write(' '.join(args)) |
221 return 0 | 217 return 0 |
222 | 218 |
223 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): | 219 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): |
224 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) | 220 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) |
OLD | NEW |