Skip to content
Myr

Use recwarn everywhere

Before adoption: this commit came in with the history the project adopted, so no landing records it.

...instead of custom fixture. Also assert that no warnings are left over after the test.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 047efac · Browse files · 5 files+110 added−92 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+110 added−92 removed

  • tests:+110 added−92 removed

5 files+110 added−92 removed

modified:tests/conftest.py+4 added-5 removed
124 unmodified lines
125 request.addfinalizer(lambda: sys.modules.pop(name, None))126 return inner127128129@pytest.fixture130def catch_deprecation_warnings():131 import warnings132 warnings.simplefilter('default', category=DeprecationWarning)133 return lambda: warnings.catch_warnings(record=True)129@pytest.yield_fixture(autouse=True)130def catch_deprecation_warnings(recwarn):131 yield132 assert not recwarn.list
modified:tests/test_basic.py+4 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 with app.test_request_context():
524 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+82 added-72 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')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) == 2354355 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()363364 # mimetypes + etag365 assert len(recwarn.list) == 2366 recwarn.clear()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'))370 rv = flask.send_file(f)371 assert rv.mimetype == 'text/html'372 assert 'x-sendfile' in rv.headers373 assert rv.headers['x-sendfile'] == \374 os.path.join(app.root_path, 'static/index.html')375 rv.close()376 # mimetypes + etag377 assert len(captured) == 2369370 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()378379 # mimetypes + etag380 recwarn.pop()381 recwarn.pop()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()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 recwarn.pop()410 recwarn.pop()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 recwarn.pop()412413 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()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()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'))430 rv = flask.send_file(f, as_attachment=True)431 value, options = parse_options_header(rv.headers['Content-Disposition'])432 assert value == 'attachment'433 rv.close()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()434 # mimetypes + etag435 assert len(captured) == 2442443 # mimetypes + etag444 assert len(recwarn.list) == 2445 recwarn.clear()446447 with app.test_request_context():448 assert options['filename'] == 'index.html'449 rv = flask.send_file('static/index.html', as_attachment=True)450 value, options = parse_options_header(rv.headers['Content-Disposition'])
299 unmodified lines