Skip to content

Commit e4ee3d8

Browse files
committed
Fixed a few ResourceWarnings.
1 parent e4e1287 commit e4ee3d8

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

tests/modeltests/files/tests.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ def test_file_object(self):
108108
temp_storage.save('tests/example.txt', ContentFile('some content'))
109109

110110
# Load it as python file object
111-
file_obj = open(temp_storage.path('tests/example.txt'))
112-
113-
# Save it using storage and read its content
114-
temp_storage.save('tests/file_obj', file_obj)
111+
with open(temp_storage.path('tests/example.txt')) as file_obj:
112+
# Save it using storage and read its content
113+
temp_storage.save('tests/file_obj', file_obj)
115114
self.assertTrue(temp_storage.exists('tests/file_obj'))
116-
self.assertEqual(
117-
temp_storage.open('tests/file_obj').read(),
118-
b'some content')
115+
with temp_storage.open('tests/file_obj') as f:
116+
self.assertEqual(f.read(), b'some content')
119117

120118

121119
def test_stringio(self):
@@ -127,9 +125,8 @@ def test_stringio(self):
127125
# Save it and read written file
128126
temp_storage.save('tests/stringio', output)
129127
self.assertTrue(temp_storage.exists('tests/stringio'))
130-
self.assertEqual(
131-
temp_storage.open('tests/stringio').read(),
132-
b'content')
128+
with temp_storage.open('tests/stringio') as f:
129+
self.assertEqual(f.read(), b'content')
133130

134131

135132

tests/regressiontests/file_storage/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def test_urllib2_urlopen(self):
639639
f = File(file_like_object)
640640
stored_filename = self.storage.save("remote_file.html", f)
641641

642-
stored_file = self.storage.open(stored_filename)
643642
remote_file = self.urlopen('/example_view/')
644643

645-
self.assertEqual(stored_file.read(), remote_file.read())
644+
with self.storage.open(stored_filename) as stored_file:
645+
self.assertEqual(stored_file.read(), remote_file.read())

tests/runtests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import sys
66
import tempfile
7-
import warnings
87

98
from django import contrib
109
from django.utils._os import upath

0 commit comments

Comments
 (0)