tests/test-stdio.py
changeset 45070 bc05c13e246f
parent 45069 9172fd511999
child 45077 fa270dcbdb55
equal deleted inserted replaced
45069:9172fd511999 45070:bc05c13e246f
    12 import unittest
    12 import unittest
    13 
    13 
    14 from mercurial import pycompat
    14 from mercurial import pycompat
    15 
    15 
    16 
    16 
    17 CHILD_PROCESS = r'''
    17 BUFFERING_CHILD_SCRIPT = r'''
    18 import os
    18 import os
    19 
    19 
    20 from mercurial import dispatch
    20 from mercurial import dispatch
    21 from mercurial.utils import procutil
    21 from mercurial.utils import procutil
    22 
    22 
    87             os.devnull, 'rb'
    87             os.devnull, 'rb'
    88         ) as child_stdin:
    88         ) as child_stdin:
    89             proc = subprocess.Popen(
    89             proc = subprocess.Popen(
    90                 [sys.executable]
    90                 [sys.executable]
    91                 + python_args
    91                 + python_args
    92                 + ['-c', CHILD_PROCESS.format(stream=stream)],
    92                 + ['-c', BUFFERING_CHILD_SCRIPT.format(stream=stream)],
    93                 stdin=child_stdin,
    93                 stdin=child_stdin,
    94                 stdout=child_stream if stream == 'stdout' else None,
    94                 stdout=child_stream if stream == 'stdout' else None,
    95                 stderr=child_stream if stream == 'stderr' else None,
    95                 stderr=child_stream if stream == 'stderr' else None,
    96             )
    96             )
    97             try:
    97             try:
   104                 raise
   104                 raise
   105             finally:
   105             finally:
   106                 retcode = proc.wait()
   106                 retcode = proc.wait()
   107             self.assertEqual(retcode, 0)
   107             self.assertEqual(retcode, 0)
   108 
   108 
   109     def test_stdout_pipes(self):
   109     def test_buffering_stdout_pipes(self):
   110         self._test('stdout', _pipes, FULLY_BUFFERED)
   110         self._test('stdout', _pipes, FULLY_BUFFERED)
   111 
   111 
   112     def test_stdout_ptys(self):
   112     def test_buffering_stdout_ptys(self):
   113         self._test('stdout', _ptys, LINE_BUFFERED)
   113         self._test('stdout', _ptys, LINE_BUFFERED)
   114 
   114 
   115     def test_stdout_pipes_unbuffered(self):
   115     def test_buffering_stdout_pipes_unbuffered(self):
   116         self._test('stdout', _pipes, UNBUFFERED, python_args=['-u'])
   116         self._test('stdout', _pipes, UNBUFFERED, python_args=['-u'])
   117 
   117 
   118     def test_stdout_ptys_unbuffered(self):
   118     def test_buffering_stdout_ptys_unbuffered(self):
   119         self._test('stdout', _ptys, UNBUFFERED, python_args=['-u'])
   119         self._test('stdout', _ptys, UNBUFFERED, python_args=['-u'])
   120 
   120 
   121     if not pycompat.ispy3 and not pycompat.iswindows:
   121     if not pycompat.ispy3 and not pycompat.iswindows:
   122         # On Python 2 on non-Windows, we manually open stdout in line-buffered
   122         # On Python 2 on non-Windows, we manually open stdout in line-buffered
   123         # mode if connected to a TTY. We should check if Python was configured
   123         # mode if connected to a TTY. We should check if Python was configured
   124         # to use unbuffered stdout, but it's hard to do that.
   124         # to use unbuffered stdout, but it's hard to do that.
   125         test_stdout_ptys_unbuffered = unittest.expectedFailure(
   125         test_buffering_stdout_ptys_unbuffered = unittest.expectedFailure(
   126             test_stdout_ptys_unbuffered
   126             test_buffering_stdout_ptys_unbuffered
   127         )
   127         )
   128 
   128 
   129     def test_stderr_pipes(self):
   129     def test_buffering_stderr_pipes(self):
   130         self._test('stderr', _pipes, UNBUFFERED)
   130         self._test('stderr', _pipes, UNBUFFERED)
   131 
   131 
   132     def test_stderr_ptys(self):
   132     def test_buffering_stderr_ptys(self):
   133         self._test('stderr', _ptys, UNBUFFERED)
   133         self._test('stderr', _ptys, UNBUFFERED)
   134 
   134 
   135     def test_stderr_pipes_unbuffered(self):
   135     def test_buffering_stderr_pipes_unbuffered(self):
   136         self._test('stderr', _pipes, UNBUFFERED, python_args=['-u'])
   136         self._test('stderr', _pipes, UNBUFFERED, python_args=['-u'])
   137 
   137 
   138     def test_stderr_ptys_unbuffered(self):
   138     def test_buffering_stderr_ptys_unbuffered(self):
   139         self._test('stderr', _ptys, UNBUFFERED, python_args=['-u'])
   139         self._test('stderr', _ptys, UNBUFFERED, python_args=['-u'])
   140 
   140 
   141 
   141 
   142 if __name__ == '__main__':
   142 if __name__ == '__main__':
   143     import silenttestrunner
   143     import silenttestrunner