summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-01-09 18:53:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-01-09 18:53:14 (GMT)
commit0560843b8fe8d4dd9e830f7b3ae7984154914516 (patch)
treebe1fabb299e11cdc957e653592bbc7d658a9fc07 /Lib/test/test_cmd_line.py
parent1483140772c3f6c4c1674f0fbfcaaa1b350d27a1 (diff)
downloadcpython-0560843b8fe8d4dd9e830f7b3ae7984154914516.zip
cpython-0560843b8fe8d4dd9e830f7b3ae7984154914516.tar.gz
cpython-0560843b8fe8d4dd9e830f7b3ae7984154914516.tar.bz2
Issue #4705: Fix the -u ("unbuffered binary stdout and stderr") command-line
flag to work properly. Furthermore, when specifying -u, the text stdout and stderr streams have line-by-line buffering enabled (the default being to buffer arbitrary chunks of data). Patch by Victor Stinner, test by me.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index e8db7d0..e567184 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -142,6 +142,23 @@ class CmdLineTest(unittest.TestCase):
self.exit_code('-c', command),
0)
+ def test_unbuffered_output(self):
+ # Test expected operation of the '-u' switch
+ for stream in ('stdout', 'stderr'):
+ # Binary is unbuffered
+ code = ("import os, sys; sys.%s.buffer.write(b'x'); os._exit(0)"
+ % stream)
+ data, rc = self.start_python_and_exit_code('-u', '-c', code)
+ self.assertEqual(rc, 0)
+ self.assertEqual(data, b'x', "binary %s not unbuffered" % stream)
+ # Text is line-buffered
+ code = ("import os, sys; sys.%s.write('x\\n'); os._exit(0)"
+ % stream)
+ data, rc = self.start_python_and_exit_code('-u', '-c', code)
+ self.assertEqual(rc, 0)
+ self.assertEqual(data.strip(), b'x',
+ "text %s not line-buffered" % stream)
+
def test_main():
test.support.run_unittest(CmdLineTest)