summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-12-21 21:14:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-12-21 21:14:56 (GMT)
commit17c93260a62ac895f336351158e6fdaa6b117bcb (patch)
tree509cf48ae9786fc19913013bff9c407f5f38851b /Lib/test/test_tempfile.py
parentbdce938af2af03b2eb0d0e4731f1b8c4b965eaf5 (diff)
downloadcpython-17c93260a62ac895f336351158e6fdaa6b117bcb.zip
cpython-17c93260a62ac895f336351158e6fdaa6b117bcb.tar.gz
cpython-17c93260a62ac895f336351158e6fdaa6b117bcb.tar.bz2
Issue #18879: When a method is looked up on a temporary file, avoid closing the file before the method is possibly called.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 9c4c158..e708ce8 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -8,6 +8,7 @@ import sys
import re
import warnings
import contextlib
+import weakref
import unittest
from test import support
@@ -674,6 +675,22 @@ class TestNamedTemporaryFile(BaseTestCase):
self.do_create(pre="a", suf="b")
self.do_create(pre="aa", suf=".txt")
+ def test_method_lookup(self):
+ # Issue #18879: Looking up a temporary file method should keep it
+ # alive long enough.
+ f = self.do_create()
+ wr = weakref.ref(f)
+ write = f.write
+ write2 = f.write
+ del f
+ write(b'foo')
+ del write
+ write2(b'bar')
+ del write2
+ if support.check_impl_detail(cpython=True):
+ # No reference cycle was created.
+ self.assertIsNone(wr())
+
def test_creates_named(self):
# NamedTemporaryFile creates files with names
f = tempfile.NamedTemporaryFile()