Ticket #27777: 27777.diff

File 27777.diff, 1003 bytes (added by Tim Graham, 8 years ago)
  • django/core/files/base.py

    diff --git a/django/core/files/base.py b/django/core/files/base.py
    index 9030ed9..74a1e41 100644
    a b class File(FileProxyMixin):  
    114114            yield buffer_
    115115
    116116    def __enter__(self):
     117        self.open()
    117118        return self
    118119
    119120    def __exit__(self, exc_type, exc_value, tb):
  • tests/files/tests.py

    diff --git a/tests/files/tests.py b/tests/files/tests.py
    index 4036fc5..ced9a77 100644
    a b class FileTests(unittest.TestCase):  
    3838        self.assertTrue(f.closed)
    3939        self.assertTrue(orig_file.closed)
    4040
     41    def test_context_manager_open(self):
     42        my_file = ContentFile('test')
     43        with my_file as f:
     44            self.assertEqual(f.read(), 'test')
     45
     46        with my_file as f:
     47            self.assertEqual(f.read(), 'test')
     48
    4149    def test_namedtemporaryfile_closes(self):
    4250        """
    4351        The symbol django.core.files.NamedTemporaryFile is assigned as
Back to Top