Ticket #16946: 16946.with-test.diff

File 16946.with-test.diff, 1.5 KB (added by Simon Charette, 13 years ago)
  • django/core/files/base.py

     
    3636        if not hasattr(self, '_size'):
    3737            if hasattr(self.file, 'size'):
    3838                self._size = self.file.size
    39             elif os.path.exists(self.file.name):
    40                 self._size = os.path.getsize(self.file.name)
     39            elif self.name and os.path.exists(self.name):
     40                self._size = os.path.getsize(self.name)
    4141            else:
    4242                raise AttributeError("Unable to determine the file's size.")
    4343        return self._size
  • tests/modeltests/files/tests.py

     
    22
    33import shutil
    44import tempfile
     5try:
     6    from cStringIO import StringIO
     7except ImportError:
     8    from StringIO import StringIO
    59
    610from django.core.cache import cache
    711from django.core.files import File
     
    114118            self.assertFalse(f.closed)
    115119        self.assertTrue(f.closed)
    116120        self.assertTrue(orig_file.closed)
     121
     122    def test_file_with_no_name_size(self):
     123        # https://code.djangoproject.com/ticket/16946
     124        file = File(StringIO('A file with no name'))
     125        self.assertRaises(AttributeError, lambda : file.size)
Back to Top