Skip to content
Myr

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

5 files+102 added−77 removed

modified:tests/conftest.py+6 added-5 removed
5 unmodified lines
6 :copyright: (c) 2015 by the Flask Team, see AUTHORS for more details.7 :license: BSD, see LICENSE for more details.8"""9import flask10import gc11import os12import sys13import pkgutil14import pytest
111 unmodified lines
126 request.addfinalizer(lambda: sys.modules.pop(name, None))127 return inner128129129@pytest.fixture130def 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)131def catch_deprecation_warnings(recwarn):132 yield133 gc.collect()134 assert not recwarn.list
modified:tests/test_basic.py+8 added-3 removed
1114 unmodified lines
1115 '/static/index.html'1116 rv.close()111711181119def test_static_path_deprecated():1120 with pytest.deprecated_call():1121 app = flask.Flask(__name__, static_path='/foo')1119def test_static_path_deprecated(recwarn):1120 app = flask.Flask(__name__, static_path='/foo')1121 recwarn.pop(DeprecationWarning)11221123 app.testing = True1124 rv = app.test_client().get('/foo/index.html')1125 assert rv.status_code == 2001126 rv.close()11271128 with app.test_request_context():1129 assert flask.url_for('static', filename='index.html') == '/foo/index.html'11301131
1 unmodified line
1133 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()11381139 with app.test_request_context():1140 assert flask.url_for('static', filename='index.html') == '/foo/index.html'11411142
512 unmodified lines
modified:tests/test_deprecations.py+8 added-12 removed
14 unmodified lines
151617class TestRequestDeprecation(object):1819 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 lines
26 assert flask.request.json == {'spam': 42}27 print(flask.request.json)28 return 'OK'2930 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)3334 assert len(captured) == 13536 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 line
40 def index():41 assert flask.request.module is None42 return 'OK'4346 with catch_deprecation_warnings() as captured:47 c = app.test_client()48 c.get('/')4944 c = app.test_client()45 c.get('/')46 recwarn.pop(DeprecationWarning)50 assert len(captured) == 1
modified:tests/test_ext.py+12 added
19 unmodified lines
20from flask._compat import PY2212223@pytest.fixture(autouse=True)24def disable_extwarnings(request, recwarn):25 from flask.exthook import ExtDeprecationWarning2627 def inner():28 assert set(w.category for w in recwarn.list) \29 <= set([ExtDeprecationWarning])30 recwarn.clear()3132 request.addfinalizer(inner)333435@pytest.fixture(autouse=True)36def 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 flaskext
160 unmodified lines
modified:tests/test_helpers.py+68 added-57 removed
335 unmodified lines
336 rv.direct_passthrough = False337 assert rv.data == f.read()338 rv.close()339340 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 lines
348 os.path.join(app.root_path, 'static/index.html')349 assert rv.mimetype == 'text/html'350 rv.close()351352 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')354355 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) == 2363364 # mimetypes + etag365 recwarn.pop(DeprecationWarning)366 recwarn.pop(DeprecationWarning)367368 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'))369370 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) == 2378379 # mimetypes + etag380 recwarn.pop(DeprecationWarning)381 recwarn.pop(DeprecationWarning)382383 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()391392 # 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)394395 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()407408 # 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 found412413 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()419420 # etags413 assert len(captured) == 1421 recwarn.pop(DeprecationWarning)422423 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) == 1424425 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()430431 # etags432 recwarn.pop(DeprecationWarning)433434 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) == 2443444 # mimetypes + etag445 assert len(recwarn.list) == 2446 recwarn.clear()447448 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