File tree Expand file tree Collapse file tree 3 files changed +9
-13
lines changed
regressiontests/file_storage Expand file tree Collapse file tree 3 files changed +9
-13
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ())
Original file line number Diff line number Diff line change 44import subprocess
55import sys
66import tempfile
7- import warnings
87
98from django import contrib
109from django .utils ._os import upath
You can’t perform that action at this time.
0 commit comments