summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2013-02-24 13:10:42 +0100
committerFlorian Apolloner <florian@apolloner.eu>2013-02-24 13:11:19 +0100
commite4ee3d8fcac987bc91ab9c559f39f52949227b76 (patch)
treecc6af18600e16b5d2df6faa947b294492c72c054
parente4e12875905ae7360e131e9ef93ce91c638b65fd (diff)
Fixed a few ResourceWarnings.
-rw-r--r--tests/modeltests/files/tests.py17
-rw-r--r--tests/regressiontests/file_storage/tests.py4
-rwxr-xr-xtests/runtests.py1
3 files changed, 9 insertions, 13 deletions
diff --git a/tests/modeltests/files/tests.py b/tests/modeltests/files/tests.py
index 4039fd90b0..cd2d15acdb 100644
--- a/tests/modeltests/files/tests.py
+++ b/tests/modeltests/files/tests.py
@@ -108,14 +108,12 @@ class FileStorageTests(TestCase):
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):
@@ -127,9 +125,8 @@ class FileStorageTests(TestCase):
# 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')
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index 8555a72e5e..7754eb2821 100644
--- a/tests/regressiontests/file_storage/tests.py
+++ b/tests/regressiontests/file_storage/tests.py
@@ -639,7 +639,7 @@ class FileLikeObjectTestCase(LiveServerBase):
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())
diff --git a/tests/runtests.py b/tests/runtests.py
index b9de137ea2..f2051a8ea6 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -4,7 +4,6 @@ import shutil
import subprocess
import sys
import tempfile
-import warnings
from django import contrib
from django.utils._os import upath