Mercurial > hg-stable
changeset 45096:e9e452eafbfb
tests: add tests for when stdout or stderr is connected to `os.devnull`
The original motivation was that creating PTYs on Windows is not possible, but
`NUL` is recognized as a TTY, so we can have at least some test coverage for
the TTY case. I think it doesn’t hurt to run the test cases on all systems.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Thu, 09 Jul 2020 12:52:42 +0200 |
parents | 8e04607023e5 |
children | dff208398ede |
files | tests/test-stdio.py |
diffstat | 1 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-stdio.py Fri Jul 10 12:27:58 2020 +0200 +++ b/tests/test-stdio.py Thu Jul 09 12:52:42 2020 +0200 @@ -58,6 +58,13 @@ @contextlib.contextmanager +def _devnull(): + devnull = os.open(os.devnull, os.O_WRONLY) + with _closing([devnull]): + yield (None, devnull) + + +@contextlib.contextmanager def _pipes(): rwpair = os.pipe() with _closing(rwpair): @@ -115,7 +122,8 @@ ) try: os.close(child_stream) - check_output(stream_receiver, proc) + if stream_receiver is not None: + check_output(stream_receiver, proc) except: # re-raises proc.terminate() raise @@ -137,12 +145,18 @@ python_args, ) + def test_buffering_stdout_devnull(self): + self._test_buffering('stdout', _devnull, None) + def test_buffering_stdout_pipes(self): self._test_buffering('stdout', _pipes, FULLY_BUFFERED) def test_buffering_stdout_ptys(self): self._test_buffering('stdout', _ptys, LINE_BUFFERED) + def test_buffering_stdout_devnull_unbuffered(self): + self._test_buffering('stdout', _devnull, None, python_args=['-u']) + def test_buffering_stdout_pipes_unbuffered(self): self._test_buffering('stdout', _pipes, UNBUFFERED, python_args=['-u']) @@ -188,24 +202,36 @@ python_args, ) + def test_large_write_stdout_devnull(self): + self._test_large_write('stdout', _devnull) + def test_large_write_stdout_pipes(self): self._test_large_write('stdout', _pipes) def test_large_write_stdout_ptys(self): self._test_large_write('stdout', _ptys) + def test_large_write_stdout_devnull_unbuffered(self): + self._test_large_write('stdout', _devnull, python_args=['-u']) + def test_large_write_stdout_pipes_unbuffered(self): self._test_large_write('stdout', _pipes, python_args=['-u']) def test_large_write_stdout_ptys_unbuffered(self): self._test_large_write('stdout', _ptys, python_args=['-u']) + def test_large_write_stderr_devnull(self): + self._test_large_write('stderr', _devnull) + def test_large_write_stderr_pipes(self): self._test_large_write('stderr', _pipes) def test_large_write_stderr_ptys(self): self._test_large_write('stderr', _ptys) + def test_large_write_stderr_devnull_unbuffered(self): + self._test_large_write('stderr', _devnull, python_args=['-u']) + def test_large_write_stderr_pipes_unbuffered(self): self._test_large_write('stderr', _pipes, python_args=['-u'])