Skip to content

Commit eb622fb

Browse files
committed
Fixed a whole bunch of resource warnings in the flask testsuite
1 parent 47572c5 commit eb622fb

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

flask/testsuite/basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ def test_static_files(self):
793793
with app.test_request_context():
794794
self.assert_equal(flask.url_for('static', filename='index.html'),
795795
'/static/index.html')
796+
rv.close()
796797

797798
def test_none_response(self):
798799
app = flask.Flask(__name__)

flask/testsuite/blueprints.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ def test_templates_and_static(self):
172172
self.assert_equal(rv.data, b'Hello from the Admin')
173173
rv = c.get('/admin/static/test.txt')
174174
self.assert_equal(rv.data.strip(), b'Admin File')
175+
rv.close()
175176
rv = c.get('/admin/static/css/test.css')
176177
self.assert_equal(rv.data.strip(), b'/* nested file */')
178+
rv.close()
177179

178180
with app.test_request_context():
179181
self.assert_equal(flask.url_for('admin.static', filename='test.txt'),
@@ -354,8 +356,10 @@ def test_templates_and_static(self):
354356
self.assert_equal(rv.data, b'Hello from the Admin')
355357
rv = c.get('/admin/static/test.txt')
356358
self.assert_equal(rv.data.strip(), b'Admin File')
359+
rv.close()
357360
rv = c.get('/admin/static/css/test.css')
358361
self.assert_equal(rv.data.strip(), b'/* nested file */')
362+
rv.close()
359363

360364
# try/finally, in case other tests use this app for Blueprint tests.
361365
max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
@@ -405,6 +409,7 @@ def get_send_file_max_age(self, filename):
405409
rv = blueprint.send_static_file('index.html')
406410
cc = parse_cache_control_header(rv.headers['Cache-Control'])
407411
self.assert_equal(cc.max_age, 100)
412+
rv.close()
408413
finally:
409414
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default
410415

flask/testsuite/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_send_file_regular(self):
159159
self.assert_equal(rv.mimetype, 'text/html')
160160
with app.open_resource('static/index.html') as f:
161161
self.assert_equal(rv.data, f.read())
162+
rv.close()
162163

163164
def test_send_file_xsendfile(self):
164165
app = flask.Flask(__name__)
@@ -170,6 +171,7 @@ def test_send_file_xsendfile(self):
170171
self.assert_equal(rv.headers['x-sendfile'],
171172
os.path.join(app.root_path, 'static/index.html'))
172173
self.assert_equal(rv.mimetype, 'text/html')
174+
rv.close()
173175

174176
def test_send_file_object(self):
175177
app = flask.Flask(__name__)
@@ -180,6 +182,7 @@ def test_send_file_object(self):
180182
with app.open_resource('static/index.html') as f:
181183
self.assert_equal(rv.data, f.read())
182184
self.assert_equal(rv.mimetype, 'text/html')
185+
rv.close()
183186
# mimetypes + etag
184187
self.assert_equal(len(captured), 2)
185188

@@ -192,6 +195,7 @@ def test_send_file_object(self):
192195
self.assert_in('x-sendfile', rv.headers)
193196
self.assert_equal(rv.headers['x-sendfile'],
194197
os.path.join(app.root_path, 'static/index.html'))
198+
rv.close()
195199
# mimetypes + etag
196200
self.assert_equal(len(captured), 2)
197201

@@ -202,13 +206,15 @@ def test_send_file_object(self):
202206
rv = flask.send_file(f)
203207
self.assert_equal(rv.data, b'Test')
204208
self.assert_equal(rv.mimetype, 'application/octet-stream')
209+
rv.close()
205210
# etags
206211
self.assert_equal(len(captured), 1)
207212
with catch_warnings() as captured:
208213
f = StringIO('Test')
209214
rv = flask.send_file(f, mimetype='text/plain')
210215
self.assert_equal(rv.data, b'Test')
211216
self.assert_equal(rv.mimetype, 'text/plain')
217+
rv.close()
212218
# etags
213219
self.assert_equal(len(captured), 1)
214220

@@ -218,6 +224,7 @@ def test_send_file_object(self):
218224
f = StringIO('Test')
219225
rv = flask.send_file(f)
220226
self.assert_not_in('x-sendfile', rv.headers)
227+
rv.close()
221228
# etags
222229
self.assert_equal(len(captured), 1)
223230

@@ -229,6 +236,7 @@ def test_attachment(self):
229236
rv = flask.send_file(f, as_attachment=True)
230237
value, options = parse_options_header(rv.headers['Content-Disposition'])
231238
self.assert_equal(value, 'attachment')
239+
rv.close()
232240
# mimetypes + etag
233241
self.assert_equal(len(captured), 2)
234242

@@ -238,6 +246,7 @@ def test_attachment(self):
238246
value, options = parse_options_header(rv.headers['Content-Disposition'])
239247
self.assert_equal(value, 'attachment')
240248
self.assert_equal(options['filename'], 'index.html')
249+
rv.close()
241250

242251
with app.test_request_context():
243252
rv = flask.send_file(StringIO('Test'), as_attachment=True,
@@ -247,6 +256,7 @@ def test_attachment(self):
247256
value, options = parse_options_header(rv.headers['Content-Disposition'])
248257
self.assert_equal(value, 'attachment')
249258
self.assert_equal(options['filename'], 'index.txt')
259+
rv.close()
250260

251261
def test_static_file(self):
252262
app = flask.Flask(__name__)
@@ -256,20 +266,24 @@ def test_static_file(self):
256266
rv = app.send_static_file('index.html')
257267
cc = parse_cache_control_header(rv.headers['Cache-Control'])
258268
self.assert_equal(cc.max_age, 12 * 60 * 60)
269+
rv.close()
259270
# Test again with direct use of send_file utility.
260271
rv = flask.send_file('static/index.html')
261272
cc = parse_cache_control_header(rv.headers['Cache-Control'])
262273
self.assert_equal(cc.max_age, 12 * 60 * 60)
274+
rv.close()
263275
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
264276
with app.test_request_context():
265277
# Test with static file handler.
266278
rv = app.send_static_file('index.html')
267279
cc = parse_cache_control_header(rv.headers['Cache-Control'])
268280
self.assert_equal(cc.max_age, 3600)
281+
rv.close()
269282
# Test again with direct use of send_file utility.
270283
rv = flask.send_file('static/index.html')
271284
cc = parse_cache_control_header(rv.headers['Cache-Control'])
272285
self.assert_equal(cc.max_age, 3600)
286+
rv.close()
273287
class StaticFileApp(flask.Flask):
274288
def get_send_file_max_age(self, filename):
275289
return 10
@@ -279,10 +293,12 @@ def get_send_file_max_age(self, filename):
279293
rv = app.send_static_file('index.html')
280294
cc = parse_cache_control_header(rv.headers['Cache-Control'])
281295
self.assert_equal(cc.max_age, 10)
296+
rv.close()
282297
# Test again with direct use of send_file utility.
283298
rv = flask.send_file('static/index.html')
284299
cc = parse_cache_control_header(rv.headers['Cache-Control'])
285300
self.assert_equal(cc.max_age, 10)
301+
rv.close()
286302

287303

288304
class LoggingTestCase(FlaskTestCase):

0 commit comments

Comments
 (0)