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 print r1 | |
M-A Ruel
2013/04/30 18:42:40
remove the print statements.
| |
336 print r2 | |
337 self.assertEquals(r1, r2) | |
338 | |
329 | 339 |
330 class S2Test(BaseTestCase): | 340 class S2Test(BaseTestCase): |
331 # Tests that can only run in subprocess2, e.g. new functionalities. | 341 # Tests that can only run in subprocess2, e.g. new functionalities. |
332 # In particular, subprocess2.communicate() doesn't exist in subprocess. | 342 # In particular, subprocess2.communicate() doesn't exist in subprocess. |
333 def _run_test(self, function): | 343 def _run_test(self, function): |
334 """Runs tests in 6 combinations: | 344 """Runs tests in 6 combinations: |
335 - LF output with universal_newlines=False | 345 - LF output with universal_newlines=False |
336 - CR output with universal_newlines=False | 346 - CR output with universal_newlines=False |
337 - CRLF output with universal_newlines=False | 347 - CRLF output with universal_newlines=False |
338 - LF output with universal_newlines=True | 348 - LF output with universal_newlines=True |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 return options.return_value | 652 return options.return_value |
643 | 653 |
644 | 654 |
645 if __name__ == '__main__': | 655 if __name__ == '__main__': |
646 logging.basicConfig(level= | 656 logging.basicConfig(level= |
647 [logging.WARNING, logging.INFO, logging.DEBUG][ | 657 [logging.WARNING, logging.INFO, logging.DEBUG][ |
648 min(2, sys.argv.count('-v'))]) | 658 min(2, sys.argv.count('-v'))]) |
649 if len(sys.argv) > 1 and sys.argv[1] == '--child': | 659 if len(sys.argv) > 1 and sys.argv[1] == '--child': |
650 sys.exit(child_main(sys.argv[2:])) | 660 sys.exit(child_main(sys.argv[2:])) |
651 unittest.main() | 661 unittest.main() |
OLD | NEW |