summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_file.py
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-01 20:52:56 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-07-01 20:52:56 (GMT)
commitceda6a67ce93dd9ac982ead61a23f98f85ea1821 (patch)
treeafbcf17649cc2972bf0267f8b32391a2eb48969f /Lib/test/test_file.py
parent6fa30f40b50e9f98579d16ee8358b75b898f13de (diff)
downloadcpython-ceda6a67ce93dd9ac982ead61a23f98f85ea1821.zip
cpython-ceda6a67ce93dd9ac982ead61a23f98f85ea1821.tar.gz
cpython-ceda6a67ce93dd9ac982ead61a23f98f85ea1821.tar.bz2
#3242: fix a crash in "print", if sys.stdout is set to a custom object,
whose write() method installs another sys.stdout. Backport of r64633
Diffstat (limited to 'Lib/test/test_file.py')
-rw-r--r--Lib/test/test_file.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 73cb5b2..0a8114a 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -323,11 +323,30 @@ class OtherFileTests(unittest.TestCase):
os.unlink(TESTFN)
+class StdoutTests(unittest.TestCase):
+
+ def test_move_stdout_on_write(self):
+ # Issue 3242: sys.stdout can be replaced (and freed) during a
+ # print statement; prevent a segfault in this case
+ save_stdout = sys.stdout
+
+ class File:
+ def write(self, data):
+ if '\n' in data:
+ sys.stdout = save_stdout
+
+ try:
+ sys.stdout = File()
+ print "some text"
+ finally:
+ sys.stdout = save_stdout
+
+
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.
# So get rid of it no matter what.
try:
- run_unittest(AutoFileTests, OtherFileTests)
+ run_unittest(AutoFileTests, OtherFileTests, StdoutTests)
finally:
if os.path.exists(TESTFN):
os.unlink(TESTFN)