Patchwork [10,of,11,V2] tests: add tests for when stdout or stderr is connected to `os.devnull`

login
register
mail settings
Submitter Manuel Jacob
Date July 12, 2020, 10:41 p.m.
Message ID <533e609683424b17e4df.1594593695@tmp>
Download mbox | patch
Permalink /patch/46714/
State Accepted
Headers show

Comments

Manuel Jacob - July 12, 2020, 10:41 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1594291962 -7200
#      Thu Jul 09 12:52:42 2020 +0200
# Node ID 533e609683424b17e4dfd04b126d8ee9d081730b
# Parent  4adabe764af5c4104da59140a04c1102592e60c1
# 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.

Patch

diff --git a/tests/test-stdio.py b/tests/test-stdio.py
--- a/tests/test-stdio.py
+++ b/tests/test-stdio.py
@@ -68,6 +68,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):
@@ -125,7 +132,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
@@ -147,12 +155,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'])
 
@@ -221,24 +235,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'])