Ticket #16946: 16946.with-test.diff
File 16946.with-test.diff, 1.5 KB (added by , 13 years ago) |
---|
-
django/core/files/base.py
36 36 if not hasattr(self, '_size'): 37 37 if hasattr(self.file, 'size'): 38 38 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) 41 41 else: 42 42 raise AttributeError("Unable to determine the file's size.") 43 43 return self._size -
tests/modeltests/files/tests.py
2 2 3 3 import shutil 4 4 import tempfile 5 try: 6 from cStringIO import StringIO 7 except ImportError: 8 from StringIO import StringIO 5 9 6 10 from django.core.cache import cache 7 11 from django.core.files import File … … 114 118 self.assertFalse(f.closed) 115 119 self.assertTrue(f.closed) 116 120 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)