diff --git a/django/core/files/base.py b/django/core/files/base.py
index f9e3f10..dc07399 100644
a
|
b
|
class File(FileProxyMixin):
|
101 | 101 | if buffer_ is not None: |
102 | 102 | yield buffer_ |
103 | 103 | |
| 104 | def __enter__(self): |
| 105 | return self |
| 106 | |
| 107 | def __exit__(self, type, value, traceback): |
| 108 | self.close() |
| 109 | |
104 | 110 | def open(self, mode=None): |
105 | 111 | if not self.closed: |
106 | 112 | self.seek(0) |
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index b90bf0e..1e6d703 100644
a
|
b
|
class FileStorageTests(unittest.TestCase):
|
111 | 111 | self.storage.delete('storage_test') |
112 | 112 | self.failIf(self.storage.exists('storage_test')) |
113 | 113 | |
| 114 | def test_file_context_managers(self): |
| 115 | """ |
| 116 | Using __enter__ and __exit__ works as expected. |
| 117 | """ |
| 118 | orig_file = tempfile.TemporaryFile() |
| 119 | with File(orig_file) as f: |
| 120 | self.assertTrue(isinstance(f, File)) |
| 121 | self.assertFalse(f.closed) |
| 122 | self.assertTrue(f.closed) |
| 123 | |
114 | 124 | def test_file_accessed_time(self): |
115 | 125 | """ |
116 | 126 | File storage returns a Datetime object for the last accessed time of |