OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Unit tests for subprocess2.py.""" | 6 """Unit tests for subprocess2.py.""" |
7 | 7 |
8 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 def test_redirect_stderr_to_stdout(self): | 320 def test_redirect_stderr_to_stdout(self): |
321 def fn(c, e, un, subp): | 321 def fn(c, e, un, subp): |
322 # stderr output into stdout but stdout is not piped. | 322 # stderr output into stdout but stdout is not piped. |
323 proc = subp.Popen( | 323 proc = subp.Popen( |
324 e + ['--stderr'], stderr=STDOUT, universal_newlines=un) | 324 e + ['--stderr'], stderr=STDOUT, universal_newlines=un) |
325 res = proc.communicate(), proc.returncode | 325 res = proc.communicate(), proc.returncode |
326 self._check_res(res, None, None, 0) | 326 self._check_res(res, None, None, 0) |
327 self._run_test(fn) | 327 self._run_test(fn) |
328 | 328 |
| 329 def test_stderr(self): |
| 330 cmd = ['expr', '1', '/', '0'] |
| 331 p1 = subprocess.Popen(cmd, stderr=subprocess.PIPE) |
| 332 p2 = subprocess2.Popen(cmd, stderr=subprocess.PIPE) |
| 333 r1 = p1.communicate() |
| 334 r2 = p2.communicate(timeout=100) |
| 335 self.assertEquals(r1, r2) |
| 336 |
329 | 337 |
330 class S2Test(BaseTestCase): | 338 class S2Test(BaseTestCase): |
331 # Tests that can only run in subprocess2, e.g. new functionalities. | 339 # Tests that can only run in subprocess2, e.g. new functionalities. |
332 # In particular, subprocess2.communicate() doesn't exist in subprocess. | 340 # In particular, subprocess2.communicate() doesn't exist in subprocess. |
333 def _run_test(self, function): | 341 def _run_test(self, function): |
334 """Runs tests in 6 combinations: | 342 """Runs tests in 6 combinations: |
335 - LF output with universal_newlines=False | 343 - LF output with universal_newlines=False |
336 - CR output with universal_newlines=False | 344 - CR output with universal_newlines=False |
337 - CRLF output with universal_newlines=False | 345 - CRLF output with universal_newlines=False |
338 - LF output with universal_newlines=True | 346 - LF output with universal_newlines=True |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 return options.return_value | 650 return options.return_value |
643 | 651 |
644 | 652 |
645 if __name__ == '__main__': | 653 if __name__ == '__main__': |
646 logging.basicConfig(level= | 654 logging.basicConfig(level= |
647 [logging.WARNING, logging.INFO, logging.DEBUG][ | 655 [logging.WARNING, logging.INFO, logging.DEBUG][ |
648 min(2, sys.argv.count('-v'))]) | 656 min(2, sys.argv.count('-v'))]) |
649 if len(sys.argv) > 1 and sys.argv[1] == '--child': | 657 if len(sys.argv) > 1 and sys.argv[1] == '--child': |
650 sys.exit(child_main(sys.argv[2:])) | 658 sys.exit(child_main(sys.argv[2:])) |
651 unittest.main() | 659 unittest.main() |
OLD | NEW |