summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-26 21:02:29 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-26 21:02:29 (GMT)
commit5604ef3e36756e59d3396ed16d7a94de2687e0ac (patch)
tree73c134b68d7a8536a9002cf427af96e67dafebf7 /Lib/test/test_cmd_line.py
parent59ff2c56402362702054fa06c2b360326941e940 (diff)
parentd7c8fbf89e751d43c56de0071702d2578676d0a1 (diff)
downloadcpython-5604ef3e36756e59d3396ed16d7a94de2687e0ac.zip
cpython-5604ef3e36756e59d3396ed16d7a94de2687e0ac.tar.gz
cpython-5604ef3e36756e59d3396ed16d7a94de2687e0ac.tar.bz2
Issue #13444: When stdout has been closed explicitly, we should not attempt to flush it at shutdown and print an error.
This also adds a test for issue #5319, whose resolution introduced the issue.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 9738691..52e715c 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -266,6 +266,25 @@ class CmdLineTest(unittest.TestCase):
self.assertRegex(err.decode('ascii', 'ignore'), 'SyntaxError')
self.assertEqual(b'', out)
+ def test_stdout_flush_at_shutdown(self):
+ # Issue #5319: if stdout.flush() fails at shutdown, an error should
+ # be printed out.
+ code = """if 1:
+ import os, sys
+ sys.stdout.write('x')
+ os.close(sys.stdout.fileno())"""
+ rc, out, err = assert_python_ok('-c', code)
+ self.assertEqual(b'', out)
+ self.assertRegex(err.decode('ascii', 'ignore'),
+ 'Exception OSError: .* ignored')
+
+ def test_closed_stdout(self):
+ # Issue #13444: if stdout has been explicitly closed, we should
+ # not attempt to flush it at shutdown.
+ code = "import sys; sys.stdout.close()"
+ rc, out, err = assert_python_ok('-c', code)
+ self.assertEqual(b'', err)
+
def test_main():
test.support.run_unittest(CmdLineTest)