@@ -608,8 +608,6 @@ def test_universal_newlines_communicate(self):
608608 universal_newlines = 1 )
609609 self .addCleanup (p .stdout .close )
610610 self .addCleanup (p .stderr .close )
611- # BUG: can't give a non-empty stdin because it breaks both the
612- # select- and poll-based communicate() implementations.
613611 (stdout , stderr ) = p .communicate ()
614612 self .assertEqual (stdout ,
615613 "line2\n line4\n line5\n line6\n line7\n line8" )
@@ -640,6 +638,35 @@ def test_universal_newlines_communicate_input_none(self):
640638 p .communicate ()
641639 self .assertEqual (p .returncode , 0 )
642640
641+ def test_universal_newlines_communicate_stdin_stdout_stderr (self ):
642+ # universal newlines through communicate(), with stdin, stdout, stderr
643+ p = subprocess .Popen ([sys .executable , "-c" ,
644+ 'import sys,os;' + SETBINARY + '''\n if True:
645+ s = sys.stdin.buffer.readline()
646+ sys.stdout.buffer.write(s)
647+ sys.stdout.buffer.write(b"line2\\ r")
648+ sys.stderr.buffer.write(b"eline2\\ n")
649+ s = sys.stdin.buffer.read()
650+ sys.stdout.buffer.write(s)
651+ sys.stdout.buffer.write(b"line4\\ n")
652+ sys.stdout.buffer.write(b"line5\\ r\\ n")
653+ sys.stderr.buffer.write(b"eline6\\ r")
654+ sys.stderr.buffer.write(b"eline7\\ r\\ nz")
655+ ''' ],
656+ stdin = subprocess .PIPE ,
657+ stderr = subprocess .PIPE ,
658+ stdout = subprocess .PIPE ,
659+ universal_newlines = True )
660+ self .addCleanup (p .stdout .close )
661+ self .addCleanup (p .stderr .close )
662+ (stdout , stderr ) = p .communicate ("line1\n line3\n " )
663+ self .assertEqual (p .returncode , 0 )
664+ self .assertEqual ("line1\n line2\n line3\n line4\n line5\n " , stdout )
665+ # Python debug build push something like "[42442 refs]\n"
666+ # to stderr at exit of subprocess.
667+ # Don't use assertStderrEqual because it strips CR and LF from output.
668+ self .assertTrue (stderr .startswith ("eline2\n eline6\n eline7\n " ))
669+
643670 def test_universal_newlines_communicate_encodings (self ):
644671 # Check that universal newlines mode works for various encodings,
645672 # in particular for encodings in the UTF-16 and UTF-32 families.
0 commit comments