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

18 lines
467 B
Python
Raw Normal View History

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)