From eb622fb34f0b2433b21b6b5454273a597b77a6d4 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 30 May 2013 14:31:36 +0100 Subject: [PATCH] Fixed a whole bunch of resource warnings in the flask testsuite --- flask/testsuite/basic.py | 1 + flask/testsuite/blueprints.py | 5 +++++ flask/testsuite/helpers.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/flask/testsuite/basic.py b/flask/testsuite/basic.py index 810b5e66..8cd3a822 100644 --- a/flask/testsuite/basic.py +++ b/flask/testsuite/basic.py @@ -793,6 +793,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): with app.test_request_context(): self.assert_equal(flask.url_for('static', filename='index.html'), '/static/index.html') + rv.close() def test_none_response(self): app = flask.Flask(__name__) diff --git a/flask/testsuite/blueprints.py b/flask/testsuite/blueprints.py index b3771fde..5935a473 100644 --- a/flask/testsuite/blueprints.py +++ b/flask/testsuite/blueprints.py @@ -172,8 +172,10 @@ class ModuleTestCase(FlaskTestCase): self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/static/test.txt') self.assert_equal(rv.data.strip(), b'Admin File') + rv.close() rv = c.get('/admin/static/css/test.css') self.assert_equal(rv.data.strip(), b'/* nested file */') + rv.close() with app.test_request_context(): self.assert_equal(flask.url_for('admin.static', filename='test.txt'), @@ -354,8 +356,10 @@ class BlueprintTestCase(FlaskTestCase): self.assert_equal(rv.data, b'Hello from the Admin') rv = c.get('/admin/static/test.txt') self.assert_equal(rv.data.strip(), b'Admin File') + rv.close() rv = c.get('/admin/static/css/test.css') self.assert_equal(rv.data.strip(), b'/* nested file */') + rv.close() # try/finally, in case other tests use this app for Blueprint tests. max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT'] @@ -405,6 +409,7 @@ class BlueprintTestCase(FlaskTestCase): rv = blueprint.send_static_file('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 100) + rv.close() finally: app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default diff --git a/flask/testsuite/helpers.py b/flask/testsuite/helpers.py index bba66bda..b74ad6bb 100644 --- a/flask/testsuite/helpers.py +++ b/flask/testsuite/helpers.py @@ -159,6 +159,7 @@ class SendfileTestCase(FlaskTestCase): self.assert_equal(rv.mimetype, 'text/html') with app.open_resource('static/index.html') as f: self.assert_equal(rv.data, f.read()) + rv.close() def test_send_file_xsendfile(self): app = flask.Flask(__name__) @@ -170,6 +171,7 @@ class SendfileTestCase(FlaskTestCase): self.assert_equal(rv.headers['x-sendfile'], os.path.join(app.root_path, 'static/index.html')) self.assert_equal(rv.mimetype, 'text/html') + rv.close() def test_send_file_object(self): app = flask.Flask(__name__) @@ -180,6 +182,7 @@ class SendfileTestCase(FlaskTestCase): with app.open_resource('static/index.html') as f: self.assert_equal(rv.data, f.read()) self.assert_equal(rv.mimetype, 'text/html') + rv.close() # mimetypes + etag self.assert_equal(len(captured), 2) @@ -192,6 +195,7 @@ class SendfileTestCase(FlaskTestCase): self.assert_in('x-sendfile', rv.headers) self.assert_equal(rv.headers['x-sendfile'], os.path.join(app.root_path, 'static/index.html')) + rv.close() # mimetypes + etag self.assert_equal(len(captured), 2) @@ -202,6 +206,7 @@ class SendfileTestCase(FlaskTestCase): rv = flask.send_file(f) self.assert_equal(rv.data, b'Test') self.assert_equal(rv.mimetype, 'application/octet-stream') + rv.close() # etags self.assert_equal(len(captured), 1) with catch_warnings() as captured: @@ -209,6 +214,7 @@ class SendfileTestCase(FlaskTestCase): rv = flask.send_file(f, mimetype='text/plain') self.assert_equal(rv.data, b'Test') self.assert_equal(rv.mimetype, 'text/plain') + rv.close() # etags self.assert_equal(len(captured), 1) @@ -218,6 +224,7 @@ class SendfileTestCase(FlaskTestCase): f = StringIO('Test') rv = flask.send_file(f) self.assert_not_in('x-sendfile', rv.headers) + rv.close() # etags self.assert_equal(len(captured), 1) @@ -229,6 +236,7 @@ class SendfileTestCase(FlaskTestCase): rv = flask.send_file(f, as_attachment=True) value, options = parse_options_header(rv.headers['Content-Disposition']) self.assert_equal(value, 'attachment') + rv.close() # mimetypes + etag self.assert_equal(len(captured), 2) @@ -238,6 +246,7 @@ class SendfileTestCase(FlaskTestCase): value, options = parse_options_header(rv.headers['Content-Disposition']) self.assert_equal(value, 'attachment') self.assert_equal(options['filename'], 'index.html') + rv.close() with app.test_request_context(): rv = flask.send_file(StringIO('Test'), as_attachment=True, @@ -247,6 +256,7 @@ class SendfileTestCase(FlaskTestCase): value, options = parse_options_header(rv.headers['Content-Disposition']) self.assert_equal(value, 'attachment') self.assert_equal(options['filename'], 'index.txt') + rv.close() def test_static_file(self): app = flask.Flask(__name__) @@ -256,20 +266,24 @@ class SendfileTestCase(FlaskTestCase): rv = app.send_static_file('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 12 * 60 * 60) + rv.close() # Test again with direct use of send_file utility. rv = flask.send_file('static/index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 12 * 60 * 60) + rv.close() app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600 with app.test_request_context(): # Test with static file handler. rv = app.send_static_file('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 3600) + rv.close() # Test again with direct use of send_file utility. rv = flask.send_file('static/index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 3600) + rv.close() class StaticFileApp(flask.Flask): def get_send_file_max_age(self, filename): return 10 @@ -279,10 +293,12 @@ class SendfileTestCase(FlaskTestCase): rv = app.send_static_file('index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 10) + rv.close() # Test again with direct use of send_file utility. rv = flask.send_file('static/index.html') cc = parse_cache_control_header(rv.headers['Cache-Control']) self.assert_equal(cc.max_age, 10) + rv.close() class LoggingTestCase(FlaskTestCase):