Merge pull request #1878 from untitaker/recwarn
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Use recwarn everywhere
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents fa327fd, 6c359e0 · Browse files · 5 files·+102 added−77 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+102 added−77 removed
- tests:+102 added−77 removed
Provenance
- Commit
3d72099- Tree
5dd60fe- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
fa327fd- Parent 2
6c359e0
5 files changed+102 added−77 removed
modified:tests/conftest.py+6 added-5 removed
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 pytest111 unmodified lines126 request.addfinalizer(lambda: sys.modules.pop(name, None))127 return inner128 129 129-@pytest.fixture130-def catch_deprecation_warnings():131- import warnings132- warnings.simplefilter('default', category=DeprecationWarning)133- return lambda: warnings.catch_warnings(record=True)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+8 added-3 removed
1114 unmodified lines1115 '/static/index.html'1116 rv.close()1117 1118 1119-def test_static_path_deprecated():1120- with pytest.deprecated_call():1121- app = flask.Flask(__name__, static_path='/foo')1119+def test_static_path_deprecated(recwarn):1120+ app = flask.Flask(__name__, static_path='/foo')1121+ recwarn.pop(DeprecationWarning)1122+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_deprecations.py+8 added-12 removed
14 unmodified lines15 16 17 class TestRequestDeprecation(object):18 19- def test_request_json(self, catch_deprecation_warnings):19+ def test_request_json(self, recwarn):20 """Request.json is deprecated"""21 app = flask.Flask(__name__)22 app.testing = True23 2 unmodified lines26 assert flask.request.json == {'spam': 42}27 print(flask.request.json)28 return 'OK'29 30- with catch_deprecation_warnings() as captured:31- c = app.test_client()32- c.post('/', data='{"spam": 42}', content_type='application/json')30+ c = app.test_client()31+ c.post('/', data='{"spam": 42}', content_type='application/json')32+ recwarn.pop(DeprecationWarning)33 34- assert len(captured) == 135-36- def test_request_module(self, catch_deprecation_warnings):34+ def test_request_module(self, recwarn):35 """Request.module is deprecated"""36 app = flask.Flask(__name__)37 app.testing = True38 1 unmodified line40 def index():41 assert flask.request.module is None42 return 'OK'43 46- with catch_deprecation_warnings() as captured:47- c = app.test_client()48- c.get('/')49-44+ c = app.test_client()45+ c.get('/')46+ recwarn.pop(DeprecationWarning)50- assert len(captured) == 1modified:tests/test_ext.py+12 added
19 unmodified lines20 from flask._compat import PY221 22 23 @pytest.fixture(autouse=True)24+def disable_extwarnings(request, recwarn):25+ from flask.exthook import ExtDeprecationWarning26+27+ def inner():28+ assert set(w.category for w in recwarn.list) \29+ <= set([ExtDeprecationWarning])30+ recwarn.clear()31+32+ request.addfinalizer(inner)33+34+35+@pytest.fixture(autouse=True)36 def importhook_setup(monkeypatch, request):37 # we clear this out for various reasons. The most important one is38 # that a real flaskext could be in there which would disable our39 # fake package. Secondly we want to make sure that the flaskext160 unmodified linesmodified:tests/test_helpers.py+68 added-57 removed
335 unmodified lines336 rv.direct_passthrough = False337 assert rv.data == f.read()338 rv.close()339 340- def test_send_file_xsendfile(self):340+ def test_send_file_xsendfile(self, catch_deprecation_warnings):341 app = flask.Flask(__name__)342 app.use_x_sendfile = True343 with app.test_request_context():344 rv = flask.send_file('static/index.html')3 unmodified lines348 os.path.join(app.root_path, 'static/index.html')349 assert rv.mimetype == 'text/html'350 rv.close()351 352- def test_send_file_object(self, catch_deprecation_warnings):352+ def test_send_file_object(self, recwarn):353 app = flask.Flask(__name__)354- with catch_deprecation_warnings() as captured:355- with app.test_request_context():356- f = open(os.path.join(app.root_path, 'static/index.html'), mode='rb')354+355+ with app.test_request_context():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- # mimetypes + etag364- assert len(captured) == 2363 364+ # mimetypes + etag365+ recwarn.pop(DeprecationWarning)366+ recwarn.pop(DeprecationWarning)367+368 app.use_x_sendfile = True367- with catch_deprecation_warnings() as captured:368- with app.test_request_context():369- f = open(os.path.join(app.root_path, 'static/index.html'))369+370+ with app.test_request_context():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()376- # mimetypes + etag377- assert len(captured) == 2378 379+ # mimetypes + etag380+ recwarn.pop(DeprecationWarning)381+ recwarn.pop(DeprecationWarning)382+383 app.use_x_sendfile = False384 with app.test_request_context():381- with catch_deprecation_warnings() as captured:382- f = StringIO('Test')383- rv = flask.send_file(f)384- rv.direct_passthrough = False385- assert rv.data == b'Test'386- assert rv.mimetype == 'application/octet-stream'387- rv.close()385+ f = StringIO('Test')386+ rv = flask.send_file(f)387+ rv.direct_passthrough = False388+ assert rv.data == b'Test'389+ assert rv.mimetype == 'application/octet-stream'390+ rv.close()391+392 # etags389- assert len(captured) == 1390- with catch_deprecation_warnings() as captured:391- class PyStringIO(object):392- def __init__(self, *args, **kwargs):393- self._io = StringIO(*args, **kwargs)394- def __getattr__(self, name):395- return getattr(self._io, name)396- f = PyStringIO('Test')397- f.name = 'test.txt'398- rv = flask.send_file(f)399- rv.direct_passthrough = False400- assert rv.data == b'Test'401- assert rv.mimetype == 'text/plain'402- rv.close()393+ recwarn.pop(DeprecationWarning)394+395+ class PyStringIO(object):396+ def __init__(self, *args, **kwargs):397+ self._io = StringIO(*args, **kwargs)398+ def __getattr__(self, name):399+ return getattr(self._io, name)400+ f = PyStringIO('Test')401+ f.name = 'test.txt'402+ rv = flask.send_file(f)403+ rv.direct_passthrough = False404+ assert rv.data == b'Test'405+ assert rv.mimetype == 'text/plain'406+ rv.close()407+408 # attachment_filename and etags409+ a = recwarn.pop(DeprecationWarning)410+ b = recwarn.pop(DeprecationWarning)404- assert len(captured) == 3405- with catch_deprecation_warnings() as captured:406- f = StringIO('Test')407- rv = flask.send_file(f, mimetype='text/plain')408- rv.direct_passthrough = False409- assert rv.data == b'Test'410- assert rv.mimetype == 'text/plain'411- rv.close()411+ c = recwarn.pop(UserWarning) # file not found412+413+ f = StringIO('Test')414+ rv = flask.send_file(f, mimetype='text/plain')415+ rv.direct_passthrough = False416+ assert rv.data == b'Test'417+ assert rv.mimetype == 'text/plain'418+ rv.close()419+420 # etags413- assert len(captured) == 1421+ recwarn.pop(DeprecationWarning)422 423 app.use_x_sendfile = True416- with catch_deprecation_warnings() as captured:417- with app.test_request_context():418- f = StringIO('Test')419- rv = flask.send_file(f)420- assert 'x-sendfile' not in rv.headers421- rv.close()422- # etags423- assert len(captured) == 1424 425- def test_attachment(self, catch_deprecation_warnings):425+ with app.test_request_context():426+ f = StringIO('Test')427+ rv = flask.send_file(f)428+ assert 'x-sendfile' not in rv.headers429+ rv.close()430+431+ # etags432+ recwarn.pop(DeprecationWarning)433+434+ def test_attachment(self, recwarn):435 app = flask.Flask(__name__)427- with catch_deprecation_warnings() as captured:428- with app.test_request_context():429- f = open(os.path.join(app.root_path, 'static/index.html'))436+ with app.test_request_context():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 = \431- value, options = parse_options_header(rv.headers['Content-Disposition'])440+ parse_options_header(rv.headers['Content-Disposition'])441 assert value == 'attachment'442 rv.close()434- # mimetypes + etag435- assert len(captured) == 2443 444+ # mimetypes + etag445+ assert len(recwarn.list) == 2446+ recwarn.clear()447+448 with app.test_request_context():449 assert options['filename'] == 'index.html'450 rv = flask.send_file('static/index.html', as_attachment=True)451 value, options = parse_options_header(rv.headers['Content-Disposition'])299 unmodified lines