1
0
mirror of https://github.com/django/django.git synced 2024-12-26 19:16:11 +00:00
django/tests/modeltests/files/tests_25.py

18 lines
467 B
Python

from __future__ import with_statement
import tempfile
from django.core.files import File
from django.utils.unittest import TestCase
class FileObjTests(TestCase):
def test_context_manager(self):
orig_file = tempfile.TemporaryFile()
base_file = File(orig_file)
with base_file as f:
self.assertIs(base_file, f)
self.assertFalse(f.closed)
self.assertTrue(f.closed)
self.assertTrue(orig_file.closed)