Fixed a whole bunch of resource warnings in the flask testsuite
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 47572c5 · Browse files · 3 files·+22 added−0 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+22 added−0 removed
- other:+22 added−0 removed
Provenance
- Commit
eb622fb- Tree
dc636c7- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
47572c5
3 files changed+22 added−0 removed
modified:flask/testsuite/basic.py+1 added
791 unmodified lines792 self.assert_equal(rv.data.strip(), b'<h1>Hello World!</h1>')793 with app.test_request_context():794 self.assert_equal(flask.url_for('static', filename='index.html'),795 '/static/index.html')796+ rv.close()797 798 def test_none_response(self):799 app = flask.Flask(__name__)800 @app.route('/')352 unmodified linesmodified:flask/testsuite/blueprints.py+5 added
170 unmodified lines171 rv = c.get('/admin/index2')172 self.assert_equal(rv.data, b'Hello from the Admin')173 rv = c.get('/admin/static/test.txt')174 self.assert_equal(rv.data.strip(), b'Admin File')175+ rv.close()176 rv = c.get('/admin/static/css/test.css')177 self.assert_equal(rv.data.strip(), b'/* nested file */')178+ rv.close()179 180 with app.test_request_context():181 self.assert_equal(flask.url_for('admin.static', filename='test.txt'),182 '/admin/static/test.txt')172 unmodified lines355 rv = c.get('/admin/index2')356 self.assert_equal(rv.data, b'Hello from the Admin')357 rv = c.get('/admin/static/test.txt')358 self.assert_equal(rv.data.strip(), b'Admin File')359+ rv.close()360 rv = c.get('/admin/static/css/test.css')361 self.assert_equal(rv.data.strip(), b'/* nested file */')362+ rv.close()363 364 # try/finally, in case other tests use this app for Blueprint tests.365 max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']366 try:41 unmodified lines408 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = unexpected_max_age409 rv = blueprint.send_static_file('index.html')410 cc = parse_cache_control_header(rv.headers['Cache-Control'])411 self.assert_equal(cc.max_age, 100)412+ rv.close()413 finally:414 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default415 416 def test_templates_list(self):354 unmodified linesmodified:flask/testsuite/helpers.py+16 added
157 unmodified lines158 self.assert_true(rv.direct_passthrough)159 self.assert_equal(rv.mimetype, 'text/html')160 with app.open_resource('static/index.html') as f:161 self.assert_equal(rv.data, f.read())162+ rv.close()163 164 def test_send_file_xsendfile(self):165 app = flask.Flask(__name__)166 app.use_x_sendfile = True3 unmodified lines170 self.assert_in('x-sendfile', rv.headers)171 self.assert_equal(rv.headers['x-sendfile'],172 os.path.join(app.root_path, 'static/index.html'))173 self.assert_equal(rv.mimetype, 'text/html')174+ rv.close()175 176 def test_send_file_object(self):177 app = flask.Flask(__name__)178 with catch_warnings() as captured:2 unmodified lines181 rv = flask.send_file(f)182 with app.open_resource('static/index.html') as f:183 self.assert_equal(rv.data, f.read())184 self.assert_equal(rv.mimetype, 'text/html')185+ rv.close()186 # mimetypes + etag187 self.assert_equal(len(captured), 2)188 189 app.use_x_sendfile = True4 unmodified lines194 self.assert_equal(rv.mimetype, 'text/html')195 self.assert_in('x-sendfile', rv.headers)196 self.assert_equal(rv.headers['x-sendfile'],197 os.path.join(app.root_path, 'static/index.html'))198+ rv.close()199 # mimetypes + etag200 self.assert_equal(len(captured), 2)201 202 app.use_x_sendfile = False2 unmodified lines205 f = StringIO('Test')206 rv = flask.send_file(f)207 self.assert_equal(rv.data, b'Test')208 self.assert_equal(rv.mimetype, 'application/octet-stream')209+ rv.close()210 # etags211 self.assert_equal(len(captured), 1)212 with catch_warnings() as captured:213 f = StringIO('Test')214 rv = flask.send_file(f, mimetype='text/plain')215 self.assert_equal(rv.data, b'Test')216 self.assert_equal(rv.mimetype, 'text/plain')217+ rv.close()218 # etags219 self.assert_equal(len(captured), 1)220 221 app.use_x_sendfile = True1 unmodified line223 with app.test_request_context():224 f = StringIO('Test')225 rv = flask.send_file(f)226 self.assert_not_in('x-sendfile', rv.headers)227+ rv.close()228 # etags229 self.assert_equal(len(captured), 1)230 231 def test_attachment(self):3 unmodified lines235 f = open(os.path.join(app.root_path, 'static/index.html'))236 rv = flask.send_file(f, as_attachment=True)237 value, options = parse_options_header(rv.headers['Content-Disposition'])238 self.assert_equal(value, 'attachment')239+ rv.close()240 # mimetypes + etag241 self.assert_equal(len(captured), 2)242 243 with app.test_request_context():1 unmodified line245 rv = flask.send_file('static/index.html', as_attachment=True)246 value, options = parse_options_header(rv.headers['Content-Disposition'])247 self.assert_equal(value, 'attachment')248 self.assert_equal(options['filename'], 'index.html')249+ rv.close()250 251 with app.test_request_context():252 rv = flask.send_file(StringIO('Test'), as_attachment=True,253 attachment_filename='index.txt',1 unmodified line255 self.assert_equal(rv.mimetype, 'text/plain')256 value, options = parse_options_header(rv.headers['Content-Disposition'])257 self.assert_equal(value, 'attachment')258 self.assert_equal(options['filename'], 'index.txt')259+ rv.close()260 261 def test_static_file(self):262 app = flask.Flask(__name__)263 # default cache timeout is 12 hours1 unmodified line265 # Test with static file handler.266 rv = app.send_static_file('index.html')267 cc = parse_cache_control_header(rv.headers['Cache-Control'])268 self.assert_equal(cc.max_age, 12 * 60 * 60)269+ rv.close()270 # Test again with direct use of send_file utility.271 rv = flask.send_file('static/index.html')272 cc = parse_cache_control_header(rv.headers['Cache-Control'])273 self.assert_equal(cc.max_age, 12 * 60 * 60)274+ rv.close()275 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600276 with app.test_request_context():277 # Test with static file handler.278 rv = app.send_static_file('index.html')279 cc = parse_cache_control_header(rv.headers['Cache-Control'])280 self.assert_equal(cc.max_age, 3600)281+ rv.close()282 # Test again with direct use of send_file utility.283 rv = flask.send_file('static/index.html')284 cc = parse_cache_control_header(rv.headers['Cache-Control'])285 self.assert_equal(cc.max_age, 3600)286+ rv.close()287 class StaticFileApp(flask.Flask):288 def get_send_file_max_age(self, filename):289 return 10290 app = StaticFileApp(__name__)1 unmodified line292 # Test with static file handler.293 rv = app.send_static_file('index.html')294 cc = parse_cache_control_header(rv.headers['Cache-Control'])295 self.assert_equal(cc.max_age, 10)296+ rv.close()297 # Test again with direct use of send_file utility.298 rv = flask.send_file('static/index.html')299 cc = parse_cache_control_header(rv.headers['Cache-Control'])300 self.assert_equal(cc.max_age, 10)301+ rv.close()302 303 304 class LoggingTestCase(FlaskTestCase):305 232 unmodified lines