From patchwork Tue Jul 14 18:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [4, of, 5, V3] tests: add tests for when stdout or stderr is connected to `os.devnull` From: Manuel Jacob X-Patchwork-Id: 46745 Message-Id: <49ebcf3b048c7352a4c3.1594752110@tmp> To: mercurial-devel@mercurial-scm.org Date: Tue, 14 Jul 2020 20:41:50 +0200 # HG changeset patch # User Manuel Jacob # Date 1594291962 -7200 # Thu Jul 09 12:52:42 2020 +0200 # Node ID 49ebcf3b048c7352a4c32b1fd6c793ab99aec246 # Parent 72d55f3922b4711c1394bf0e51479fba1129ca8c # EXP-Topic stdio 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. diff --git a/tests/test-stdio.py b/tests/test-stdio.py --- a/tests/test-stdio.py +++ b/tests/test-stdio.py @@ -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'])