summaryrefslogtreecommitdiff
path: root/tests/files
diff options
context:
space:
mode:
authorChristopher Adams <christopher.r.adams@gmail.com>2013-09-06 14:23:50 -0400
committerChristopher Adams <christopher.r.adams@gmail.com>2013-09-06 14:32:46 -0400
commitb2f5ac16565605f20a0c4e90acc6beed5a5ac1ce (patch)
tree8b40ecb183e8d9a398a195c7a05be88a1064244c /tests/files
parent05e14e8eaf577e64dc45e26466ebb6117589e572 (diff)
Fixed #11857 -- Added missing 'closed' property on TemporaryFile class.
- TemporaryFile now minimally mocks the API of the Python standard library class tempfile.NamedTemporaryFile to avoid AttributeError exceptions. - The symbol django.core.files.NamedTemporaryFile is actually assigned as a different class on different operating systems. - The bug only occurred if Django is running on Windows, hence why it was hard to diagnose.
Diffstat (limited to 'tests/files')
-rw-r--r--tests/files/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py
index b353c1a213..2bc9d566d8 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -11,6 +11,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.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