Eliminate some resource warnings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 293eb58 · Browse files · 3 files·+26 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+26 added−19 removed
- tests:+26 added−19 removed
Provenance
- Commit
6c359e0- Tree
7240eec- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
293eb58
3 files changed+26 added−19 removed
modified:tests/conftest.py+2 added
5 unmodified lines6 :copyright: (c) 2015 by the Flask Team, see AUTHORS for more details.7 :license: BSD, see LICENSE for more details.8 """9 import flask10+import gc11 import os12 import sys13 import pkgutil14 import pytest114 unmodified lines129 130 @pytest.yield_fixture(autouse=True)131 def catch_deprecation_warnings(recwarn):132 yield133+ gc.collect()134 assert not recwarn.listmodified:tests/test_basic.py+4 added
1121 unmodified lines1122 1123 app.testing = True1124 rv = app.test_client().get('/foo/index.html')1125 assert rv.status_code == 2001126+ rv.close()1127+1128 with app.test_request_context():1129 assert flask.url_for('static', filename='index.html') == '/foo/index.html'1130 1131 1 unmodified line1133 app = flask.Flask(__name__, static_url_path='/foo')1134 app.testing = True1135 rv = app.test_client().get('/foo/index.html')1136 assert rv.status_code == 2001137+ rv.close()1138+1139 with app.test_request_context():1140 assert flask.url_for('static', filename='index.html') == '/foo/index.html'1141 1142 512 unmodified linesmodified:tests/test_helpers.py+20 added-19 removed
351 unmodified lines352 def test_send_file_object(self, recwarn):353 app = flask.Flask(__name__)354 355 with app.test_request_context():356- f = open(os.path.join(app.root_path, 'static/index.html'), mode='rb')357- rv = flask.send_file(f)358- rv.direct_passthrough = False359- with app.open_resource('static/index.html') as f:360- assert rv.data == f.read()361- assert rv.mimetype == 'text/html'362- rv.close()356+ with open(os.path.join(app.root_path, 'static/index.html'), mode='rb') as f:357+ rv = flask.send_file(f)358+ rv.direct_passthrough = False359+ with app.open_resource('static/index.html') as f:360+ assert rv.data == f.read()361+ assert rv.mimetype == 'text/html'362+ rv.close()363 364 # mimetypes + etag365 recwarn.pop(DeprecationWarning)366 recwarn.pop(DeprecationWarning)367 368 app.use_x_sendfile = True369 370 with app.test_request_context():371- f = open(os.path.join(app.root_path, 'static/index.html'))372- rv = flask.send_file(f)373- assert rv.mimetype == 'text/html'374- assert 'x-sendfile' in rv.headers375- assert rv.headers['x-sendfile'] == \376- os.path.join(app.root_path, 'static/index.html')377- rv.close()371+ with open(os.path.join(app.root_path, 'static/index.html')) as f:372+ rv = flask.send_file(f)373+ assert rv.mimetype == 'text/html'374+ assert 'x-sendfile' in rv.headers375+ assert rv.headers['x-sendfile'] == \376+ os.path.join(app.root_path, 'static/index.html')377+ rv.close()378 379 # mimetypes + etag380 recwarn.pop(DeprecationWarning)381 recwarn.pop(DeprecationWarning)51 unmodified lines433 434 def test_attachment(self, recwarn):435 app = flask.Flask(__name__)436 with app.test_request_context():437- f = open(os.path.join(app.root_path, 'static/index.html'))438- rv = flask.send_file(f, as_attachment=True)439- value, options = parse_options_header(rv.headers['Content-Disposition'])440- assert value == 'attachment'441- rv.close()437+ with open(os.path.join(app.root_path, 'static/index.html')) as f:438+ rv = flask.send_file(f, as_attachment=True)439+ value, options = \440+ parse_options_header(rv.headers['Content-Disposition'])441+ assert value == 'attachment'442+ rv.close()443 444 # mimetypes + etag445 assert len(recwarn.list) == 2446 recwarn.clear()304 unmodified lines