1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

Fixed a few ResourceWarnings.

This commit is contained in:
Florian Apolloner 2013-02-24 13:10:42 +01:00
parent e4e1287590
commit e4ee3d8fca
3 changed files with 9 additions and 13 deletions

View File

@ -108,14 +108,12 @@ class FileStorageTests(TestCase):
temp_storage.save('tests/example.txt', ContentFile('some content')) temp_storage.save('tests/example.txt', ContentFile('some content'))
# Load it as python file object # Load it as python file object
file_obj = open(temp_storage.path('tests/example.txt')) with open(temp_storage.path('tests/example.txt')) as file_obj:
# Save it using storage and read its content
# Save it using storage and read its content temp_storage.save('tests/file_obj', file_obj)
temp_storage.save('tests/file_obj', file_obj)
self.assertTrue(temp_storage.exists('tests/file_obj')) self.assertTrue(temp_storage.exists('tests/file_obj'))
self.assertEqual( with temp_storage.open('tests/file_obj') as f:
temp_storage.open('tests/file_obj').read(), self.assertEqual(f.read(), b'some content')
b'some content')
def test_stringio(self): def test_stringio(self):
@ -127,9 +125,8 @@ class FileStorageTests(TestCase):
# Save it and read written file # Save it and read written file
temp_storage.save('tests/stringio', output) temp_storage.save('tests/stringio', output)
self.assertTrue(temp_storage.exists('tests/stringio')) self.assertTrue(temp_storage.exists('tests/stringio'))
self.assertEqual( with temp_storage.open('tests/stringio') as f:
temp_storage.open('tests/stringio').read(), self.assertEqual(f.read(), b'content')
b'content')

View File

@ -639,7 +639,7 @@ class FileLikeObjectTestCase(LiveServerBase):
f = File(file_like_object) f = File(file_like_object)
stored_filename = self.storage.save("remote_file.html", f) stored_filename = self.storage.save("remote_file.html", f)
stored_file = self.storage.open(stored_filename)
remote_file = self.urlopen('/example_view/') remote_file = self.urlopen('/example_view/')
self.assertEqual(stored_file.read(), remote_file.read()) with self.storage.open(stored_filename) as stored_file:
self.assertEqual(stored_file.read(), remote_file.read())

View File

@ -4,7 +4,6 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import warnings
from django import contrib from django import contrib
from django.utils._os import upath from django.utils._os import upath