diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2013-09-06 17:38:37 -0700 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2013-09-06 19:44:25 -0500 |
| commit | 2a2ac5c1400c67f25388621a39749c918a4efe98 (patch) | |
| tree | e4560d9516bca0e655c7d52925cdca631b407805 | |
| parent | 6ba01f64c1e5baf1e876cabd3d625ad53f39a5e4 (diff) | |
Merge pull request #1566 from adamsc64/ticket_11857
Fixed #11857 -- Added missing 'closed' property on TemporaryFile class.
Backport of 926bc42 from trunk.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/core/files/temp.py | 9 | ||||
| -rw-r--r-- | tests/files/tests.py | 15 |
3 files changed, 25 insertions, 0 deletions
@@ -56,6 +56,7 @@ answer newbie questions, and generally made Django that much better: Gisle Aas <gisle@aas.no> Chris Adams + Christopher Adams <christopher.r.adams@gmail.com> Mathieu Agopian <mathieu.agopian@gmail.com> Roberto Aguilar <roberto@baremetal.io> ajs <adi@sieker.info> diff --git a/django/core/files/temp.py b/django/core/files/temp.py index b607291294..3dcda17a09 100644 --- a/django/core/files/temp.py +++ b/django/core/files/temp.py @@ -46,6 +46,15 @@ if os.name == 'nt': except (OSError): pass + @property + def closed(self): + """ + This attribute needs to be accessible in certain situations, + because this class is supposed to mock the API of the class + tempfile.NamedTemporaryFile in the Python standard library. + """ + return self.file.closed + def __del__(self): self.close() diff --git a/tests/files/tests.py b/tests/files/tests.py index f1e3d5b14b..79d5e97164 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -10,6 +10,7 @@ from django.core.files import File from django.core.files.move import file_move_safe from django.core.files.base import ContentFile from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.files.temp import NamedTemporaryFile from django.test import TestCase from django.utils import unittest from django.utils.six import StringIO @@ -142,6 +143,20 @@ class FileTests(unittest.TestCase): self.assertTrue(f.closed) self.assertTrue(orig_file.closed) + def test_namedtemporaryfile_closes(self): + """ + The symbol django.core.files.NamedTemporaryFile is assigned as + a different class on different operating systems. In + any case, the result should minimally mock some of the API of + tempfile.NamedTemporaryFile from the Python standard library. + """ + tempfile = NamedTemporaryFile() + self.assertTrue(hasattr(tempfile, "closed")) + self.assertFalse(tempfile.closed) + + tempfile.close() + self.assertTrue(tempfile.closed) + def test_file_mode(self): # Should not set mode to None if it is not present. # See #14681, stdlib gzip module crashes if mode is set to None |
