Skip to content

Commit

Permalink
Fixed a few ResourceWarnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Feb 24, 2013
1 parent e4e1287 commit e4ee3d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
17 changes: 7 additions & 10 deletions tests/modeltests/files/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ def test_file_object(self):
temp_storage.save('tests/example.txt', ContentFile('some content'))

# Load it as python file object
file_obj = open(temp_storage.path('tests/example.txt'))

# Save it using storage and read its content
temp_storage.save('tests/file_obj', file_obj)
with open(temp_storage.path('tests/example.txt')) as file_obj:
# Save it using storage and read its content
temp_storage.save('tests/file_obj', file_obj)
self.assertTrue(temp_storage.exists('tests/file_obj'))
self.assertEqual(
temp_storage.open('tests/file_obj').read(),
b'some content')
with temp_storage.open('tests/file_obj') as f:
self.assertEqual(f.read(), b'some content')


def test_stringio(self):
Expand All @@ -127,9 +125,8 @@ def test_stringio(self):
# Save it and read written file
temp_storage.save('tests/stringio', output)
self.assertTrue(temp_storage.exists('tests/stringio'))
self.assertEqual(
temp_storage.open('tests/stringio').read(),
b'content')
with temp_storage.open('tests/stringio') as f:
self.assertEqual(f.read(), b'content')



Expand Down
4 changes: 2 additions & 2 deletions tests/regressiontests/file_storage/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def test_urllib2_urlopen(self):
f = File(file_like_object)
stored_filename = self.storage.save("remote_file.html", f)

stored_file = self.storage.open(stored_filename)
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())
1 change: 0 additions & 1 deletion tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
import sys
import tempfile
import warnings

from django import contrib
from django.utils._os import upath
Expand Down

0 comments on commit e4ee3d8

Please sign in to comment.