Mercurial > public > mercurial-scm > hg-stable
annotate tests/test-stdio.py @ 45079:a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Tue, 07 Jul 2020 12:13:40 +0200 |
parents | fa270dcbdb55 |
children | 8e04607023e5 |
rev | line source |
---|---|
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
2 """ |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
3 Tests the buffering behavior of stdio streams in `mercurial.utils.procutil`. |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
4 """ |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
5 from __future__ import absolute_import |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
6 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
7 import contextlib |
45069
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
8 import errno |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
9 import os |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
10 import subprocess |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
11 import sys |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
12 import unittest |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
13 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
14 from mercurial import pycompat |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
15 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
16 |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
17 TEST_BUFFERING_CHILD_SCRIPT = r''' |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
18 import os |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
19 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
20 from mercurial import dispatch |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
21 from mercurial.utils import procutil |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
22 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
23 dispatch.initstdio() |
45047
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
24 procutil.{stream}.write(b'aaa') |
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
25 os.write(procutil.{stream}.fileno(), b'[written aaa]') |
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
26 procutil.{stream}.write(b'bbb\n') |
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
27 os.write(procutil.{stream}.fileno(), b'[written bbb\\n]') |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
28 ''' |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
29 UNBUFFERED = b'aaa[written aaa]bbb\n[written bbb\\n]' |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
30 LINE_BUFFERED = b'[written aaa]aaabbb\n[written bbb\\n]' |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
31 FULLY_BUFFERED = b'[written aaa][written bbb\\n]aaabbb\n' |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
32 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
33 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
34 @contextlib.contextmanager |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
35 def _closing(fds): |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
36 try: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
37 yield |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
38 finally: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
39 for fd in fds: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
40 try: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
41 os.close(fd) |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
42 except EnvironmentError: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
43 pass |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
44 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
45 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
46 @contextlib.contextmanager |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
47 def _pipes(): |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
48 rwpair = os.pipe() |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
49 with _closing(rwpair): |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
50 yield rwpair |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
51 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
52 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
53 @contextlib.contextmanager |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
54 def _ptys(): |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
55 if pycompat.iswindows: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
56 raise unittest.SkipTest("PTYs are not supported on Windows") |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
57 import pty |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
58 import tty |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
59 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
60 rwpair = pty.openpty() |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
61 with _closing(rwpair): |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
62 tty.setraw(rwpair[0]) |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
63 yield rwpair |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
64 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
65 |
45069
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
66 def _readall(fd, buffer_size): |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
67 buf = [] |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
68 while True: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
69 try: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
70 s = os.read(fd, buffer_size) |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
71 except OSError as e: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
72 if e.errno == errno.EIO: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
73 # If the child-facing PTY got closed, reading from the |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
74 # parent-facing PTY raises EIO. |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
75 break |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
76 raise |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
77 if not s: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
78 break |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
79 buf.append(s) |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
80 return b''.join(buf) |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
81 |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
82 |
45047
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
83 class TestStdio(unittest.TestCase): |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
84 def _test( |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
85 self, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
86 child_script, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
87 stream, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
88 rwpair_generator, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
89 check_output, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
90 python_args=[], |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
91 ): |
45047
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
92 assert stream in ('stdout', 'stderr') |
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
93 with rwpair_generator() as (stream_receiver, child_stream), open( |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
94 os.devnull, 'rb' |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
95 ) as child_stdin: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
96 proc = subprocess.Popen( |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
97 [sys.executable] + python_args + ['-c', child_script], |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
98 stdin=child_stdin, |
45047
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
99 stdout=child_stream if stream == 'stdout' else None, |
359884685eab
tests: generalize common test case code in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45046
diff
changeset
|
100 stderr=child_stream if stream == 'stderr' else None, |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
101 ) |
45069
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
102 try: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
103 os.close(child_stream) |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
104 check_output(stream_receiver) |
45070
9172fd511999
tests: terminate subprocess in test-stdio.py in case of exception
Manuel Jacob <me@manueljacob.de>
parents:
45069
diff
changeset
|
105 except: # re-raises |
9172fd511999
tests: terminate subprocess in test-stdio.py in case of exception
Manuel Jacob <me@manueljacob.de>
parents:
45069
diff
changeset
|
106 proc.terminate() |
9172fd511999
tests: terminate subprocess in test-stdio.py in case of exception
Manuel Jacob <me@manueljacob.de>
parents:
45069
diff
changeset
|
107 raise |
45069
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
108 finally: |
8cd18aba5e6c
tests: proof test-stdio.py against buffer fill-up
Manuel Jacob <me@manueljacob.de>
parents:
45048
diff
changeset
|
109 retcode = proc.wait() |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
110 self.assertEqual(retcode, 0) |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
111 |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
112 def _test_buffering( |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
113 self, stream, rwpair_generator, expected_output, python_args=[] |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
114 ): |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
115 def check_output(stream_receiver): |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
116 self.assertEqual(_readall(stream_receiver, 1024), expected_output) |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
117 |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
118 self._test( |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
119 TEST_BUFFERING_CHILD_SCRIPT.format(stream=stream), |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
120 stream, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
121 rwpair_generator, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
122 check_output, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
123 python_args, |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
124 ) |
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
125 |
45071
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
126 def test_buffering_stdout_pipes(self): |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
127 self._test_buffering('stdout', _pipes, FULLY_BUFFERED) |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
128 |
45071
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
129 def test_buffering_stdout_ptys(self): |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
130 self._test_buffering('stdout', _ptys, LINE_BUFFERED) |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
131 |
45071
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
132 def test_buffering_stdout_pipes_unbuffered(self): |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
133 self._test_buffering('stdout', _pipes, UNBUFFERED, python_args=['-u']) |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
134 |
45071
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
135 def test_buffering_stdout_ptys_unbuffered(self): |
45079
a59aab6078eb
tests: make subprocess handling reusable for different tests in test-stdio.py
Manuel Jacob <me@manueljacob.de>
parents:
45078
diff
changeset
|
136 self._test_buffering('stdout', _ptys, UNBUFFERED, python_args=['-u']) |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
137 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
138 if not pycompat.ispy3 and not pycompat.iswindows: |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
139 # On Python 2 on non-Windows, we manually open stdout in line-buffered |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
140 # mode if connected to a TTY. We should check if Python was configured |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
141 # to use unbuffered stdout, but it's hard to do that. |
45071
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
142 test_buffering_stdout_ptys_unbuffered = unittest.expectedFailure( |
bc05c13e246f
tests: make names in test-stdio.py more distinctive
Manuel Jacob <me@manueljacob.de>
parents:
45070
diff
changeset
|
143 test_buffering_stdout_ptys_unbuffered |
45041
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
144 ) |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
145 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
146 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
147 if __name__ == '__main__': |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
148 import silenttestrunner |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
149 |
c7d109c400a4
tests: add tests for buffering behavior of mercurial.utils.procutil.stdout
Manuel Jacob <me@manueljacob.de>
parents:
diff
changeset
|
150 silenttestrunner.main(__name__) |