Index: Lib/test/test_subprocess.py =================================================================== --- Lib/test/test_subprocess.py (revision 73407) +++ Lib/test/test_subprocess.py (working copy) @@ -537,6 +537,55 @@ except (IOError, OSError) as err: if err.errno != 2: # ignore "no such file" raise + + def test_encoded_stdout(self): + send = '\xef' + encoding = 'utf-8' + script = """ +import os +import sys +send = %(send)r.encode(%(encoding)r) +while send: + sent = os.write(sys.stdout.fileno(), send) + send = send[sent:] +""" % {'send': send, 'encoding': encoding} + p = subprocess.Popen([sys.executable, "-c", script], + encoding=encoding, stdout=subprocess.PIPE) + self.assertEqual(p.stdout.read(), send) + + def test_encoded_stderr(self): + send = '\xef' + encoding = 'utf-8' + script = """ +import os +import sys +send = %(send)r.encode(%(encoding)r) +while send: + sent = os.write(sys.stderr.fileno(), send) + send = send[sent:] +""" % {'send': send, 'encoding': encoding} + p = subprocess.Popen([sys.executable, "-c", script], + encoding=encoding, stderr=subprocess.PIPE) + self.assertEqual(p.stderr.read(), send) + + def test_encoded_stdin(self): + send = '\xef' + encoding = 'utf-8' + script = """ +import os +import sys +send = %(send)r.encode(%(encoding)r) +recv = bytes() +while len(recv) != len(send): + recv += os.read(sys.stdin.fileno(), len(send) - len(recv)) +if send != recv: + sys.exit(1) +""" % {'send': send, 'encoding': encoding} + p = subprocess.Popen([sys.executable, "-c", script], + encoding=encoding, stdin=subprocess.PIPE) + p.stdin.write(send) + p.stdin.flush() + self.assertEqual(p.wait(), 0) # # POSIX tests