summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-12-21 21:16:19 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-12-21 21:16:19 (GMT)
commit2b7f69851d641e4bf48c762c9a23df5b51982a1f (patch)
tree6bfd2dce3c4aa7bbec313e1001e32b6842621a66 /Lib/test/test_tempfile.py
parentc16dfe18376791b3118ef42d39a3afd25ac6e306 (diff)
parent17c93260a62ac895f336351158e6fdaa6b117bcb (diff)
downloadcpython-2b7f69851d641e4bf48c762c9a23df5b51982a1f.zip
cpython-2b7f69851d641e4bf48c762c9a23df5b51982a1f.tar.gz
cpython-2b7f69851d641e4bf48c762c9a23df5b51982a1f.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 2e99013..351ef08 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
@@ -689,6 +690,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()