Issue #18879: When a method is looked up on a temporary file, avoid closing the file before the method is possibly called.

This commit is contained in:
Antoine Pitrou 2013-12-21 22:14:56 +01:00
parent bdce938af2
commit 17c93260a6
3 changed files with 87 additions and 35 deletions

View file

@ -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()